Skip to content

Instantly share code, notes, and snippets.

@awaxa
Last active February 23, 2017 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awaxa/f7f4693c9601539c087f93631227ff96 to your computer and use it in GitHub Desktop.
Save awaxa/f7f4693c9601539c087f93631227ff96 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# set -v
export TZ=America/Los_Angeles
node -e 'console.log(JSON.stringify({date: (new Date).getTime()}))' | jq '.date/1000 | strftime("%Y-%m-%d %H:%M:%S %Z")'
export TZ=America/New_York
node -e 'console.log(JSON.stringify({date: (new Date).getTime()}))' | jq '.date/1000 | strftime("%Y-%m-%d %H:%M:%S %Z")'
export TZ=UTC
node -e 'console.log(JSON.stringify({date: (new Date).getTime()}))' | jq '.date/1000 | strftime("%Y-%m-%d %H:%M:%S %Z")'
@awaxa
Copy link
Author

awaxa commented Feb 23, 2017

"2017-02-23 13:58:07 PST"
"2017-02-23 13:58:07 EST"
"2017-02-23 13:58:07 UTC"

@awaxa
Copy link
Author

awaxa commented Feb 23, 2017

For posterity, according to https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/strptime.3.html

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.

I believe this is cause of what I demonstrated above.

@nicowilliams
Copy link

nicowilliams commented Feb 23, 2017

Can you show the inputs that jq is getting? Make it

node -e 'console.log(JSON.stringify({date: (new Date).getTime()}))' | jq '.date/1000 | (., strftime("%Y-%m-%d %H:%M:%S %Z"))'

EDIT: Never mind, I can reproduce this.

@nicowilliams
Copy link

@nicowilliams
Copy link

Thanks for the bug report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment