From 8aa3a0a15fece90e067be6b6af79bfaf38aa95be Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Tue, 3 May 2022 15:34:31 +0200 Subject: android 6 compatibility --- .../java/org/uic/barcode/test/TimeStampTest.java | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/test/java/org/uic') diff --git a/src/test/java/org/uic/barcode/test/TimeStampTest.java b/src/test/java/org/uic/barcode/test/TimeStampTest.java index f03a63c..a3e8256 100644 --- a/src/test/java/org/uic/barcode/test/TimeStampTest.java +++ b/src/test/java/org/uic/barcode/test/TimeStampTest.java @@ -84,6 +84,32 @@ public class TimeStampTest { assert (secondOfDay2 >= secondOfDay - 1); assert (secondOfDay2 <= secondOfDay + 1); - } + + @Test public void testSetDateTime() { + ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")); + Date dateNow = Date.from(now.toInstant()); + + TimeStamp ts = new TimeStamp(); + ts.setDateTime(dateNow); + + assert (ts.day.intValue() == now.get(ChronoField.DAY_OF_YEAR)); + assert (ts.secondOfDay.intValue() == now.get(ChronoField.SECOND_OF_DAY)); + } + + @Test public void testGetTimeAsDate() { + ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).withNano(0); // we ignore nano seconds + Date dateNow = Date.from(now.toInstant()); + + TimeStamp ts = new TimeStamp(); + ts.setDateTime(dateNow); + + Date resDate = ts.getTimeAsDate(); + + assert (resDate.getTime() == dateNow.getTime()); + ZonedDateTime res = ZonedDateTime.ofInstant(resDate.toInstant(), ZoneId.of("UTC")).withNano(0); + assert (res.compareTo(now) == 0); + + } + } -- cgit v1.2.3