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
I have a need to figure out how many (ISO) week numbers have passed between two dates. This is an error prone calculation. So if one date is in week 34 and another in week 32 I want 34 - 32 = 2.
Idea 1: Take the difference in days between the dates and divide by 7. Does not work because there might be a week boundary between two dates even though less than 7 days have passed.
Idea 2: Convert both dates to IsoWeek and subtract the week numbers. This breaks if there is a year boundary between the weeks.
Idea 3: Convert both dates to IsoWeek and subtract the week numbers, as well as a fixed multiplier for the number of years in between them. Does not work since a year can have varying numbers of weeks.
Idea 4: Convert both dates to IsoWeek, get the years and week numbers for both, use those numbers to generate new dates using NaiveDate::from_isoywd_opt and a fixed day of week, subtract those to get a duration, divide the number of days in that duration by 7 to get elapsed weeks. This works (unless there's another edge case I missed), but this is getting very convoluted for a conceptually simple calculation.
Proposal: Add a method to IsoWeek that compares it to another IsoWeek and returns the number of weeks between them.
The text was updated successfully, but these errors were encountered:
Hi,
I have a need to figure out how many (ISO) week numbers have passed between two dates. This is an error prone calculation. So if one date is in week 34 and another in week 32 I want 34 - 32 = 2.
IsoWeek
and subtract the week numbers. This breaks if there is a year boundary between the weeks.IsoWeek
and subtract the week numbers, as well as a fixed multiplier for the number of years in between them. Does not work since a year can have varying numbers of weeks.IsoWeek
, get the years and week numbers for both, use those numbers to generate new dates usingNaiveDate::from_isoywd_opt
and a fixed day of week, subtract those to get a duration, divide the number of days in that duration by 7 to get elapsed weeks. This works (unless there's another edge case I missed), but this is getting very convoluted for a conceptually simple calculation.Proposal: Add a method to
IsoWeek
that compares it to anotherIsoWeek
and returns the number of weeks between them.The text was updated successfully, but these errors were encountered: