xtime

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 6 Imported by: 2

README

xtime

Dependencies

  • xtesting*

Documents

Types
  • type JsonDate time.Time
  • type JsonDateTime time.Time
Variables
  • None
Constants
  • const RFC3339DateTime string
  • const CJKDateTime string
  • const RFC3339Date string
  • const CJKDate string
Functions
  • func SetYear(t time.Time, year int) time.Time
  • func SetMonth(t time.Time, month int) time.Time
  • func SetDay(t time.Time, day int) time.Time
  • func SetHour(t time.Time, hour int) time.Time
  • func SetMinute(t time.Time, minute int) time.Time
  • func SetSecond(t time.Time, second int) time.Time
  • func SetMillisecond(t time.Time, millisecond int) time.Time
  • func SetMicrosecond(t time.Time, microsecond int) time.Time
  • func SetNanosecond(t time.Time, nanosecond int) time.Time
  • func SetLocation(t time.Time, loc *time.Location) time.Time
  • func ToDate(t time.Time) time.Time
  • func ToDateTime(t time.Time) time.Time
  • func ToDateTimeNS(t time.Time) time.Time
  • func LocationDuration(loc *time.Location) time.Duration
  • func GetTimeLocation(t time.Time) *time.Location
  • func GetLocalLocation() *time.Location
  • func ParseTimezone(timezone string) (*time.Location, error)
  • func DurationNanosecondComponent(d time.Duration) int
  • func DurationMicrosecondComponent(d time.Duration) int
  • func DurationMillisecondComponent(d time.Duration) int
  • func DurationSecondComponent(d time.Duration) int
  • func DurationMinuteComponent(d time.Duration) int
  • func DurationHourComponent(d time.Duration) int
  • func DurationDayComponent(d time.Duration) int
  • func DurationTotalNanoseconds(d time.Duration) int64
  • func DurationTotalMicroseconds(d time.Duration) int64
  • func DurationTotalMilliseconds(d time.Duration) int64
  • func DurationTotalSeconds(d time.Duration) float64
  • func DurationTotalMinutes(d time.Duration) float64
  • func DurationTotalHours(d time.Duration) float64
  • func DurationTotalDays(d time.Duration) float64
  • func NewJsonDate(t time.Time) JsonDate
  • func NewJsonDateTime(t time.Time) JsonDateTime
  • func ParseJsonDate(s string) (JsonDate, error)
  • func ParseJsonDateOr(s string, d JsonDate) JsonDate
  • func ParseJsonDateTime(s string) (JsonDateTime, error)
  • func ParseJsonDateTimeOr(s string, d JsonDateTime) JsonDateTime
Methods
  • func (d JsonDate) Time() time.Time
  • func (d JsonDate) String() string
  • func (d JsonDate) MarshalJSON() ([]byte, error)
  • func (d *JsonDate) UnmarshalJSON(bytes []byte) error
  • func (d *JsonDate) Scan(value interface{}) error
  • func (d JsonDate) Value() (driver.Value, error)
  • func (dt JsonDateTime) Time() time.Time
  • func (dt JsonDateTime) String() string
  • func (dt JsonDateTime) MarshalJSON() ([]byte, error)
  • func (dt *JsonDateTime) UnmarshalJSON(bytes []byte) error
  • func (dt *JsonDateTime) Scan(value interface{}) error
  • func (dt JsonDateTime) Value() (driver.Value, error)

Documentation

Index

Constants

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

func DurationDayComponent(d time.Duration) int

DurationDayComponent returns the day component of the time.Duration.

func DurationHourComponent added in v1.5.0

func DurationHourComponent(d time.Duration) int

DurationHourComponent returns the hour component of the time.Duration.

func DurationMicrosecondComponent added in v1.5.0

func DurationMicrosecondComponent(d time.Duration) int

DurationMicrosecondComponent returns the microsecond component of the time.Duration.

func DurationMillisecondComponent added in v1.5.0

func DurationMillisecondComponent(d time.Duration) int

DurationMillisecondComponent returns the millisecond component of the time.Duration.

func DurationMinuteComponent added in v1.5.0

func DurationMinuteComponent(d time.Duration) int

DurationMinuteComponent returns the minute component of the time.Duration.

func DurationNanosecondComponent added in v1.5.0

func DurationNanosecondComponent(d time.Duration) int

DurationNanosecondComponent returns the nanosecond component of the time.Duration.

func DurationSecondComponent added in v1.5.0

func DurationSecondComponent(d time.Duration) int

DurationSecondComponent returns the second component of the time.Duration.

func DurationTotalDays added in v1.5.0

func DurationTotalDays(d time.Duration) float64

DurationTotalDays returns the value of the time.Duration expressed in whole and fractional days.

func DurationTotalHours added in v1.5.0

func DurationTotalHours(d time.Duration) float64

DurationTotalHours returns the value of the time.Duration expressed in whole and fractional hours.

func DurationTotalMicroseconds added in v1.5.0

func DurationTotalMicroseconds(d time.Duration) int64

