34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
// AppTimezoneName is the default business timezone for Rezina (East Africa Time).
|
|
const AppTimezoneName = "Africa/Addis_Ababa"
|
|
|
|
// AppTimezone returns Africa/Addis_Ababa (EAT, UTC+3). Used as the default for
|
|
// calendar day filters, analytics buckets, and admin-facing date interpretation.
|
|
func AppTimezone() *time.Location {
|
|
loc, err := time.LoadLocation(AppTimezoneName)
|
|
if err != nil {
|
|
return time.FixedZone("EAT", 3*60*60)
|
|
}
|
|
return loc
|
|
}
|
|
|
|
// ParseDateOnly parses YYYY-MM-DD as midnight in the app timezone (EAT).
|
|
func ParseDateOnly(raw string) (time.Time, error) {
|
|
return time.ParseInLocation("2006-01-02", raw, AppTimezone())
|
|
}
|
|
|
|
// DateOnly truncates t to midnight in the app timezone (EAT).
|
|
func DateOnly(t time.Time) time.Time {
|
|
loc := AppTimezone()
|
|
local := t.In(loc)
|
|
return time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, loc)
|
|
}
|
|
|
|
// NextDateOnly returns the next calendar day at midnight in the app timezone.
|
|
func NextDateOnly(t time.Time) time.Time {
|
|
return DateOnly(t).AddDate(0, 0, 1)
|
|
}
|