spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.99k stars 183 forks source link

unixFmt escape characters #207

Closed jayasurian123 closed 3 years ago

jayasurian123 commented 4 years ago

unixFmt method is not formatting correctly with 'T' eg. from the unit test case

let epoch = 1510850065194
let s = spacetime(epoch, 'Canada/Eastern')
s.unixFmt("yyyy-MM-dd'T'HH:mm:ssZ") // ISO8601Format
// output 2017-11-ddT11:34:25-0500
// desired output 2017-11-16T11:34:25-0500

Its somehow adds T to the previous character and makes it ddT.

I have tried to check it and fix my own but there were not enough test example case for the quoted string.

spencermountain commented 4 years ago

hey Jayasurian, thanks. Is there a reason why you add the apostrophes around the T?

it should work I think, like this:

let epoch = 1510850065194
let s = spacetime(epoch, 'Canada/Eastern')
let str = s.unixFmt('yyyy-MM-ddTHH:mm:ssZ') // ISO8601Format
// 2017-11-16T11:34:25-0500

let me know if I've misunderstood cheers

KaylaBrady commented 3 years ago

Hi -- having a similar issue here when trying to use unixFmt to format a time for display in French.

s.unixFmt("HH'h'mm")
// output:  HHh49
// expected output: 14h49
spencermountain commented 3 years ago

ah - thanks Kayla. Good eye. Will take a look at supporting the quote-style escaping. In the short-term, you'll probably have to split it into two fmt commands. cheers

KaylaBrady commented 3 years ago

Thanks! It seems to be only an issue when there is not a space before the quoted character -- ex this works as expected

s.unixFmt("HH 'h' mm")
// output: 14 h 49
// exected output: 14 h 49
spencermountain commented 3 years ago

fixed in v6.12.2 thanks!