Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom string when instantiating #179

Open
iamvanja opened this issue Dec 30, 2019 · 4 comments
Open

Custom string when instantiating #179

iamvanja opened this issue Dec 30, 2019 · 4 comments

Comments

@iamvanja
Copy link

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?

@spencermountain
Copy link
Owner

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
Copy link
Owner

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

@iamvanja
Copy link
Author

iamvanja commented Jan 5, 2020

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

@spencermountain
Copy link
Owner

spencermountain commented Jan 5, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants