valera/internal/modules/times/times.go

39 lines
549 B
Go
Raw Permalink Normal View History

2023-04-15 12:13:10 +00:00
package times
2023-04-16 10:08:40 +00:00
import (
"time"
)
2023-04-15 12:13:10 +00:00
2023-04-16 10:08:40 +00:00
var (
loc *time.Location
)
func init() {
loc, _ = time.LoadLocation("Asia/Novosibirsk")
}
func GetNow() time.Time {
2023-04-15 12:13:10 +00:00
t := time.Now().In(loc)
2023-04-16 10:08:40 +00:00
return t
}
func GetStartDay() time.Time {
t := GetNow()
2023-04-15 12:13:10 +00:00
t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, loc)
return t
}
2023-04-16 10:08:40 +00:00
func GetStartDayMinus(days int) time.Time {
t := GetStartDay()
for i := 0; i < days; i++ {
t = t.Add(-24 * time.Hour)
}
return t
}
2023-04-15 12:13:10 +00:00
func GetStartWeek() time.Time {
t := GetStartDay()
t = t.Add(-6 * 24 * time.Hour)
return t
}