Documentation
¶
Index ¶
- func FromRequest(r *http.Request) string
- func FromUser(user userstore.UserInterface) string
- func UTCDateToTz(utcDateString string, timezone string) (string, error)
- func UTCDatetimeToTz(utcDatetimeString string, timezone string) (string, error)
- func UTCTimeToTz(utcTimeString string, timezone string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromRequest ¶ added in v0.42.3
FromRequest returns the timezone from the authenticated user in the request context, or UTC if the user is not authenticated or has no timezone set.
func FromUser ¶ added in v0.42.3
func FromUser(user userstore.UserInterface) string
FromUser returns the timezone from the given user, or UTC if the user is nil or has no timezone set.
func UTCDateToTz ¶
UTCDateToTz converts a UTC date string to the specified timezone. It accepts date strings in "YYYY-MM-DD" format.
Example:
dateInNewYork, err := UTCDateToTz("2022-01-01", "America/New_York")
Parameters:
- utcDateString: a string representing the UTC date in "YYYY-MM-DD" format.
- timezone: a string representing the timezone (e.g., "America/New_York").
Returns:
- a string representing the converted date in "YYYY-MM-DD" format, or an empty string and an error if parsing fails.
func UTCDatetimeToTz ¶
UTCDatetimeToTz converts a UTC datetime string to the specified timezone. It accepts datetime strings in "YYYY-MM-DD HH:MM" format.
Example:
datetimeInNewYork, err := UTCDatetimeToTz("2022-01-01 10:00", "America/New_York")
Parameters:
- utcDatetimeString: a string representing the UTC datetime in "YYYY-MM-DD HH:MM" format.
- timezone: a string representing the timezone (e.g., "America/New_York").
Returns:
- a string representing the converted datetime in "YYYY-MM-DD HH:MM" format, or an empty string and an error if parsing fails.
func UTCTimeToTz ¶
UTCTimeToTz converts a UTC time string to the specified timezone. It accepts time strings in "HH:MM" format.
Example:
timeInNewYork, err := UTCTimeToTz("10:00", "America/New_York")
Parameters:
- utcTimeString: a string representing the UTC time in "HH:MM" format.
- timezone: a string representing the timezone (e.g., "America/New_York").
Returns:
- a string representing the converted time in "HH:MM" format, or an empty string and an error if parsing fails.
Types ¶
This section is empty.