From 89185c8a27dba84347de507a3b3622172e30a3b5 Mon Sep 17 00:00:00 2001 From: Hanabi <317387557+Hanabi9248@users.noreply.github.com> Date: Wed, 23 Sep 2026 23:26:01 +0800 Subject: [PATCH 1/2] test: cover pod timestamps across server time zones --- .../com/highgo/cloud/util/CommonUtilTest.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 common/src/test/java/com/highgo/cloud/util/CommonUtilTest.java diff --git a/common/src/test/java/com/highgo/cloud/util/CommonUtilTest.java b/common/src/test/java/com/highgo/cloud/util/CommonUtilTest.java new file mode 100644 index 0000000..74501cf --- /dev/null +++ b/common/src/test/java/com/highgo/cloud/util/CommonUtilTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.highgo.cloud.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.text.ParseException; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import java.util.Date; +import java.util.TimeZone; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class CommonUtilTest { + @Parameterized.Parameters(name = "{0}") + public static Collection timeZones() { + return Arrays.asList(new Object[][]{{"UTC"}, {"Asia/Shanghai"}, {"America/Los_Angeles"}}); + } + + private final String timeZone; + private TimeZone originalTimeZone; + + public CommonUtilTest(String timeZone) { + this.timeZone = timeZone; + } + + @Before + public void setTimeZone() { + originalTimeZone = TimeZone.getDefault(); + TimeZone.setDefault(TimeZone.getTimeZone(timeZone)); + } + + @After + public void restoreTimeZone() { + TimeZone.setDefault(originalTimeZone); + } + + @Test + public void parsesUtcTimestampIndependentlyOfDefaultTimeZone() throws ParseException { + assertEquals(Date.from(Instant.parse("2026-09-23T14:00:00Z")), + CommonUtil.stringToDate("2026-09-23T14:00:00Z")); + } + + @Test + public void preservesPodStartTimeOrderingAroundInstanceUpdate() throws ParseException { + Date updatedAt = Date.from(Instant.parse("2026-09-23T14:00:00Z")); + assertTrue(CommonUtil.stringToDate("2026-09-23T13:59:59Z").before(updatedAt)); + assertFalse(CommonUtil.stringToDate("2026-09-23T14:00:01Z").before(updatedAt)); + } +} From 35a8d0e16040e3c1599095044e0ebe64e954c780 Mon Sep 17 00:00:00 2001 From: Hanabi <317387557+Hanabi9248@users.noreply.github.com> Date: Wed, 23 Sep 2026 23:28:39 +0800 Subject: [PATCH 2/2] fix: parse pod start timestamps in UTC --- common/src/main/java/com/highgo/cloud/util/CommonUtil.java | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/main/java/com/highgo/cloud/util/CommonUtil.java b/common/src/main/java/com/highgo/cloud/util/CommonUtil.java index 237f091..d36b51a 100644 --- a/common/src/main/java/com/highgo/cloud/util/CommonUtil.java +++ b/common/src/main/java/com/highgo/cloud/util/CommonUtil.java @@ -183,6 +183,7 @@ public static String unBase64(String str) { public static Date stringToDate(String dateStr) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat.parse(dateStr); }