times

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTZ

func ConvertTZ(t time.Time, tz string) (time.Time, error)

ConvertTZ converts a time.Time into a new time.Time in a timezone specified by tz. This is unlike OverwriteTZ, where its tz is overwritten, resulting in a completely different point of time: ConvertTZ keeps the point of time unchanged - it merely switches the input time.Time to a different timezone.

func OverwriteTZ

func OverwriteTZ(t time.Time, tz string) (time.Time, error)

OverwriteTZ takes the literal values of y/m/d/h/m/s of a time.Time and uses them together with a supplied timezone to form a new time.Time, effectively "overwriting" the original time.Time's tz. If tz is empty, the original time.Time is returned.

func SmartParse

func SmartParse(s string) (t time.Time, tz bool, err error)

SmartParse parses a date time string and returns a time.Time and a tz flag indicates whether the date time string contains tz info. The date time string can be either date only, or date + time, or date + time + tz. The date part of the string has the following supported formats:

yyyy-mm-dd
mm-dd-yyyy
yyyy/mm/dd
mm/dd/yyyy
mm/dd/yy
yyyymmdd

The time part of the string has the following supported formats:

hh:mm:ss[.sssssssss]  (sub-second precision is up to nano-second, or 9-digit)
hh:mm
hhmmss
hhmm

Note: all formats above can also be followed by 'AM/PM'. The tz part of the string has the following supported formats:

Z
-/+hh
-/+hhmm
-/+hh:mm
-America/New_York

Note 1: the tz name in the last one above must come from standard IANA timezone names. Upon successful parsing, SmartParse returns the time.Time, and a flag whether the input date time string has tz info in it or not. Note the time.Time returned will always have tz baked in, because golang time.Time doesn't really have a notion of un-timezone'ed timestamp. So if your date time string is a un-tz'ed relative time stamp, such as "2020/09/10T12:34:56", which really means different point of time depending on which time zone you try to interpret it in, the returned tz flag will be false but the returned time.Time will be "2020/09/10T12:34:56Z" (note the 'Z') if you format it using RFC3339. That's the key subtlety one must understand well.

Types

This section is empty.

Jump to

Keyboard shortcuts

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