Skip to content

Commit

Permalink
devfeat(test): Support UTC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloud7050 committed Sep 21, 2023
1 parent 8fd31e0 commit 6dc36eb
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/test/java/com/cloud/chatbot/DateConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
package com.cloud.chatbot;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.Instant;
import java.util.Arrays;

import org.junit.jupiter.api.Test;



// Assuming the "user" is on a GMT+8 system
// Assuming the "user" is on a GMT+8 or GMT/UTC system
public class DateConverterTest {
@Test
public void timestampToInstant() {
Instant instantExpected = Instant.parse("2023-01-31T20:56:00Z");
Instant instantActual = DateConverter.timestampToInstant("1 2 23 456");
assertEquals(instantExpected, instantActual);
Instant instantActual2 = DateConverter.timestampToInstant("1 1 31 2056");
assertTrue(
Arrays.asList(instantActual, instantActual2)
.contains(instantExpected)
);
}

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

@Test
public void instantToPrettyTimestamp_zeroMinutes() {
Instant instant = Instant.parse("2023-09-14T13:00:00Z");
String timestamp = DateConverter.instantToPrettyTimestamp(instant);
assertEquals("14 Sep '23, 9pm", timestamp);
assertTrue(
Arrays.asList("14 Sep '23, 9pm", "14 Sep '23, 1pm")
.contains(timestamp)
);
}
}

0 comments on commit 6dc36eb

Please sign in to comment.