You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

package tools
import "time"
func GetStartOfLastMonth() time.Time {
d := time.Now().AddDate(0, -1, 0)
return GetZeroTime(d)
}
func GetFirstDateOfMonth(d time.Time) time.Time {
d = d.AddDate(0, 0, -d.Day()+1)
return GetZeroTime(d)
}
func GetFirstDateOfNextMonth(d time.Time) time.Time {
lastDay := GetFirstDateOfMonth(d).AddDate(0, 1, -1)
return lastDay.Add(24 * time.Hour)
}
func GetZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
}
func GetTodayStartPoint() time.Time {
now := time.Now()
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
}
func GetYesterdayStartPoint() time.Time {
now := time.Now().Add(-24 * time.Hour)
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
}
func GetSevenDayStartPoint() time.Time {
now := time.Now().Add(-24 * 7 * time.Hour)
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
}
func GetNextDayStartPoint() time.Time {
next := time.Now().Add(24 * time.Hour)
return time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, time.Local)
}
func GetToday23Clock() time.Time {
now := time.Now()
return time.Date(now.Year(), now.Month(), now.Day(), 23, 0, 0, 0, time.Local)
}
func GetTomorrow23Clock() time.Time {
next := time.Now().Add(24 * time.Hour)
return time.Date(next.Year(), next.Month(), next.Day(), 23, 0, 0, 0, time.Local)
}