_This issue is copied over from the temporal polyfil repo_
Hi there,
I maintain a javascript recurring dates/schedule library, rSchedule, which happens to be date library agnostic (i.e. it supports moment, luxon, js-joda, and standard Date). For fun, I decided to try implementing a date adapter for the temporal polyfill and running it against my tests. Eventually I realized that the version of this polyfill on NPM is pretty behind the version in this repo. That alone would have stopped my experiment.
Even basing my implementation of the current temporal API though, I ended up giving up when it became apparent that I was going to need to do more work than I realized. A few usability issues with the current API:
new CivilDateTime() / new ZonedDateTime()/ etc like new Date() to get an object with the current local clock's values (and current timezone, if applicable).CivilDateTime nor ZonedDateTime have a fromObject() static method to simplify the creation of new CivilDateTime / ZonedDateTime.ZonedDateTime.fromObject({year: 2019, month: 10, day: 10, timeZone: 'America/Los_Angeles'}) (units not provided would default to 0, or 1 in the case of month/day)ZonedDateTime.with() rather than ZonedDateTime.fromObject().Date#toISOString() on ZonedDateTime to see what the value looks like as a string in UTC.toISOString(), but in development I often find it quite handy.new CivilDate(2010, 10, 1).lengthOfMonth === 31ZonedDateTime.prototype.set(arg: DateTimeLike) method.with() does thisAlso another annoyance which may not be universally applicable, but in my case I'm using both CivilDateTime and ZonedDateTime together. Having ZonedDateTime implement getCivilDateTime() but not having CivilDateTime implement it means that I need to check what type of object I'm dealing with, rather than simply call date.getCivilDateTime() and know that I've got a CivilDateTime.
In general, I think the API could be improved by normalizing the interfaces between objects, even when that means CivilDateTime#getCivilDateTime() simply returns the same object. Not sure if this will be a feeling others share though.
I'm closing this since it's being documented in #154 and reflected in the current polyfill.
THANKS!
I'm strongly seconding @thefliik 's feedback about
can't do ZonedDateTime.fromObject({year: 2019, month: 10, day: 10, timeZone: 'America/Los_Angeles'})
Is it captured in #154 ? Couldn't find it.
The method was named fromObject() at the time, but now it's just from(), this should work: Temporal.ZonedDateTime.from({year: 2019, month: 10, day: 10, timeZone: 'America/Los_Angeles'})
Most helpful comment
The method was named fromObject() at the time, but now it's just from(), this should work:
Temporal.ZonedDateTime.from({year: 2019, month: 10, day: 10, timeZone: 'America/Los_Angeles'})