add strftimeUTC(...)
andrewschaaf opened this issue · comments
Lily commented
Same as strftime, but using d.getUTC{Hours,...}
Lily commented
Here's a hacky approach:
UTCify_date = (x) -> y = new Date() y.setFullYear x.getUTCFullYear() y.setMonth x.getUTCMonth() y.setDate x.getUTCDate() y.setHours x.getUTCHours() y.setMinutes x.getUTCMinutes() y.setSeconds x.getUTCSeconds() y.setMilliseconds x.getUTCMilliseconds() y exports.strftimeUTC = strftimeUTC = (format, d) -> strftime format, UTCify_date(d)
Lily commented
Would this hack be merged if it also special-cased %z
and %z
?
Sami Samhuri commented
Seems useful, I would merge this. I was surprised to see there's no way to convert a Date to UTC directly.
It's still a hack but how about instead of setting so many properties we use the TZ offset, e.g.
function toUTC(d) { return new Date(+d - (1000 * 60 * 60 * d.getTimezoneOffset() || 0)) }
Do you see any problems with that method? I have || 0
in case getTimezoneOffset
returns NaN
. The math might be off but you get the idea.