You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The task I'm trying to accomplish is to pull in data from a data source that has timestamps but that doesn't specify time zone or daylight savings time. Ideally I'll get an accurate "seconds since the epoch" when I'm done parsing.
The problem is that I get different results depending on whether I'm on OS X Mavericks or on Linux Ubuntu. Here's a small sample script; I'm in EDT:
date | sed -e 's/^/\"/' -e 's/$/\"/'| ./jq '(strptime("%a %b %d %H:%M:%S %Z %Y")|mktime) - now'
(feed the output of the date command into jq as a string, parse the time, subtract current time, result in seconds).
On OS X I typically get output like -14400.879971027374 which corresponds to 4 hours off.
On Ubuntu I get output like -0.6590850353240967 which is less than a second off.
If I had to guess, there's something to do with this in the OS X docs:
The %Z format specifier only accepts time zone abbreviations of the local
time zone, or the value "GMT". This limitation is because of ambiguity
due to of the over loading of time zone abbreviations. One such example
is EST which is both Eastern Standard Time and Eastern Australia Summer
Time.
but not in the Ubuntu docs, which reference glibc:
%Z The timezone name.
The text was updated successfully, but these errors were encountered:
As for fixing it, either "this is documented behavior" (OK) or perhaps somehow build and load the GNU datetime libraries (to give predictable and testable behavior).
Is there a GNU datetime library? We'd not link against it if it's GPL though. Anyways, yes, we rely on the C library for datetime support, so if the OS' C library implementation's strptime() does not support the %Z input field descriptor, well, there's nothing we can do. They should all support UTC though.
The task I'm trying to accomplish is to pull in data from a data source that has timestamps but that doesn't specify time zone or daylight savings time. Ideally I'll get an accurate "seconds since the epoch" when I'm done parsing.
The problem is that I get different results depending on whether I'm on OS X Mavericks or on Linux Ubuntu. Here's a small sample script; I'm in EDT:
(feed the output of the date command into jq as a string, parse the time, subtract current time, result in seconds).
On OS X I typically get output like -14400.879971027374 which corresponds to 4 hours off.
On Ubuntu I get output like -0.6590850353240967 which is less than a second off.
If I had to guess, there's something to do with this in the OS X docs:
but not in the Ubuntu docs, which reference glibc:
The text was updated successfully, but these errors were encountered: