yearmonth: extract to separate file

This commit is contained in:
mappu 2017-08-13 14:40:26 +12:00
parent e0dc2fe930
commit 4a7a3ba867
2 changed files with 29 additions and 8 deletions

View File

@ -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
}

28
YearMonth.go Normal file
View File

@ -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}
}
}