timeutil

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDateToTime

func AddDateToTime(t int64, addYear int, addMonth int, addDate int, loc *time.Location) int64

AddDateToTime add year,month and date, if loc is nil, using local time zone

func AddSecondToNowTime

func AddSecondToNowTime(addSecs int, loc *time.Location) string

AddSecondToNowTime add seconds to now time, if loc is nil, using local time zone

func DateStrToTime

func DateStrToTime(d string, loc *time.Location) time.Time

DateStrToTime string format "2006-01-02"

func DateStrToTimeUnix

func DateStrToTimeUnix(d string, loc *time.Location) int64

DateStrToTimeUnix string format "2006-01-02" to timestamp

func DateTimeStrToTime

func DateTimeStrToTime(dt string, loc *time.Location) time.Time

DateTimeStrToTime string format "2006-01-02 15:04:05"

func DateTimeStrToTimeUnix

func DateTimeStrToTimeUnix(dt string, loc *time.Location) int64

DateTimeStrToTimeUnix string format "2006-01-02 15:04:05" to timestamp

func DateTimeStrToTimeUnixWithErr

func DateTimeStrToTimeUnixWithErr(dt string, loc *time.Location) (int64, error)

DateTimeStrToTimeUnix string format "2006-01-02 15:04:05" to timestamp

func DayLengthFromTwoLocalDate

func DayLengthFromTwoLocalDate(dateStr1 string, dateStr2 string, region string) (uint32, error)

DayLengthFromTwoLocalDate :

func GetDefaultRegion

func GetDefaultRegion() string

func GetNowDateStr

func GetNowDateStr(loc *time.Location) string

GetNowDateStr string format "2006-01-02" if loc is nil, using local time zone

func GetNowTimeStr

func GetNowTimeStr(loc *time.Location) string

GetNowTimeStr string format "2006-01-02 15:04:05" if loc is nil, using local time zone

func GetOffsetToUTCInSecs

func GetOffsetToUTCInSecs(region string) (int64, error)

GetOffsetToUTCInSecs : calculate the offset in seconds between the input region and UTC

func GetTimeFromUnix

func GetTimeFromUnix(timestamp int64) time.Time

GetTimeFromUnix

func IsTheSameDay

func IsTheSameDay(newTimestamp int64, oldTimestamp int64, offsetSeconds int64, region string) (bool, error)

IsTheSameDay check two timestamp whether is the same day

func IsTheSameDayByHour

func IsTheSameDayByHour(newTimestamp int64, oldTimestamp int64, offsetHour int64, region string) (bool, error)

IsTheSameDayByHour use offsetHour as the dividing time point, check two timestamp whether is the same day

func IsTheSameWeek

func IsTheSameWeek(newTimestamp, oldTimestamp, offsetSeconds int64, region string) (bool, error)

IsTheSameWeek check two timestamp whether is the same week

func IsTheSameWeekByHour

func IsTheSameWeekByHour(newTimestamp, oldTimestamp, offsetHour int64, region string) (bool, error)

IsTheSameWeekByHour use offsetHour as the dividing time point, check two timestamp whether is the same week

func IsWeekend

func IsWeekend(t time.Time) bool

IsWeekend check time sunday or saturday

func LastRegionWeekRefreshTime

func LastRegionWeekRefreshTime(t time.Time, refreshDay time.Weekday, refreshHour int, refreshMinutes int, loc *time.Location) time.Time

LastRegionWeekRefreshTime return the last refresh time for the event's refresh weekly based on region For exmaple, if the refresh time is Monday 08:00 in each region and check region is -0500 EST If t is 2018-04-02 12:59 0000 UTC which is 2018-04-02 07:59 -0500 EST would return 2018-03-26 08:00 -0500 EST If t is 2018-04-02 13:01 0000 UTC which is 2018-04-02 08:01 -0500 EST would return 2018-04-02 08:00 -0500 EST

func LastXHourTime

func LastXHourTime(addHour time.Duration, loc *time.Location) time.Time

LastXHourTime if loc is nil, using local time zone

func LastXHourTimeUnix

func LastXHourTimeUnix(addHour time.Duration, loc *time.Location) int64

LastXHourTimeUnix if loc is nil, using local time zone

func LocalDate

func LocalDate(datetime string, region string) (string, error)

LocalDate : convert GMT+8 datetime to Local datetime, format yyyy-mm-dd

func LocalDateByAddSomeDays

func LocalDateByAddSomeDays(dateStr string, someDays int64, region string) (string, error)

LocalDateByAddSomeDays : 2016-01-02 + (2days-1) = 2016-01-03

func LocalDateFromTimestamp

func LocalDateFromTimestamp(timestamp int64, region string) (string, error)

LocalDateFromTimestamp : convert timestamp to Local datetime, format yyyy-mm-dd

func LocalDateTime

func LocalDateTime(datetime string, region string) (string, error)

LocalDateTime : convert GMT+8 datetime to Local datetime, format yyyy-mm-dd hh:ii:ss

func LocalDateTimeFromTimestamp

func LocalDateTimeFromTimestamp(timestamp int64, region string) (string, error)

LocalDateTimeFromTimestamp : convert timestamp to Local datetime, format yyyy-mm-dd hh:ii:ss

func LocalDateTimeToLocalDate

func LocalDateTimeToLocalDate(datetimeStr string, offsetHour int64, region string) (string, error)

LocalDateTimeToLocalDate : convert datetime to date, from yyyy-mm-dd hh:ii:ss to yyyy-mm-dd

func LocalDateTimeToTimeStamp

func LocalDateTimeToTimeStamp(datetime string, region string) (int64, error)

LocalDateTimeToTimeStamp : convert datetime to timestamp, format yyyy-mm-dd hh:ii:ss

func LocalDateToTimeStamp

func LocalDateToTimeStamp(datetime string, region string) (int64, error)

LocalDateToTimeStamp : convert datetime to timestamp, format yyyy-mm-dd

func LocalIsNeedResetDailyAtXHourChkByNow

func LocalIsNeedResetDailyAtXHourChkByNow(resetHour, nowTimestamp, lastUpdateTimestamp int64, region string) (bool, error)

LocalIsNeedResetDailyAtXHourChkByNow : reset daily at xx hour Caution : return true if last update time is 0

func LocalIsNeedResetMonthlyAtXHourChkByNow

func LocalIsNeedResetMonthlyAtXHourChkByNow(resetHour, nowTimestamp, lastUpdateTimestamp int64, region string) (bool, error)

LocalIsNeedResetMonthlyAtXHourChkByNow : reset monthly at xx hour Caution : return true if last update time is 0

func LocalIsNeedResetWeeklyAtXHourChkByNow

func LocalIsNeedResetWeeklyAtXHourChkByNow(resetHour, nowTimestamp, lastUpdateTimestamp int64, region string) (bool, error)

LocalIsNeedResetWeeklyAtXHourChkByNow : reset monthly at xx hour Caution : return true if last update time is 0

func LocalIsNeedRestDailyAtXHour

func LocalIsNeedRestDailyAtXHour(resetHour int64, lastUpdateTimestamp int64, region string) (bool, error)

LocalIsNeedRestDailyAtXHour : reset daily at xx hour Caution : return true if last update time is 0

func LocalIsNeedRestMonthlyAtXHour

func LocalIsNeedRestMonthlyAtXHour(resetHour int64, lastUpdateTimestamp int64, region string) (bool, error)

LocalIsNeedRestMonthlyAtXHour : reset monthly at xx hour Caution : return true if last update time is 0

func LocalIsNeedRestWeeklyAtXHour

func LocalIsNeedRestWeeklyAtXHour(resetHour int64, lastUpdateTimestamp int64, region string) (bool, error)

LocalIsNeedRestWeeklyAtXHour : reset monthly at xx hour Caution : return true if last update time is 0

func LocalMondayFromTimeStamp

func LocalMondayFromTimeStamp(timestamp int64, region string) (string, error)

LocalMondayFromTimeStamp return region Monday date, format: 2006-01-02

func LocalMonthFromTimestamp

func LocalMonthFromTimestamp(timestamp int64, region string) (string, error)

LocalMonthFromTimestamp : convert timestamp to Local datetime, format yyyy-mm

func LocalNowDate

func LocalNowDate(region string) (string, error)

LocalNowDate : get local datetime now, format yyyy-mm-dd

func LocalNowDateTime

func LocalNowDateTime(region string) (string, error)

LocalNowDateTime : get local datetime now, format yyyy-mm-dd hh:ii:ss

func LocalTodayXHourTimeUnix

func LocalTodayXHourTimeUnix(addHour time.Duration, region string) int64

LocalTodayXHourTimeUnix using regional timezone

func LocalTomorrowXHourTimeUnix

func LocalTomorrowXHourTimeUnix(addHour time.Duration, region string) int64

LocalTomorrowXHourTimeUnix using regional timezone

func LocalWeekday

func LocalWeekday(region string) (int32, error)

LocalWeekday : get local weekday. Monday = 1, Sunday = 7

func LocalWeekdayFromTimestamp

func LocalWeekdayFromTimestamp(timestamp int64, region string) (int32, error)

LocalWeekdayFromTimestamp : get local weekday by timestamp. Monday = 1, Sunday = 7

func LocalYesterdayXHourTimeUnix

func LocalYesterdayXHourTimeUnix(addHour time.Duration, region string) int64

LocalYesterdayXHourTimeUnix using regional timezone

func PatchDefaultRegion

func PatchDefaultRegion(region string) error

PatchDefaultRegion change the default region for the pkg

func PatchRegionLocationMapping

func PatchRegionLocationMapping(options ...*PatchOption)

PatchRegionLocationMapping change the default region location mapping for the pkg

func RegionMonday4HourDateTime

func RegionMonday4HourDateTime(loc *time.Location) string

RegionMonday5HourDateTime return region Monday 05am date, format: 2006-01-02 04:00:00

func RegionMondayXHourTimestamp

func RegionMondayXHourTimestamp(region string, addHour uint32) (int64, error)

RegionMondayXHourTimestamp return region Monday 0x:00:00 timestamp

func RegionNextDailyResetHourTimeUnix

func RegionNextDailyResetHourTimeUnix(resetHour int64, region string) (int64, error)

RegionNextDailyResetHourTimeUnix return next reset time unix using regional timezone

func RegionNextDailyResetHourTimeUnixFrom

func RegionNextDailyResetHourTimeUnixFrom(timestamp int64, resetHour int64, region string) (int64, error)

RegionNextDailyResetHourTimeUnixFrom : return next resetHour timestamp from given time

func RegionPassedDayFromDateTime

func RegionPassedDayFromDateTime(region string, datetime string) (uint32, error)

RegionPassedDayFromDateTime return passed day from datetime to nowtime

func RegionTimeZoneLocation

func RegionTimeZoneLocation(region string) (*time.Location, error)

RegionTimeZoneLocation : return time zone location

func ThisMondayXHourTimeUnix

func ThisMondayXHourTimeUnix(addHour time.Duration, loc *time.Location) int64

ThisMondayXHourTimeUnix if loc is nil, using local time zone

func TimeToDate

func TimeToDate(t time.Time) string

TimeToDate format "2006-01-02"

func TimeToDateTime

func TimeToDateTime(t time.Time) string

TimeToDateTime format "2006-01-02 15:04:05"

func TodayXHourTime

func TodayXHourTime(addHour time.Duration, loc *time.Location) time.Time

TodayXHourTime if loc is nil, using local time zone

func TodayXHourTimeUnix

func TodayXHourTimeUnix(addHour time.Duration, loc *time.Location) int64

TodayXHourTimeUnix if loc is nil, using local time zone

func TomorrowXHourTime

func TomorrowXHourTime(addHour time.Duration, loc *time.Location) time.Time

TomorrowXHourTime if loc is nil, using local time zone

func TomorrowXHourTimeUnix

func TomorrowXHourTimeUnix(addHour time.Duration, loc *time.Location) int64

TomorrowXHourTimeUnix if loc is nil, using local time zone

Types

type PatchOption

type PatchOption struct {
	Region     string
	OffsetHour float32
}

Jump to

Keyboard shortcuts

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