Skip to content

OS X "strptime" results inconsistent with Linux #929

Open
@vielmetti

Description

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.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions