Skip to content

Commit 630d7ed

Browse files
committed
devfeat(test): Support UTC tests
1 parent 8fd31e0 commit 630d7ed

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
11
package com.cloud.chatbot;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
45

56
import java.time.Instant;
7+
import java.util.Arrays;
68

79
import org.junit.jupiter.api.Test;
810

911

1012

11-
// Assuming the "user" is on a GMT+8 system
13+
// Assuming the "user" is on a GMT+8 or GMT/UTC system
1214
public class DateConverterTest {
1315
@Test
1416
public void timestampToInstant() {
1517
Instant instantExpected = Instant.parse("2023-01-31T20:56:00Z");
1618
Instant instantActual = DateConverter.timestampToInstant("1 2 23 456");
19+
Instant instantActual2 = DateConverter.timestampToInstant("1 1 31 2056");
1720
assertEquals(instantExpected, instantActual);
21+
assertTrue(
22+
Arrays.asList(instantActual, instantActual2)
23+
.contains(instantExpected)
24+
);
1825
}
1926

2027
@Test
2128
public void instantToPrettyTimestamp_nonZeroMinutes() {
2229
Instant instant = Instant.parse("2023-01-31T20:56:00Z");
2330
String timestamp = DateConverter.instantToPrettyTimestamp(instant);
24-
assertEquals("1 Feb '23, 4:56am", timestamp);
31+
assertTrue(
32+
Arrays.asList("1 Feb '23, 4:56am", "31 Jan '23, 8:56pm")
33+
.contains(timestamp)
34+
);
2535
}
2636

2737
@Test
2838
public void instantToPrettyTimestamp_zeroMinutes() {
2939
Instant instant = Instant.parse("2023-09-14T13:00:00Z");
3040
String timestamp = DateConverter.instantToPrettyTimestamp(instant);
31-
assertEquals("14 Sep '23, 9pm", timestamp);
41+
assertTrue(
42+
Arrays.asList("14 Sep '23, 9pm", "14 Sep '23, 1pm")
43+
.contains(timestamp)
44+
);
3245
}
3346
}

0 commit comments

Comments
 (0)