yearmonth: extract to separate file
This commit is contained in:
parent
e0dc2fe930
commit
4a7a3ba867
@ -4,13 +4,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type YearMonth struct {
|
|
||||||
Year int
|
|
||||||
|
|
||||||
// time.Month is a 1-based month counting system
|
|
||||||
Month time.Month
|
|
||||||
}
|
|
||||||
|
|
||||||
type LogLocation struct {
|
type LogLocation struct {
|
||||||
|
|
||||||
// LogFilePath will be passed to time.Format().
|
// 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)
|
// assume it's the last in the list (although it might not be)
|
||||||
end := this.FileLocation[len(this.FileLocation)-1].EndMonth
|
end := this.FileLocation[len(this.FileLocation)-1].EndMonth
|
||||||
if end == nil {
|
if end == nil {
|
||||||
return YearMonth{time.Now().Year(), time.Now().Month()}
|
return CurrentYearMonth()
|
||||||
} else {
|
} else {
|
||||||
return *end
|
return *end
|
||||||
}
|
}
|
||||||
|
28
YearMonth.go
Normal file
28
YearMonth.go
Normal 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}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user