You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a random Temporal.ZonedDateTime, I would like to get a Temporal.ZonedDateTime for the time 00:00:00.000000 of the first Monday before that time. I have tried:
Sorry the answer took so long; I lost this in my holiday notifications pile-up.
tl;dr, yes, subtracting dayOfWeek is the way to do it. You could make that code slightly smaller by using startOfDay() to truncate to midnight: dateTime.startOfDay().subtract(...) or if you just need the date and not the midnight, preferably toPlainDate(). See also https://tc39.es/proposal-temporal/docs/cookbook.html#nth-weekday-of-the-month for some similar recipes.
More background on why this is not supported by ZonedDateTime.p.round() is discussed in #1785. Unlike rounding a Duration, when you round a ZonedDateTime you are actually 'snapping' to the nearest start of a time unit. 'Start of a day' or 'start of a minute' are well-defined but 'start of a week' is not. We could choose to make it well-defined in the future, so there's a Temporal V2 issue open for exploring it: js-temporal/proposal-temporal-v2#20
The from() and with() ideas don't work because we don't support yearOfWeek/weekOfYear/dayOfWeek as a first-class scheme to create or manipulate dates. There's no reason why we couldn't, just that it didn't make the cut for V1. Here's the Temporal V2 issue for it, if you want to follow it: js-temporal/proposal-temporal-v2#11
Given a random
Temporal.ZonedDateTime
, I would like to get aTemporal.ZonedDateTime
for the time00:00:00.000000
of the first Monday before that time. I have tried:round()
: does not supportweek
as a rounding modewith()
: does not support as an argumentdayOfWeek
Is the only way to do this to manually by subtracting
dayOfWeek
from itself? Ie:The text was updated successfully, but these errors were encountered: