Documentation ¶
Index ¶
- Variables
- func Since(t Timex) time.Duration
- func TimeZoneOfGeography(country string, state string) (timeZone string)
- func Until(t Timex) time.Duration
- type Timex
- func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Timex
- func MustParse(layout string, value string) Timex
- func MustParseInLocation(layout string, value string, loc *time.Location) Timex
- func New(t time.Time) Timex
- func Now() Timex
- func Parse(layout string, value string) (Timex, error)
- func ParseInLocation(layout string, value string, loc *time.Location) (Timex, error)
- func Unix(sec int64, nsec int64) Timex
- func UnixMicro(usec int64) Timex
- func UnixMilli(msec int64) Timex
- func (tx Timex) Add(d time.Duration) Timex
- func (tx Timex) AddDate(years int, months int, days int) Timex
- func (tx Timex) After(u Timex) bool
- func (tx Timex) Before(u Timex) bool
- func (tx Timex) Compare(u Timex) int
- func (tx Timex) Equal(u Timex) bool
- func (tx Timex) Format(layout string) string
- func (tx Timex) In(loc *time.Location) Timex
- func (tx Timex) JSONSchemaAlias() any
- func (tx Timex) Local() Timex
- func (tx Timex) MarshalJSON() ([]byte, error)
- func (tx Timex) MarshalYAML() (interface{}, error)
- func (tx Timex) Round(d time.Duration) Timex
- func (tx *Timex) Scan(value interface{}) error
- func (tx Timex) Sub(u Timex) time.Duration
- func (tx Timex) Truncate(d time.Duration) Timex
- func (tx Timex) UTC() Timex
- func (tx *Timex) UnmarshalJSON(b []byte) error
- func (tx *Timex) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (tx Timex) Value() (driver.Value, error)
- func (tx Timex) ZoneBounds() (start, end Timex)
Constants ¶
This section is empty.
Variables ¶
var TimeZoneNames = []string{}/* 515 elements not displayed */
TimeZoneNames is an alphabetically sorted list of most time zone names.
var USTimeZoneNames = []string{
"US/Alaska",
"US/Aleutian",
"US/Arizona",
"US/Central",
"US/East-Indiana",
"US/Eastern",
"US/Hawaii",
"US/Indiana-Starke",
"US/Michigan",
"US/Mountain",
"US/Pacific",
"US/Samoa",
}
USTimeZoneNames is an alphabetically sorted list of US time zone names.
Functions ¶
func TimeZoneOfGeography ¶
TimeZoneOfGeography returns the time zone name of the given country and (optional) state. If one cannot be determined, the empty string is returned.
Types ¶
type Timex ¶
Timex is an extension of the standard time.Time. It improves on parsing and overrides JSON serialization and database formatting for the zero time.
To create a new timex.Timex from time.Time:
timex := New(stdTime)
To obtain time.Time from a Timex:
stdTime := timex.Time
func Date ¶
Date returns the Time corresponding to
yyyy-mm-dd hh:mm:ss + nsec nanoseconds
in the appropriate zone for that time in the given location.
The month, day, hour, min, sec, and nsec values may be outside their usual ranges and will be normalized during the conversion. For example, October 32 converts to November 1.
A daylight savings time transition skips or repeats times. For example, in the United States, March 13, 2011 2:15am never occurred, while November 6, 2011 1:15am occurred twice. In such cases, the choice of time zone, and therefore the time, is not well-defined. Date returns a time that is correct in one of the two zones involved in the transition, but it does not guarantee which.
Date panics if loc is nil.
func MustParseInLocation ¶
MustParse is the same as Parse but panics on error.
func Parse ¶
Parse creates a new timex from a string. The empty string is parsed to the zero time. Layout is optional. If not provided, layout is assumed to be RFC3339Nano "2006-01-02T15:04:05.999999999Z07:00", RFC3339 "2006-01-02T15:04:05Z07:00", "2006-01-02T15:04:05", "2006-01-02 15:04:05", or "2006-01-02" based on the length of the value.
func ParseInLocation ¶
ParseInLocation is like Parse but differs in two important ways. First, in the absence of time zone information, Parse interprets a time as UTC; ParseInLocation interprets the time as in the given location. Second, when given a zone offset or abbreviation, Parse tries to match it against the Local location; ParseInLocation uses the given location.
func Unix ¶
Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).
func UnixMicro ¶
UnixMicro returns the local Time corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
func UnixMilli ¶
UnixMilli returns the local Time corresponding to the given Unix time, msec milliseconds since January 1, 1970 UTC.
func (Timex) AddDate ¶
AddDate returns the time corresponding to adding the given number of years, months, and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010.
AddDate normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.
func (Timex) Compare ¶
Compare compares the time instant t with u. If t is before u, it returns -1; if t is after u, it returns +1; if they're the same, it returns 0.
func (Timex) Equal ¶
Equal reports whether t and u represent the same time instant. Two times can be equal even if they are in different locations. For example, 6:00 +0200 and 4:00 UTC are Equal. See the documentation on the Time type for the pitfalls of using == with Time values; most code should use Equal instead.
func (Timex) Format ¶
Format returns a textual representation of the time value formatted according to the layout defined by the argument. See the documentation for the constant called Layout to see how to represent the layout format.
The executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference.
The zero time is formatted as an empty string.
func (Timex) In ¶
In returns a copy of t representing the same time instant, but with the copy's location information set to loc for display purposes.
In panics if loc is nil.
func (Timex) JSONSchemaAlias ¶
JSONSchemaAlias indicates to use the JSON schema of time.
func (Timex) MarshalJSON ¶
MarshalJSON overrides JSON serialization of the zero value to null.
func (Timex) MarshalYAML ¶
MarshalYAML overrides YAML serialization of the zero value to null.
func (Timex) Round ¶
Round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
Round operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Round(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (Timex) Sub ¶
Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).
func (Timex) Truncate ¶
Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.
func (*Timex) UnmarshalJSON ¶
UnmarshalJSON overrides JSON deserialization, interpreting "null" and "" as the zero time.
func (*Timex) UnmarshalYAML ¶
UnmarshalYAML overrides YAML deserialization, interpreting "null" and "" as the zero time.
func (Timex) ZoneBounds ¶
ZoneBounds returns the bounds of the time zone in effect at time t. The zone begins at start and the next zone begins at end. If the zone begins at the beginning of time, start will be returned as a zero Time. If the zone goes on forever, end will be returned as a zero Time. The Location of the returned times will be the same as t.