Skip to content

Instantly share code, notes, and snippets.

@vivekmittal
Last active February 9, 2019 08:09
Show Gist options
  • Save vivekmittal/3d7d562950e28057a17927b37ef28410 to your computer and use it in GitHub Desktop.
Save vivekmittal/3d7d562950e28057a17927b37ef28410 to your computer and use it in GitHub Desktop.
Operational hour encoding
const OperationalHourStepSizeInMinutes = 5
func Encode(t time.Time) int64 {
return encode(int(t.Weekday()), t.Hour(), t.Minute())
}
func encode(weekday int, hour int, minute int) int64 {
wd := ((weekday*100 + hour) * 100) + (minute/OperationalHourStepSizeInMinutes)*OperationalHourStepSizeInMinutes
return int64(wd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment