diff --git a/Config.go b/Config.go index 0488eec..a36901b 100644 --- a/Config.go +++ b/Config.go @@ -4,13 +4,6 @@ import ( "time" ) -type YearMonth struct { - Year int - - // time.Month is a 1-based month counting system - Month time.Month -} - type LogLocation struct { // LogFilePath will be passed to time.Format(). @@ -37,7 +30,7 @@ func (this *LogSource) LatestDate() YearMonth { // assume it's the last in the list (although it might not be) end := this.FileLocation[len(this.FileLocation)-1].EndMonth if end == nil { - return YearMonth{time.Now().Year(), time.Now().Month()} + return CurrentYearMonth() } else { return *end } diff --git a/YearMonth.go b/YearMonth.go new file mode 100644 index 0000000..4495392 --- /dev/null +++ b/YearMonth.go @@ -0,0 +1,28 @@ +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} + } +}