timezone

package
v0.62.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 2 Imported by: 0

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

View Source
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

View Source
var (
	// UTC is the coordinated universal time timezone
	UTC = time.UTC

	// Local is the local timezone
	Local = time.Local
)

Default location constants

View Source
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 EndOfDay

func EndOfDay(t time.Time, tz *time.Location) time.Time

EndOfDay returns the end of the day (23:59:59.999999999) in the given timezone.

func FormatScheduleForContext

func FormatScheduleForContext(startTs int64, endTs *int64, title string, location string, allDay bool, index int, tz *time.Location) string

FormatScheduleForContext formats a schedule for LLM context. Format: "1. 2026-01-21 14:00 - 16:00 - Team Meeting @ Room A"

func FormatScheduleTime

func FormatScheduleTime(startTs int64, endTs *int64, allDay bool, tz *time.Location) string

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

func FormatTimeWithTimezone(ts int64, tz *time.Location, format string) string

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

func GetDefaultTimezone() *time.Location

GetDefaultTimezone returns the default timezone (UTC).

func IsValidTimezone

func IsValidTimezone(tz string) bool

IsValidTimezone checks if a timezone identifier is valid.

func MustParseTimezone

func MustParseTimezone(tz string) *time.Location

MustParseTimezone parses a timezone or panics if invalid. Use this for constants that are known to be valid at compile time.

func NowInTimezone

func NowInTimezone(tz *time.Location) time.Time

NowInTimezone returns the current time in the given timezone.

func ParseTimezone

func ParseTimezone(tz string) (*time.Location, error)

ParseTimezone parses an IANA timezone identifier (e.g., "Asia/Shanghai"). If the timezone is invalid, returns UTC and an error.

func StartOfDay

func StartOfDay(t time.Time, tz *time.Location) time.Time

StartOfDay returns the start of the day (00:00:00) in the given timezone.

func ToUTCTimestamp

func ToUTCTimestamp(t time.Time) int64

ToUTCTimestamp converts a time in the user's timezone to a Unix timestamp (UTC).

func ToUserTimezone

func ToUserTimezone(ts int64, tz *time.Location) time.Time

ToUserTimezone converts a Unix timestamp to the user's timezone.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL