From 865c6e3fdccc5b59b55501aa58fd921cdb8a1ec1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 2 Jan 2016 09:24:45 +1300 Subject: Correct date if device sends not full time --- test/org/traccar/helper/DateUtilTest.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/org/traccar/helper/DateUtilTest.java (limited to 'test/org/traccar/helper') diff --git a/test/org/traccar/helper/DateUtilTest.java b/test/org/traccar/helper/DateUtilTest.java new file mode 100644 index 000000000..ae5f20696 --- /dev/null +++ b/test/org/traccar/helper/DateUtilTest.java @@ -0,0 +1,29 @@ +package org.traccar.helper; + +import org.junit.Assert; +import org.junit.Test; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class DateUtilTest { + + @Test + public void testCorrectDate() throws ParseException { + + DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + Assert.assertEquals(f.parse("2015-12-31 23:59:59"), + DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2016-01-01 23:59:59"), Calendar.DAY_OF_MONTH)); + + Assert.assertEquals(f.parse("2016-01-01 00:00:02"), + DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2016-01-01 00:00:02"), Calendar.DAY_OF_MONTH)); + + Assert.assertEquals(f.parse("2016-01-01 00:00:02"), + DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2015-12-31 00:00:02"), Calendar.DAY_OF_MONTH)); + + } + +} -- cgit v1.2.3