spacetime
spacetime copied to clipboard
Custom string when instantiating
Is something like this not possible?
const d = spacetime(
'12/30/19 12:22:08 PM', // pass unix format for spacetime to understand how to parse this value in options?
'Pacific/Honolulu',
{ silent: false } // format: 'MM/dd/yy hh:mm:ss a'
);
Expected to get a datetime instance of this date/time in Hawaii, but instead
d.isValid(); // false
d.unxFmt('MM/dd/yy hh:mm:ss a'); // 12/31/69 02:00:00 PM
Also, in TS, { silent: false }
fails because weekStart
is required. Is this by design?
Furthermore, dmy
field is mentioned as an option in the README, but it is not part of the type definitions?
hi Vanja, thank you for this. Yeah, we need to be more explicit about which input formats are supported in the docs. This month, and into 2020, I'd like to greatly improve them.
Out of curiosity, where is that '12/30/19 12:22:08 PM'
format from? That looks like one I'm not familiar with. I'm happy to support it.
Re:Typescript - thank you, i've fixed it on dev.
yeah, and IMO, when there's silent:false
, it should log something that it failed to parse the date string. That would be the best behaviour.
Oh - and lastly - I think the missing dmy
thing is just a function of it refusing to log the invalid date. This seems to work:
let d = spacetime.now()
console.log(d.format('dmy'))
Thanks for your help
Happy New Year!
12/30/19 12:22:08 PM
is coming from a server of which I have no control over. It would be nice to have a string parser given the passed format
option so that it can be intercepted before instantiating Date (and spacetime
).
Ok, I agree. I’ll add it to the next release.
On Sunday, January 5, 2020, Vanja Gavric [email protected] wrote:
Happy New Year! 12/30/19 12:22:08 PM is coming from a server of which I have no control over. It would be nice to have a string parser given the passed format option so that it can be intercepted before instantiating Date (and spacetime).
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/spencermountain/spacetime/issues/179?email_source=notifications&email_token=AADBSKPHYSXDK5DQBVOVFWTQ4IWPXA5CNFSM4KBRA42KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEID5L2Q#issuecomment-570938858, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADBSKMCQWGEMBL5XZKDCV3Q4IWPXANCNFSM4KBRA42A .