bigeasy / timezone

Full-blown timezone aware date math and formatting for JavaScript in 2.7k.
http://bigeasy.github.io/timezone
MIT License
255 stars 26 forks source link

Show positive nanosecond for dates prior 1970-01-01. #326

Closed covin closed 4 years ago

covin commented 4 years ago

JavaScript modulo operator calculates a negative remainder if the dividend becomes negative. Thus current implementation renders signed nanoseconds on %N directive for negative timestamps, i.e. dates prior 1970-01-01:

var d = '1969-12-31 23:59:59.100'
var utc = tz(d) // -900
tz(utc, '%Y-%m-%d %H:%M:%S.%3N')
// -> "1969-12-31 22:59:59.-90"
bigeasy commented 4 years ago

Lovely. Can you make it a one-liner? Not using the function you generated anywhere else, so just put the logic in the anonymous function.

covin commented 4 years ago

Of course.