Files
Erupe/common/gametime/gametime.go
Houmgaor 2acbb5d03a feat(channelserver): implement monthly guild item claim tracking
Players could never claim monthly guild items because the handler
always returned 0x01 (claimed). Now tracks per-character per-type
(standard/HLC/EXC) claim timestamps in the stamps table, comparing
against the current month boundary to determine claim eligibility.

Adds MonthStart() to gametime, extends StampRepo with
GetMonthlyClaimed/SetMonthlyClaimed, and includes schema migration
31-monthly-items.sql.
2026-02-22 16:46:57 +01:00

45 lines
1.4 KiB
Go

package gametime
import (
"time"
)
// Adjusted returns the current time in JST (UTC+9), the timezone used by MHF.
func Adjusted() time.Time {
baseTime := time.Now().In(time.FixedZone("UTC+9", 9*60*60))
return time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), baseTime.Hour(), baseTime.Minute(), baseTime.Second(), baseTime.Nanosecond(), baseTime.Location())
}
// Midnight returns today's midnight (00:00) in JST.
func Midnight() time.Time {
baseTime := time.Now().In(time.FixedZone("UTC+9", 9*60*60))
return time.Date(baseTime.Year(), baseTime.Month(), baseTime.Day(), 0, 0, 0, 0, baseTime.Location())
}
// WeekStart returns the most recent Monday at midnight in JST.
func WeekStart() time.Time {
midnight := Midnight()
offset := int(midnight.Weekday()) - int(time.Monday)
if offset < 0 {
offset += 7
}
return midnight.Add(-time.Duration(offset) * 24 * time.Hour)
}
// WeekNext returns the next Monday at midnight in JST.
func WeekNext() time.Time {
return WeekStart().Add(time.Hour * 24 * 7)
}
// MonthStart returns the first day of the current month at midnight in JST.
func MonthStart() time.Time {
midnight := Midnight()
return time.Date(midnight.Year(), midnight.Month(), 1, 0, 0, 0, 0, midnight.Location())
}
// GameAbsolute returns the current position within the 5760-second (96-minute)
// in-game day/night cycle, offset by 2160 seconds.
func GameAbsolute() uint32 {
return uint32((Adjusted().Unix() - 2160) % 5760)
}