electricity_bill_calc_service/utils/time.go

30 lines
718 B
Go

package utils
import (
"time"
)
func VeryBeginOfDate(date time.Time) time.Time {
return time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
}
func VeryEndOfDate(date time.Time) time.Time {
return time.Date(date.Year(), date.Month(), date.Day(), 23, 59, 59, 999999999, date.Location())
}
func DifferenceInMonth(t1, t2 time.Time) int {
var differYear, differMonth int
if t1.After(t2) {
differYear = t1.Year() - t2.Year()
differMonth = int(t1.Month() - t2.Month())
} else {
differYear = t2.Year() - t1.Year()
differMonth = int(t2.Month() - t1.Month())
}
return differYear*12 + differMonth
}
func IsNextMonth(t1, t2 time.Time) bool {
return DifferenceInMonth(t1, t2) == 1
}