Skip to content

Commit 6dc36eb

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

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
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");
17-
assertEquals(instantExpected, instantActual);
19+
Instant instantActual2 = DateConverter.timestampToInstant("1 1 31 2056");
20+
assertTrue(
21+
Arrays.asList(instantActual, instantActual2)
22+
.contains(instantExpected)
23+
);
1824
}
1925

2026
@Test
2127
public void instantToPrettyTimestamp_nonZeroMinutes() {
2228
Instant instant = Instant.parse("2023-01-31T20:56:00Z");
2329
String timestamp = DateConverter.instantToPrettyTimestamp(instant);
24-
assertEquals("1 Feb '23, 4:56am", timestamp);
30+
assertTrue(
31+
Arrays.asList("1 Feb '23, 4:56am", "31 Jan '23, 8:56pm")
32+
.contains(timestamp)
33+
);
2534
}
2635

2736
@Test
2837
public void instantToPrettyTimestamp_zeroMinutes() {
2938
Instant instant = Instant.parse("2023-09-14T13:00:00Z");
3039
String timestamp = DateConverter.instantToPrettyTimestamp(instant);
31-
assertEquals("14 Sep '23, 9pm", timestamp);
40+
assertTrue(
41+
Arrays.asList("14 Sep '23, 9pm", "14 Sep '23, 1pm")
42+
.contains(timestamp)
43+
);
3244
}
3345
}

0 commit comments

Comments
 (0)