spacetime icon indicating copy to clipboard operation
spacetime copied to clipboard

Custom string when instantiating

Open iamvanja opened this issue 5 years ago • 4 comments

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?

iamvanja avatar Dec 30 '19 23:12 iamvanja

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.

spencermountain avatar Jan 02 '20 19:01 spencermountain

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

spencermountain avatar Jan 02 '20 19:01 spencermountain

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).

iamvanja avatar Jan 05 '20 19:01 iamvanja

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 .

spencermountain avatar Jan 05 '20 22:01 spencermountain