EPL - Event.time or alarm.time - Extracting date from event/alarm.time

Hi,

in EPL, I need to make sure that both alarms happen at the same date before issuing some logic but I am facing an issue: Apparently APAMA uses Unix timestamp (milliseconds since epoch) and it doesn’t use the ISO timestamp

image

since in EPL we don’t have something like “datetime” like in python to do the needed date trip/split, how can we get the date where this event/alarm happened in EPL?

You can use TimeFormat utility to format timestamps, see TimeFormat

Would you please elaborate more?

so I should first add the following statement to the EPL:
“using com.apama.correlator.timeformat”

and then I should use in the code
timeformat.formatUTC(a1.time)?

if correct, then I need to do some split to get only the date. I need to do in EPL the equivalent to what I can do in python:

///////////////////////
// Convert to ISO 8601 string e.g., “2024-07-03T13:45:00.000+02:00”
datetime dt_a1 := datetime.fromMilliseconds(a1.time);

string isoTime_a1 := dt_a1.toString();

string dateOnly_a1 := isoTime_a1.split(“T”)[0]
///////////////////////////////////

is it possible?

there are some convenience functions available.

You can use either to get a value to compare two timestamps based on their dates only.

ok I will test daysSinceEpoch using the following EPL code snipet:
//////////////////////////////////
using com.apama.correlator.timeformat.TimeFormat;

monitor DaysSinceEpochExample {
action onload() {
on all Alarm() as a1 {
float days := TimeFormat.daysSinceEpoch(a1.time);
//////////////////////

and then I can compare the days of a1 to the days of a2, if the same then the alarms happened at the same day, is it a correct approach?

Yes, in general, but daysSinceEpoch returns an integer not a float. Can you guarantee that both timestamps are in the same timezone? If not going with daysSinceEpochUTC may be safer. (Update: if you get the timestamp from “currentTime” or from an alarm, event, or measurement, you should be fine).

yes both alarms from the same worker tag → Same timezone
many thanks for your input

and by the way, is there a way to import the “duration” object that we usually use in analytics builder to EPL? Duration contains a very useful input called RESET and we reset it every end of day to avoid measuring the time between 2 alarms from different days