MCPcopy Index your code
hub / github.com/coder/coder / GetMondayOfWeek

Function GetMondayOfWeek

coderd/schedule/autostop.go:340–355  ·  view source on GitHub ↗

GetMondayOfWeek gets the Monday (0:00) of the n-th week since epoch.

(loc *time.Location, n int64)

Source from the content-addressed store, hash-verified

338
339// GetMondayOfWeek gets the Monday (0:00) of the n-th week since epoch.
340func 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

Callers 2

TestFindWeekFunction · 0.92

Calls 3

NewMethod · 0.65
ErrorfMethod · 0.45

Tested by 1

TestFindWeekFunction · 0.74