48 lines
862 B
Go
48 lines
862 B
Go
package main
|
|
|
|
import "time"
|
|
|
|
func wrap (value, around int) (wrapped int) {
|
|
wrapped = value % around
|
|
if wrapped < 0 {
|
|
wrapped += around
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func firstOfMonth (year int, month time.Month) (day time.Time) {
|
|
day = time.Date(year, month, 0, 0, 0, 0, 0, time.Local)
|
|
return
|
|
}
|
|
|
|
func daysInMonth (year int, month time.Month) (days int) {
|
|
switch month {
|
|
case 1: days = 31
|
|
case 2:
|
|
// betcha didn't know this about leap years
|
|
if year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) {
|
|
days = 29
|
|
} else {
|
|
days = 28
|
|
}
|
|
case 3: days = 31
|
|
case 4: days = 30
|
|
case 5: days = 31
|
|
case 6: days = 30
|
|
case 7: days = 31
|
|
case 8: days = 31
|
|
case 9: days = 30
|
|
case 10: days = 31
|
|
case 11: days = 30
|
|
case 12: days = 31
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func canonMonth (when time.Time) (month int) {
|
|
month = int(when.Month() - 1) + when.Year() * 12
|
|
return
|
|
}
|