esper - Cumulocity date formats -
i wondering why date format different between fields. rule declared this:
@name("measurement_occupation") context parkingspotoccupation insert createmeasurement select e.source source, "parkingspotoccupation" type, min(e.time) time, { "startdate", min(e.time), "enddate", max(e.time), "duration", datedifferenceinsec(max(e.time), min(e.time)) } fragments smartparkingevent e output last when terminated;
and result following using api measurements:
{ "time": "2016-05-30t06:00:00.000+02:00", "id": "33200", "self": "https://management.post-iot.lu/measurement/measurements/33200", "source": { "id": "26932", "self": "https://management.post-iot.lu/inventory/managedobjects/26932" }, "type": "parkingspotoccupation", "startdate": { "time": 1464580800000, "minutes": 0, "seconds": 0, "hours": 6, "month": 4, "timezoneoffset": -120, "year": 116, "day": 1, "date": 30 }, "duration": 600, "enddate": { "time": 1464581400000, "minutes": 10, "seconds": 0, "hours": 6, "month": 4, "timezoneoffset": -120, "year": 116, "day": 1, "date": 30 } }
why ate time , startdate/enddate rendered differently? stranger, when output of event processig rule displayed formatted follows:
{ "time": { "date": 30, "day": 1, "hours": 6, "minutes": 0, "month": 4, "seconds": 0, "time": 1464580800000, "timezoneoffset": -120, "year": 116 }, "source": "26932", "fragments": [ "startdate", { "date": 30, "day": 1, "hours": 6, "minutes": 0, "month": 4, "seconds": 0, "time": 1464580800000, "timezoneoffset": -120, "year": 116 }, "enddate", { "date": 30, "day": 1, "hours": 6, "minutes": 10, "month": 4, "seconds": 0, "time": 1464581400000, "timezoneoffset": -120, "year": 116 }, "duration", 600 ], "type": "parkingspotoccupation" }
so every date looks same, not when use api access measurements. i'd dates stored in format: "2016-05-30t06:00:00.000+02:00". tried use cast(min(e.time), date) got error (class listed in cast function name 'date' cannot loaded). , tried todate() function didn't change anything.
the issue in esper dates date class in java , when parsing not nice structure.
easiest way format iso string yourself. can use java simpledateformat. declare in module.
create constant variable simpledateformat iso_formatter = new simpledateformat("yyyy-mm-dd't'hh:mm:ssz");
and use it
iso_formatter.format(min(e.time)) iso_formatter.format(max(e.time))
and returns iso string of date
Comments
Post a Comment