DurationTotalMicroseconds returns the value of the time.Duration expressed in whole and fractional microseconds.

func DurationTotalMilliseconds added in v1.5.0

func DurationTotalMilliseconds(d time.Duration) int64

DurationTotalMilliseconds returns the value of the time.Duration expressed in whole and fractional milliseconds.

func DurationTotalMinutes added in v1.5.0

func DurationTotalMinutes(d time.Duration) float64

DurationTotalMinutes returns the value of the time.Duration expressed in whole and fractional minutes.

func DurationTotalNanoseconds added in v1.5.0

func DurationTotalNanoseconds(d time.Duration) int64

DurationTotalNanoseconds returns the value of the time.Duration expressed in whole and fractional nanoseconds.

func DurationTotalSeconds added in v1.5.0

func DurationTotalSeconds(d time.Duration) float64

DurationTotalSeconds returns the value of the time.Duration expressed in whole and fractional seconds.

func GetLocalLocation added in v1.5.0

func GetLocalLocation() *time.Location

GetLocalLocation returns a time.Location with empty name for representing time.Local.

func GetTimeLocation added in v1.5.0

func GetTimeLocation(t time.Time) *time.Location

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

func LocationDuration(loc *time.Location) time.Duration

LocationDuration returns a time.Duration that equals to the duration for the given time.Location.

func ParseTimezone added in v1.5.0

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

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 SetDay added in v1.4.2

func SetDay(t time.Time, day int) time.Time

SetDay sets the dat value to given time and returns a new time.Time.

func SetHour added in v1.4.2

func SetHour(t time.Time, hour int) time.Time

SetHour sets the hour value to given time and returns a new time.Time.

func SetLocation added in v1.4.2

func SetLocation(t time.Time, loc *time.Location) time.Time

SetLocation sets the location value to given time and returns a new time.Time.

func SetMicrosecond added in v1.5.0

func SetMicrosecond(t time.Time, microsecond int) time.Time

SetMicrosecond sets the microsecond value to given time and returns a new time.Time.

func SetMillisecond added in v1.5.0

func SetMillisecond(t time.Time, millisecond int) time.Time

SetMillisecond sets the millisecond value to given time and returns a new time.Time.

func SetMinute added in v1.4.2

func SetMinute(t time.Time, minute int) time.Time

SetMinute sets the minute value to given time and returns a new time.Time.

func SetMonth added in v1.4.2

func SetMonth(t time.Time, month int) time.Time

SetMonth sets the month value to given time and returns a new time.Time.

func SetNanosecond added in v1.4.2

func SetNanosecond(t time.Time, nanosecond int) time.Time

SetNanosecond sets the nanosecond value to given time and returns a new time.Time.

func SetSecond added in v1.4.2

func SetSecond(t time.Time, second int) time.Time

SetSecond sets the second value to given time and returns a new time.Time.

func SetYear added in v1.4.2

func SetYear(t time.Time, year int) time.Time

SetYear sets the year value to given time and returns a new time.Time.

func ToDate

func ToDate(t time.Time) time.Time

ToDate returns a new time.Time with the old year, month, day value and parsed location (see GetTimeLocation).

func ToDateTime

func ToDateTime(t time.Time) time.Time

ToDateTime returns a new time.Time with the old year, month, day, hour, minute, second value and parsed location (see GetTimeLocation).

func ToDateTimeNS added in v1.5.0

func ToDateTimeNS(t time.Time) time.Time

ToDateTimeNS returns a new time.Time with the old year, month, day, hour, minute, second, nanosecond value and parsed location (see GetTimeLocation).

Types

type JsonDate

type JsonDate time.Time

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

func NewJsonDate(t time.Time) JsonDate

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

func ParseJsonDate(s string) (JsonDate, error)

ParseJsonDate parses a string to JsonDate in RFC3339Date format, it uses the local timezone.

func ParseJsonDateOr added in v1.5.0

func ParseJsonDateOr(s string, d JsonDate) JsonDate

ParseJsonDateOr parses a string to JsonDate in RFC3339Date format with a fallback value, it uses the local timezone.

func (JsonDate) MarshalJSON

func (d JsonDate) MarshalJSON() ([]byte, error)

MarshalJSON marshals the time value to json bytes in RFC3339Date format.

func (*JsonDate) Scan

func (d *JsonDate) Scan(value interface{}) error

Scan implementations sql.Scanner to support sql scan.

func (JsonDate) String

func (d JsonDate) String() string

String parses and returns the time value in RFC3339Date format.

func (JsonDate) Time

func (d JsonDate) Time() time.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

func (d *JsonDate) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals the time value from json bytes in RFC3339Date format.

func (JsonDate) Value

func (d JsonDate) Value() (driver.Value, error)

Value implementations driver.Valuer to support sql value.

type JsonDateTime

type JsonDateTime time.Time

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.

func (JsonDateTime) Value

func (dt JsonDateTime) Value() (driver.Value, error)

Value implementations driver.Valuer to support sql value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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