archive/YearMonth.go

29 lines
550 B
Go

package archive
import (
"time"
)
type YearMonth struct {
Year int
// time.Month is a 1-based month counting system
Month time.Month
}
func CurrentYearMonth() YearMonth {
return YearMonth{time.Now().Year(), time.Now().Month()}
}
func (ym YearMonth) Equals(other YearMonth) bool {
return ym.Year == other.Year && ym.Month == other.Month
}
func (ym YearMonth) Next() YearMonth {
if ym.Month == time.December {
return YearMonth{Year: ym.Year + 1, Month: time.January}
} else {
return YearMonth{Year: ym.Year, Month: ym.Month + 1}
}
}