js-temporal/temporal-polyfill

Allow creation of Temporal objects from ordinal informations

khawarizmus opened this issue · 1 comments

Currently the polyfill implementation does not allow creation of Temporal objects from yearDay property. for example this code does not run and throws and error that day property is needed.

Temporal.PlainDateTime.from({ year: 2024, yearDay: 1 })

as for the following example:

const date = Temporal.PlainDateTime.from({ year: 2024, month: 2, day: 5, yearDay: 1 })

which doesn't throw any error creates a 2024-02-05T00:00:00 PlainDateTime Temporal object.

I expect the first example to have created a 2024-01-01T00:00:00 PlainDateTime Temporal object.

Thanks for the suggestion. This repo is a polyfill for the Temporal proposal. That proposal doesn't include the ability to use from with a day-of-year argument, so this polyfill does not implement this capability either. Temporal is very close to being finished and incorporated into the ECMAScript language, so no new APIs are being added to it. Therefore, I'm going to close this issue here.

There's a Temporal V2 repo that's used for suggestions to add to future iterations of the Temporal API.

In the meantime, what you're looking for can be easily accomplished by adding days to the first day of the year. Like this:

function plainDateFromYearDay({year, dayOfYear}) {
  return Temporal.PlainDate.from({ year, month: 1, day: 1 }).add({ days: dayOfYear-1 });
}
plainDateFromYearDay({ year: 2024, dayOfYear: 77 });
// => 2024-03-17

which doesn't throw any error creates a 2024-02-05T00:00:00 PlainDateTime Temporal object.

This is expected behavior. When a Temporal from method sees an unknown property in its input, that property is ignored.