mirror of
https://github.com/Walter-Sparrow/lunar-tear.git
synced 2026-07-02 13:53:41 +03:00
28 lines
629 B
Go
28 lines
629 B
Go
package gametime
|
|
|
|
import "time"
|
|
|
|
func Now() time.Time {
|
|
return time.Now().UTC()
|
|
}
|
|
|
|
func NowMillis() int64 {
|
|
return Now().UnixMilli()
|
|
}
|
|
|
|
func StartOfDayMillis() int64 {
|
|
n := Now()
|
|
return time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, time.UTC).UnixMilli()
|
|
}
|
|
|
|
// WeeklyVersion returns a stable weekly identifier (start-of-week timestamp in millis, Monday 00:00 UTC).
|
|
func WeeklyVersion(millis int64) int64 {
|
|
t := time.UnixMilli(millis).UTC()
|
|
weekday := int(t.Weekday())
|
|
if weekday == 0 {
|
|
weekday = 7
|
|
}
|
|
monday := time.Date(t.Year(), t.Month(), t.Day()-(weekday-1), 0, 0, 0, 0, time.UTC)
|
|
return monday.UnixMilli()
|
|
}
|