String to Time not preserving original value?


#1

1) Give a description of the problem
I have a piston that’s retrieving a response from a 3rd-party web service. One of the fields from that service is a date and time in ISO 8601 format. I’m trying to convert it into a webCoRE datetime format, but it’s ignoring the time zone and dropping the seconds. As I was testing things, I discovered that the same thing happens if I take time($now), convert it to a string, and then try to convert it back to a time. Is there a better way to convert a string to a time that preserves all of the data?

2) What is the expected behavior?
Converting a time to a string and then back to a time should produce the same as the original value, including the seconds, microseconds, and time zone.

3) What is happening/not happening?
If I take time($now), convert it to a string using string(time($now)), then convert it back to a time using time(string(time($now))), the result is different from the original time value.

4) Post a Green Snapshot of the piston!!

5) Attach any logs
+1ms ╔Received event [Home].test = 1536542374231 with a delay of 0ms +99ms ║RunTime Analysis CS > 17ms > PS > 69ms > PE > 13ms > CE +102ms ║Runtime (39391 bytes) successfully initialized in 69ms (v0.3.108.20180906) (100ms) +104ms ║╔Execution stage started +112ms ║║Cancelling statement #1's schedules... +124ms ║║Executed virtual command setVariable (4ms) +140ms ║║8:19:34 PM CDT +142ms ║║Executed virtual command log (2ms) +165ms ║║3:19:00 PM CDT +166ms ║║Executed virtual command log (2ms) +172ms ║╚Execution stage complete. (68ms) +174ms ╚Event processed successfully (173ms)


#2

Have you tried using formatDateTime function to manipulate your date instead of converting it to a string?

https://wiki.webcore.co/Functions#formatDateTime


#3

I thought formatDateTime was only used for converting a datetime to a string. In this case, I’m receiving a string from a 3rd-party service that I need to convert into a datetime. Can formatDateTime also be used for that?


#4

If you have a simple piston with the raw date value you receive and the end result of the formatted dates.


#5

@bangali maybe a similar issue to the datetime bug that you fixed? time() is acting strangely when given a time zone mapping back to GMT or similar (current zone here is EDT):

(expression) time('9:40:26 AM') »»» (time) 34800000
(expression) time('9:40:26 AM EST') »»» (time) 38400000
(expression) time('9:40:26 AM EDT') »»» (time) 20400000

#6

it’s odd that its a 5 hour difference. will take a look.

edit: maybe not so odd when you consider the 4 hour difference between EDT and GMT plus the extra hour for EDT to EST.


#7

|+106ms|║Mon, Sep 10 2018 @ 11:13:51 AM CDT|
|+115ms|║Mon, Sep 10 2018 @ 11:13:51 AM CDT|
|+122ms|║2018-09-10T16:13:51.000+00:00|
|+142ms|║Mon, Sep 10 2018 @ 4:13:00 PM CDT|
|+150ms|║2018-09-10T16:13:51.000 GMT|
|+169ms|║Mon, Sep 10 2018 @ 11:13:00 AM CDT|