Skip to content

Commit c4aa07f

Browse files
committed
A flow can use local time
Signed-off-by: Didier Wenzek <[email protected]>
1 parent bb5f526 commit c4aa07f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function onMessage (message) {
2+
let payload = JSON.parse(message.payload)
3+
let timestamp = message.timestamp
4+
let tzOffset = timestamp.getTimezoneOffset() * 60000;
5+
6+
payload.time = timestamp.toString();
7+
payload.utc = timestamp.toISOString();
8+
payload.local = (new Date(timestamp.getTime() - tzOffset)).toISOString().slice(0, -1);
9+
10+
return {
11+
topic: message.topic,
12+
payload: JSON.stringify(payload)
13+
}
14+
}

tests/RobotFramework/tests/tedge_flows/tedge_flows.robot

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ Test Tags theme:tedge_flows
1010

1111
*** Test Cases ***
1212
Add missing timestamps
13-
${transformed_msg} Execute Command tedge flows test --processing-time "2025-06-27 11:31:02" te/device/main///m/ '{}'
13+
${transformed_msg} Execute Command
14+
... tedge flows test --processing-time "2025-06-27 11:31:02" te/device/main///m/ '{}'
1415
Should Contain ${transformed_msg} item="time":"2025-06-27T11:31:02.000Z"
1516

1617
Convert timestamps to ISO
1718
${transformed_msg} Execute Command tedge flows test te/device/main///m/ '{"time": 1751023862.000}'
1819
Should Contain ${transformed_msg} item="time":"2025-06-27T11:31:02.000Z"
1920

21+
Convert message timestamps to local time
22+
Execute Command ln -sf /usr/share/zoneinfo/Australia/Brisbane /etc/localtime
23+
${transformed_msg} Execute Command
24+
... tedge flows test --flow get-localtime.js --processing-time "2025-11-19T11:31:02" t {}
25+
Should Contain ${transformed_msg} item="time":"Wed Nov 19 2025 21:31:02 GMT+1000"
26+
Should Contain ${transformed_msg} item="utc":"2025-11-19T11:31:02.000Z"
27+
Should Contain ${transformed_msg} item="local":"2025-11-19T21:31:02.000
28+
[Teardown] Execute Command ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
29+
2030
Extract measurement type from topic
2131
${transformed_msg} Execute Command
2232
... tedge flows test te/device/main///m/environment '{"temperature": 258}'

0 commit comments

Comments
 (0)