GetMondayOfWeek gets the Monday (0:00) of the n-th week since epoch.
(loc *time.Location, n int64)
| 338 | |
| 339 | // GetMondayOfWeek gets the Monday (0:00) of the n-th week since epoch. |
| 340 | func GetMondayOfWeek(loc *time.Location, n int64) (time.Time, error) { |
| 341 | if n < 0 { |
| 342 | return time.Time{}, xerrors.New("weeks since epoch must be positive") |
| 343 | } |
| 344 | epoch := TemplateAutostopRequirementEpoch(loc) |
| 345 | monday := epoch.AddDate(0, 0, int(n*7)) |
| 346 | |
| 347 | y, m, d := monday.Date() |
| 348 | monday = time.Date(y, m, d, 0, 0, 0, 0, loc) |
| 349 | if monday.Weekday() != time.Monday { |
| 350 | // This condition should never be hit, but we have a check for it just |
| 351 | // in case. |
| 352 | return time.Time{}, xerrors.Errorf("calculated incorrect Monday for week %v since epoch (actual weekday %q)", n, monday.Weekday()) |
| 353 | } |
| 354 | return monday, nil |
| 355 | } |
| 356 | |
| 357 | // GetNextApplicableMondayOfNWeeks gets the next Monday (0:00) of the next week |
| 358 | // divisible by n since epoch. If the next applicable week is invalid for any |