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

How do I round to a week #3063

Open
lucacasonato opened this issue Dec 11, 2024 · 0 comments
Open

How do I round to a week #3063

lucacasonato opened this issue Dec 11, 2024 · 0 comments

Comments

@lucacasonato
Copy link
Member

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 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant