Documentation ¶
Index ¶
- Constants
- Variables
- func AfterEqual(a, b time.Time) bool
- func BeforeEqual(a, b time.Time) bool
- func CountDays(begin, end time.Time) int
- func CountWorkDays(begin, end time.Time) int
- func CountWorkDaysThisWeekFrom(from time.Weekday) int
- func CountWorkDaysThisWeekTo(to time.Weekday) int
- func CurrentUnixMillis() uint32
- func DateValid(year, month, day int) bool
- func DaysBetween(since, to time.Time) (exactDays float64, biggerDays, smallerDays int)
- func DetectBestLayout(in []ElegantTime) string
- func DetectBestLayoutRaw(in []time.Time) string
- func ElapsedTimeInDay(tm time.Time) time.Duration
- func EpochMillisToTime(millis int64) time.Time
- func EpochNsecToTime(nsec int64) time.Time
- func EpochSecToTime(sec int64) time.Time
- func FormatDay(tm time.Time) string
- func GetLocalTimezone() (int, error)
- func GetMonthDays(year, month int) int
- func GetMonthDuration(year, month int) time.Duration
- func GetNetTimeInLocalONLINE() (time.Time, error)
- func GetNetTimeInUTCONLINE() (time.Time, error)
- func GetSystemUptime() (uint64, error)
- func GetYearDuration(year int) time.Duration
- func HasDuplicated(times []time.Time, accuracy time.Duration) (bool, error)
- func IsEpochBeginning(tm time.Time) bool
- func IsLeapYear(year int) bool
- func IsWorkDay(tm time.Time) bool
- func IsZero(tm time.Time) bool
- func LeftTimeInDay(tm time.Time) time.Duration
- func MaxTime(a time.Time, b ...time.Time) time.Time
- func MicrosToMillis(micros int64) int64
- func MillisToDuration(millis int64) time.Duration
- func MillisToMicros(millis int64) int64
- func MillisToNsec(millis int64) int64
- func MinTime(a time.Time, b ...time.Time) time.Time
- func MulDuration(size int64, unit time.Duration) time.Duration
- func NsecToDuration(nsec int64) time.Duration
- func NsecToMillis(nsec int64) int64
- func NsecToSec(nsec int64) int64
- func ParseDatetimeStringFuzz(datetimeString string) (time.Time, error)
- func ParseTimezoneCode(tz string) (offset int, err error)
- func PrettyFormat(d time.Duration) string
- func RoundEarlier(t time.Time, d time.Duration) time.Time
- func RoundLater(t time.Time, d time.Duration) time.Time
- func SetLocalTimezone(timezone int) error
- func SetSystemTimeROOT(t time.Time) error
- func SortTimes(in []time.Time) []time.Time
- func StringHumanReadable(duration time.Duration) string
- func StringTimeZone(tm time.Time, tz time.Location) string
- func Sub(t time.Time, d time.Duration) time.Time
- func SyncNetTimeONLINEROOT() error
- func ThisMonthString() string
- func TimeToEpochMillis(t time.Time) int64
- func TimeToEpochNsec(t time.Time) int64
- func TimeToEpochSec(t time.Time) int64
- func TimeToIntYYYYMMDDHHMM(t time.Time) int
- func UnixNanoToTime(un int64, loc *time.Location) time.Time
- func VerifySystemTimeWithNtpOL(intervalAllowed time.Duration) error
- type Clock
- type Date
- func MaxDate(a, b Date) Date
- func MinDate(a, b Date) Date
- func NewDate(year, month, day int) (Date, error)
- func NewDatePanic(year, month, day int) Date
- func ParseDateString(s string, strict bool) (Date, error)
- func TimeToDate(tm time.Time, loc *time.Location) Date
- func Today(loc *time.Location) Date
- func Yesterday(loc *time.Location) Date
- func (d Date) AddDays(days int) Date
- func (d Date) After(cmp Date) bool
- func (d Date) AfterEqual(cmp Date) bool
- func (d Date) Before(cmp Date) bool
- func (d Date) BeforeEqual(cmp Date) bool
- func (d Date) Day() int
- func (d Date) Equal(cmp Date) bool
- func (d Date) IntYYYYMMDD() int
- func (d Date) IsZero() bool
- func (d Date) MarshalJSON() ([]byte, error)
- func (d Date) Month() time.Month
- func (d Date) NextDay() Date
- func (d Date) PreviousDay() Date
- func (d Date) String() string
- func (d Date) StringYYYYMMDD() string
- func (d Date) StringYYYY_MM_DD() string
- func (d Date) Sub(cmp Date) int
- func (d Date) ToTime(hour, minute, sec, nsec int, loc *time.Location) time.Time
- func (d Date) ToTimeLocation(loc *time.Location) time.Time
- func (d Date) ToTimeUTC() time.Time
- func (d Date) UnixDays() int
- func (d *Date) UnmarshalJSON(b []byte) error
- func (d Date) Year() int
- type DateRange
- type ElegantTime
- func (t *ElegantTime) DetectBestLayout() string
- func (t *ElegantTime) JSON() ([]byte, error)
- func (t *ElegantTime) JSONAutoDetect() ([]byte, error)
- func (t *ElegantTime) MarshalJSON() ([]byte, error)
- func (t *ElegantTime) Raw() time.Time
- func (t *ElegantTime) SetLayout(layout string)
- func (t *ElegantTime) UnmarshalJSON(b []byte) error
- type HumanDuration
- type MockClock
- type NtpClock
- type SysClock
- type TimeMap
- type YearMonth
- func (ym *YearMonth) Equal(cmp YearMonth) bool
- func (ym *YearMonth) Int() int
- func (ym *YearMonth) IsZero() bool
- func (ym YearMonth) MarshalJSON() ([]byte, error)
- func (ym *YearMonth) Month() time.Month
- func (ym YearMonth) String() string
- func (ym *YearMonth) StringYYYYMM() string
- func (ym *YearMonth) StringYYYY_MM() string
- func (ym *YearMonth) ToTime(day, hour, minute, sec, nsec int, tz time.Location) time.Time
- func (ym *YearMonth) ToTimeDefault() time.Time
- func (ym *YearMonth) UnmarshalJSON(b []byte) error
- func (ym *YearMonth) Year() int
Constants ¶
const TimeLayout_FULL = "2006-01-02 15:04:05.999999999 -0700 MST"
const TimeLayout_MM_DD_HH = "15:04:05"
const TimeLayout_YYYY = "2006"
const TimeLayout_YYYY_MM = "2006-01"
const TimeLayout_YYYY_MM_DD = "2006-01-02"
const TimeLayout_YYYY_MM_DD_HH = "2006-01-02 15"
const TimeLayout_YYYY_MM_DD_HH_mm = "2006-01-02 15:04"
const TimeLayout_YYYY_MM_DD_HH_mm_SS = "2006-01-02 15:04:05"
const TimeLayout_YYYY_MM_DD_HH_mm_SS_NS = "2006-01-02 15:04:05.999999999"
Variables ¶
var ( EpochBeginTime time.Time = EpochSecToTime(0) // 1970-01-01 00:00:00 +0000 UTC EpochBeginDate Date = Date(19700101) // 0001-01-01 00:00:00 +0000 UTC ZeroTime time.Time = time.Time{} // 0001-01-01 00:00:00 +0000 UTC ZeroDate Date = TimeToDate(ZeroTime, time.UTC) // 0001-01-01 00:00:00 +0000 UTC ZeroYearMonth YearMonth = 0 // 0000-00 ZeroDateRange DateRange = DateRange{Begin: ZeroDate, End: ZeroDate} )
var (
TimeZoneAsiaShanghai, _ = time.LoadLocation("Asia/Shanghai")
)
Functions ¶
func AfterEqual ¶
func BeforeEqual ¶
func CountWorkDays ¶
this is not accurate, holidays(christmas, thanks giving day, spring festival...) are marked as workday
func CountWorkDaysThisWeekFrom ¶
*
Count how many work days from a specified Weekday in this week Weekday-Index Weekday Work-Days-From Work-Days-To 0 Sunday 5 0 1 Monday 5 1 2 Tuesday 4 2 3 Wednesday 3 3 4 Thursday 2 4 5 Friday 1 5 6 Saturday 0 5
'from' is included
func DaysBetween ¶
计算两个时间直接的间隔天数,不足一天的算一天称为biggerDays,不足一天不计算称为smallerDays
func DetectBestLayout ¶
func DetectBestLayout(in []ElegantTime) string
func DetectBestLayoutRaw ¶
func EpochMillisToTime ¶
func EpochNsecToTime ¶
func EpochSecToTime ¶
func GetLocalTimezone ¶
func GetMonthDuration ¶
func GetNetTimeInLocalONLINE ¶
Get network time in local machine timezone
func GetNetTimeInUTCONLINE ¶
Get network time in UTC
func GetSystemUptime ¶
func GetYearDuration ¶
func IsEpochBeginning ¶
不可以用tm.Seconds() 和 tm.Nanoseconds()作为判断标准, 因为这两个都只是钟表刻度盘上的零头而已 1970-01-01 00:00:00 +0000 UTC
func MicrosToMillis ¶
func MillisToDuration ¶
func MillisToMicros ¶
func MillisToNsec ¶
func MulDuration ¶
Convert int64 type duration to duration type MulDuration(3, time.Second) -> 3 seconds duration
func NsecToDuration ¶
func NsecToMillis ¶
func ParseDatetimeStringFuzz ¶
3rd choice package: github.com/olebedev/when Parse human readable date time string to machine-oriented time - unix timestamp
func ParseTimezoneCode ¶
func PrettyFormat ¶
time.Duaration.String() = "354h22m3.24s" PrettyFormat() = "2 weeks 18 hours 22 minutes 3 seconds"
func RoundEarlier ¶
RoundEarlier("2017-01-07 09:35:00 +0000 UTC", 20 * time.Minute) -> "2017-01-07 09:20:00 +0000 UTC"
func RoundLater ¶
RoundLater("2017-01-07 09:35:00 +0000 UTC", 20 * time.Minute) -> "2017-01-07 09:40:00 +0000 UTC"
func SetLocalTimezone ¶
func SetSystemTimeROOT ¶
func StringHumanReadable ¶
func SyncNetTimeONLINEROOT ¶
func SyncNetTimeONLINEROOT() error
Get network time and update time for local machine This API must run as root/admin, 但不知道Windows下是不是也是如此 有时警告有时不警告,内容为,sudo: timestamp too far in the future
func ThisMonthString ¶
func ThisMonthString() string
func TimeToEpochMillis ¶
func TimeToEpochNsec ¶
func TimeToEpochSec ¶
func TimeToIntYYYYMMDDHHMM ¶
Types ¶
type Clock ¶
type Date ¶
type Date int32
func NewDatePanic ¶
func ParseDateString ¶
strict == true : only can parse ISO standard date: "YYYY-MM-DD" strict == false : fuzzy parse date: "YYYY-MM-DD" or "YYYY.M.D"
func (Date) AfterEqual ¶
func (Date) BeforeEqual ¶
func (Date) IntYYYYMMDD ¶
func (Date) MarshalJSON ¶
func (Date) PreviousDay ¶
func (Date) StringYYYYMMDD ¶
yyyymmdd Notice: 如果你写成了fmt.Sprintf("%04d%02d%02d", d.Year, d.YearMonth, d.Day),编译也能通过 但是返回结果却是很大很大的数字,因为它们代表函数地址
func (*Date) UnmarshalJSON ¶
type DateRange ¶
func ParseDateRangeString ¶
strict == true: standard date range supported only: "YYYY-MM-DD/YYYY-MM-DD" Date Range standard reference:http://www.ukoln.ac.uk/metadata/dcmi/date-dccd-odrf/ strict == false: fuzzy parse in web page parser, these formats supported: 2018-01-02 - 2018-01-03 2018-01-02 ~ 2018-01-03 2017.1.2-2017.1.7
func (DateRange) MarshalJSON ¶
func (*DateRange) UnmarshalJSON ¶
type ElegantTime ¶
type ElegantTime struct {
// contains filtered or unexported fields
}
ElegantTime is the time.Time with JSON marshal and unmarshal capability
func NewElegantTime ¶
func NewElegantTime(tm time.Time, layout string) ElegantTime
func NewElegantTimeArray ¶
func NewElegantTimeArray(tms []time.Time, layout string) []ElegantTime
func (*ElegantTime) DetectBestLayout ¶
func (t *ElegantTime) DetectBestLayout() string
func (*ElegantTime) JSON ¶
func (t *ElegantTime) JSON() ([]byte, error)
func (*ElegantTime) JSONAutoDetect ¶
func (t *ElegantTime) JSONAutoDetect() ([]byte, error)
func (*ElegantTime) MarshalJSON ¶
func (t *ElegantTime) MarshalJSON() ([]byte, error)
MarshalJSON will marshal using 2006-01-02T15:04:05+07:00 layout
func (*ElegantTime) Raw ¶
func (t *ElegantTime) Raw() time.Time
func (*ElegantTime) SetLayout ¶
func (t *ElegantTime) SetLayout(layout string)
func (*ElegantTime) UnmarshalJSON ¶
func (t *ElegantTime) UnmarshalJSON(b []byte) error
UnmarshalJSON will unmarshal using 2006-01-02T15:04:05+07:00 layout
type HumanDuration ¶
func ParseHumanDuration ¶
func ParseHumanDuration(s string) (*HumanDuration, error)
func ToHumanDuration ¶
func ToHumanDuration(d time.Duration) HumanDuration
func (HumanDuration) MarshalJSON ¶
func (d HumanDuration) MarshalJSON() ([]byte, error)
func (HumanDuration) String ¶
func (d HumanDuration) String() string
func (HumanDuration) ToDuration ¶
func (d HumanDuration) ToDuration() time.Duration
func (*HumanDuration) UnmarshalJSON ¶
func (d *HumanDuration) UnmarshalJSON(b []byte) error
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
func (*MockClock) SetLocation ¶
type NtpClock ¶
type NtpClock struct {
// contains filtered or unexported fields
}
func GetNtpClockONLINE ¶
func GetNtpSyncClockONLINE ¶
type YearMonth ¶
type YearMonth int32
func NewYearMonth ¶
func ParseYearMonthInt ¶
func ParseYearMonthString ¶
support formats: 201601, 2016-01