Skip to content

Instantly share code, notes, and snippets.

@ScalaWilliam
Last active January 2, 2017 02:49
Show Gist options
  • Save ScalaWilliam/2cd79a9e2703b062fca66bedb0b6ba59 to your computer and use it in GitHub Desktop.
Save ScalaWilliam/2cd79a9e2703b062fca66bedb0b6ba59 to your computer and use it in GitHub Desktop.
#!/usr/bin/jjs
function cstTime(unixTime) {
var instant = java.time.Instant.ofEpochSecond(unixTime);
var zoned = instant.atZone(java.time.ZoneId.of("America/New_York"));
return java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.format(zoned);
}
java.nio.file.Files.lines(
java.nio.file.Paths.get("/dev/stdin")
).map(JSON.parse)
.map(function(obj) { obj.iso_timestamp = cstTime(obj.unix_timestamp); return obj; })
.map(JSON.stringify)
.forEach(print);
/*
Usage:
./add-ny-time-json.js << EOF
{"unix_timestamp": 1552134142}
{"unix_timestamp": 1552134143}
{"unix_timestamp": 1562134142}
EOF
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment