Documentation ¶
Index ¶
- Constants
- func DurationDayComponent(d time.Duration) int
- func DurationHourComponent(d time.Duration) int
- func DurationMicrosecondComponent(d time.Duration) int
- func DurationMillisecondComponent(d time.Duration) int
- func DurationMinuteComponent(d time.Duration) int
- func DurationNanosecondComponent(d time.Duration) int
- func DurationSecondComponent(d time.Duration) int
- func DurationTotalDays(d time.Duration) float64
- func DurationTotalHours(d time.Duration) float64
- func DurationTotalMicroseconds(d time.Duration) int64
- func DurationTotalMilliseconds(d time.Duration) int64
- func DurationTotalMinutes(d time.Duration) float64
- func DurationTotalNanoseconds(d time.Duration) int64
- func DurationTotalSeconds(d time.Duration) float64
- func GetLocalLocation() *time.Location
- func GetTimeLocation(t time.Time) *time.Location
- func LocationDuration(loc *time.Location) time.Duration
- func ParseTimezone(timezone string) (*time.Location, error)
- func SetDay(t time.Time, day int) time.Time
- func SetHour(t time.Time, hour int) time.Time
- func SetLocation(t time.Time, loc *time.Location) time.Time
- func SetMicrosecond(t time.Time, microsecond int) time.Time
- func SetMillisecond(t time.Time, millisecond int) time.Time
- func SetMinute(t time.Time, minute int) time.Time
- func SetMonth(t time.Time, month int) time.Time
- func SetNanosecond(t time.Time, nanosecond int) time.Time
- func SetSecond(t time.Time, second int) time.Time
- func SetYear(t time.Time, year int) time.Time
- func ToDate(t time.Time) time.Time
- func ToDateTime(t time.Time) time.Time
- func ToDateTimeNS(t time.Time) time.Time
- type JsonDate
- type JsonDateTime
Constants ¶
const ( RFC3339Date = "2006-01-02" // RFC3339 date format CJKDate = "2006-01-02" // CJK date format RFC3339DateTime = "2006-01-02T15:04:05Z07:00" // RFC3339 datetime format CJKDateTime = "2006-01-02 15:04:05" // CJK datetime format )
Variables ¶
This section is empty.
Functions ¶
func DurationDayComponent ¶ added in v1.5.0
DurationDayComponent returns the day component of the time.Duration.
func DurationHourComponent ¶ added in v1.5.0
DurationHourComponent returns the hour component of the time.Duration.
func DurationMicrosecondComponent ¶ added in v1.5.0
DurationMicrosecondComponent returns the microsecond component of the time.Duration.
func DurationMillisecondComponent ¶ added in v1.5.0
DurationMillisecondComponent returns the millisecond component of the time.Duration.
func DurationMinuteComponent ¶ added in v1.5.0
DurationMinuteComponent returns the minute component of the time.Duration.
func DurationNanosecondComponent ¶ added in v1.5.0
DurationNanosecondComponent returns the nanosecond component of the time.Duration.
func DurationSecondComponent ¶ added in v1.5.0
DurationSecondComponent returns the second component of the time.Duration.
func DurationTotalDays ¶ added in v1.5.0
DurationTotalDays returns the value of the time.Duration expressed in whole and fractional days.
func DurationTotalHours ¶ added in v1.5.0
DurationTotalHours returns the value of the time.Duration expressed in whole and fractional hours.
func DurationTotalMicroseconds ¶ added in v1.5.0
DurationTotalMicroseconds returns the value of the time.Duration expressed in whole and fractional microseconds.
func DurationTotalMilliseconds ¶ added in v1.5.0
DurationTotalMilliseconds returns the value of the time.Duration expressed in whole and fractional milliseconds.
func DurationTotalMinutes ¶ added in v1.5.0
DurationTotalMinutes returns the value of the time.Duration expressed in whole and fractional minutes.
func DurationTotalNanoseconds ¶ added in v1.5.0
DurationTotalNanoseconds returns the value of the time.Duration expressed in whole and fractional nanoseconds.
func DurationTotalSeconds ¶ added in v1.5.0
DurationTotalSeconds returns the value of the time.Duration expressed in whole and fractional seconds.
func GetLocalLocation ¶ added in v1.5.0
GetLocalLocation returns a time.Location with empty name for representing time.Local.
func GetTimeLocation ¶ added in v1.5.0
GetTimeLocation returns a time.Location with empty name for given time.Time. Note that time.Time.Location() will return an unusable location (UTC or Local or empty name).
func LocationDuration ¶ added in v1.5.0
LocationDuration returns a time.Duration that equals to the duration for the given time.Location.
func ParseTimezone ¶ added in v1.5.0
ParseTimezone parses a UTC offset timezone string to time.Location (with UTC+00:00 name), format: `[+-][0-9]{1,2}(:[0-9]{1,2})?`.
func SetHour ¶ added in v1.4.2
SetHour sets the hour value to given time and returns a new time.Time.
func SetLocation ¶ added in v1.4.2
SetLocation sets the location value to given time and returns a new time.Time.
func SetMicrosecond ¶ added in v1.5.0
SetMicrosecond sets the microsecond value to given time and returns a new time.Time.
func SetMillisecond ¶ added in v1.5.0
SetMillisecond sets the millisecond value to given time and returns a new time.Time.
func SetMinute ¶ added in v1.4.2
SetMinute sets the minute value to given time and returns a new time.Time.
func SetMonth ¶ added in v1.4.2
SetMonth sets the month value to given time and returns a new time.Time.
func SetNanosecond ¶ added in v1.4.2
SetNanosecond sets the nanosecond value to given time and returns a new time.Time.
func SetSecond ¶ added in v1.4.2
SetSecond sets the second value to given time and returns a new time.Time.
func SetYear ¶ added in v1.4.2
SetYear sets the year value to given time and returns a new time.Time.
func ToDate ¶
ToDate returns a new time.Time with the old year, month, day value and parsed location (see GetTimeLocation).
func ToDateTime ¶
ToDateTime returns a new time.Time with the old year, month, day, hour, minute, second value and parsed location (see GetTimeLocation).
Types ¶
type JsonDate ¶
JsonDate represents a parsed time.Time in time.RFC3339, that is in openapi `string#date` format. This time only preserves year, month, day value. DO NOT create it by xtime.JsonDate(time.Now()), just use xtime.NewJsonDate.
func NewJsonDate ¶
NewJsonDate creates a JsonDate from time.Time, it only preserves year, month, day value and use parsed location.
func ParseJsonDate ¶ added in v1.5.0
ParseJsonDate parses a string to JsonDate in RFC3339Date format, it uses the local timezone.
func ParseJsonDateOr ¶ added in v1.5.0
ParseJsonDateOr parses a string to JsonDate in RFC3339Date format with a fallback value, it uses the local timezone.
func (JsonDate) MarshalJSON ¶
MarshalJSON marshals the time value to json bytes in RFC3339Date format.
func (JsonDate) Time ¶
Time returns the time.Time value from JsonDate, it does not equal to the parameter for NewJsonDate.
func (*JsonDate) UnmarshalJSON ¶ added in v1.5.0
UnmarshalJSON unmarshals the time value from json bytes in RFC3339Date format.
type JsonDateTime ¶
JsonDateTime represents a parsed time.Time in time.RFC3339, that is in openapi `string#date-time` format. This time only preserves year, month, day, hour, minute, second value and use parsed location. DO NOT create it by xtime.JsonDateTime(time.Now()), just use xtime.NewJsonDateTime.
func NewJsonDateTime ¶
func NewJsonDateTime(t time.Time) JsonDateTime
NewJsonDateTime creates a JsonDateTime from time.Time, it only preserves year, month, day, hour, minute, second value and use parsed location.
func ParseJsonDateTime ¶ added in v1.5.0
func ParseJsonDateTime(s string) (JsonDateTime, error)
ParseJsonDateTime parses a string to JsonDateTime in RFC3339DateTime format.
func ParseJsonDateTimeOr ¶ added in v1.5.0
func ParseJsonDateTimeOr(s string, dt JsonDateTime) JsonDateTime
ParseJsonDateTimeOr parses a string to JsonDateTime in RFC3339DateTime format with a fallback value.
func (JsonDateTime) MarshalJSON ¶
func (dt JsonDateTime) MarshalJSON() ([]byte, error)
MarshalJSON marshals the time value to json bytes in RFC3339DateTime format.
func (*JsonDateTime) Scan ¶
func (dt *JsonDateTime) Scan(value interface{}) error
Scan implementations sql.Scanner to support sql scan.
func (JsonDateTime) String ¶
func (dt JsonDateTime) String() string
String parses and returns the time value in RFC3339DateTime format.
func (JsonDateTime) Time ¶
func (dt JsonDateTime) Time() time.Time
Time returns the time.Time value from JsonDateTime, it does not equal to the parameter for NewJsonDateTime.
func (*JsonDateTime) UnmarshalJSON ¶ added in v1.5.0
func (dt *JsonDateTime) UnmarshalJSON(bytes []byte) error
UnmarshalJSON unmarshals the time value from json bytes in RFC3339DateTime format.