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 ++++++++++++++++++++++ .../protocol/TramigoProtocolDecoderTest.java | 6 ++--- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 test/org/traccar/helper/DateUtilTest.java (limited to 'test/org') 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)); + + } + +} diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index da04e5bf1..9ac02a7ad 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -12,11 +12,11 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(new TramigoProtocol()); - /*verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, "80005408b000af000101b23903677f00c8436d3842616c697365204f6e653a20416c6c756d616765206d61726368652064e974656374e92c20676172e92c20302e3735206b6d20452064652045636f6c65204175746f726f757465206465204b696e73686173612c2056696c6c65206465204b696e73686173612c204b696e73686173612c2043442c202d342e33343130362c2031352e33343931352c2030313a3030204a616e2031202020454f46")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, - "8000011bb0009e0001015b93032ef6f35994a9545472616d69676f3a204d6f76696e672c20302e3930206b6d205345206f66204372616e6562726f6f6b20466972652053746174696f6e2c2050656e726974682c205379646e65792c2041552c202d33332e37303732322c203135302e37313735392c2053452077697468207370656564203337206b6d2f682c2031393a3438204a616e20342020454f46"));*/ + //verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + // "8000011bb0009e0001015b93032ef6f35994a9545472616d69676f3a204d6f76696e672c20302e3930206b6d205345206f66204372616e6562726f6f6b20466972652053746174696f6e2c2050656e726974682c205379646e65792c2041552c202d33332e37303732322c203135302e37313735392c2053452077697468207370656564203337206b6d2f682c2031393a3438204a616e20342020454f46")); // Tramigo: Parked, 0.12 km E of McDonald's H.V. dela Costa, Makati, 11:07 Mar 27 // Tramigo: Moving, 0.90 km SE of Cranebrook Fire Station, Penrith, Sydney, AU, -33.70722, 150.71759, SE with speed 37 km/h, 19:48 Jan 4 EOF -- cgit v1.2.3