Documentation
¶
Overview ¶
Package timezone provides timezone utilities for the DivineSense application.
This package handles timezone conversions, parsing, and formatting to ensure consistent time handling across the application.
Index ¶
- Constants
- Variables
- func EndOfDay(t time.Time, tz *time.Location) time.Time
- func FormatScheduleForContext(startTs int64, endTs *int64, title string, location string, allDay bool, ...) string
- func FormatScheduleTime(startTs int64, endTs *int64, allDay bool, tz *time.Location) string
- func FormatTimeWithTimezone(ts int64, tz *time.Location, format string) string
- func GetDefaultTimezone() *time.Location
- func IsValidTimezone(tz string) bool
- func MustParseTimezone(tz string) *time.Location
- func NowInTimezone(tz *time.Location) time.Time
- func ParseTimezone(tz string) (*time.Location, error)
- func StartOfDay(t time.Time, tz *time.Location) time.Time
- func ToUTCTimestamp(t time.Time) int64
- func ToUserTimezone(ts int64, tz *time.Location) time.Time
Constants ¶
const ( // TimezoneUTC is the UTC timezone identifier. TimezoneUTC = "UTC" // TimezoneAsiaShanghai is the China Standard Time timezone. TimezoneAsiaShanghai = "Asia/Shanghai" // TimezoneAmericaNewYork is the Eastern Time timezone. TimezoneAmericaNewYork = "America/New_York" // TimezoneAmericaLosAngeles is the Pacific Time timezone. TimezoneAmericaLosAngeles = "America/Los_Angeles" // TimezoneEuropeLondon is the GMT/BST timezone. TimezoneEuropeLondon = "Europe/London" // TimezoneEuropeParis is the CET/CEST timezone. TimezoneEuropeParis = "Europe/Paris" // TimezoneAsiaTokyo is the Japan Standard Time timezone. TimezoneAsiaTokyo = "Asia/Tokyo" // TimezoneAustraliaSydney is the AEST/AEDT timezone. TimezoneAustraliaSydney = "Australia/Sydney" )
Common timezone constants.
Variables ¶
var ( // UTC is the coordinated universal time timezone. UTC = time.UTC // Local is the local timezone. Local = time.Local )
Default location constants.
var ( // LocationAsiaShanghai is the pre-loaded Asia/Shanghai location. LocationAsiaShanghai = MustParseTimezone(TimezoneAsiaShanghai) // LocationAmericaNewYork is the pre-loaded America/New_York location. LocationAmericaNewYork = MustParseTimezone(TimezoneAmericaNewYork) // LocationAmericaLosAngeles is the pre-loaded America/Los_Angeles location. LocationAmericaLosAngeles = MustParseTimezone(TimezoneAmericaLosAngeles) // LocationEuropeLondon is the pre-loaded Europe/London location. LocationEuropeLondon = MustParseTimezone(TimezoneEuropeLondon) // LocationEuropeParis is the pre-loaded Europe/Paris location. LocationEuropeParis = MustParseTimezone(TimezoneEuropeParis) // LocationAsiaTokyo is the pre-loaded Asia/Tokyo location. LocationAsiaTokyo = MustParseTimezone(TimezoneAsiaTokyo) // LocationAustraliaSydney is the pre-loaded Australia/Sydney location. LocationAustraliaSydney = MustParseTimezone(TimezoneAustraliaSydney) )
Common timezone locations (pre-loaded for performance).
Functions ¶
func FormatScheduleForContext ¶
func FormatScheduleForContext(startTs int64, endTs *int64, title string, location string, allDay bool, index int, tz *time.Location) string
Format: "1. 2026-01-21 14:00 - 16:00 - Team Meeting @ Room A".
func FormatScheduleTime ¶
FormatScheduleTime formats a schedule's time for display. Rules:
- All-day event: "2006-01-02"
- With end time: "2006-01-02 15:04 - 16:00"
- No end time: "2006-01-02 15:00"
func FormatTimeWithTimezone ¶
FormatTimeWithTimezone formats a Unix timestamp as a string in the given timezone. The format should be a valid Go time format string (e.g., "2006-01-02 15:04").
func GetDefaultTimezone ¶
GetDefaultTimezone returns the default timezone (UTC).
func IsValidTimezone ¶
IsValidTimezone checks if a timezone identifier is valid.
func MustParseTimezone ¶
MustParseTimezone parses a timezone or panics if invalid. Use this for constants that are known to be valid at compile time.
func NowInTimezone ¶
NowInTimezone returns the current time in the given timezone.
func ParseTimezone ¶
ParseTimezone parses an IANA timezone identifier (e.g., "Asia/Shanghai"). If the timezone is invalid, returns UTC and an error.
func StartOfDay ¶
StartOfDay returns the start of the day (00:00:00) in the given timezone.
func ToUTCTimestamp ¶
ToUTCTimestamp converts a time in the user's timezone to a Unix timestamp (UTC).
Types ¶
This section is empty.