Skip to content

How do I round to a week #3063

Open
Open
@lucacasonato

Description

@lucacasonato

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:

  • round(): does not support week as a rounding mode
  • Temporal.ZonedDateTime.from({
      timeZone: dateTime.timeZoneId,
      year: dateTime.year,
      weekOfYear: dateTime.weekOfYear,
      dayOfWeek: 1,
    });
  • with(): does not support as an argument dayOfWeek

Is the only way to do this to manually by subtracting dayOfWeek from itself? Ie:

dateTime
  .round({ smallestUnit: "day", roundingMode: "trunc" })
  .subtract({ days: dateTime.dayOfWeek - 1 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions