Documentation ¶
Index ¶
- Constants
- Variables
- func DateSub(t1 time.Time, t2 time.Time, loc *time.Location) time.Duration
- func DateSubLocal(t1 time.Time, t2 time.Time) time.Duration
- func DateSubToDay(t1 time.Time, t2 time.Time, loc *time.Location) int
- func DefaultFormat(t time.Time) string
- func DurationFormat(dur time.Duration) string
- func FixLocalTimeToOffsetSpecifiedZoneTime(timeOffset int, localTime string) string
- func FromUnixFloat(f float64) time.Time
- func GetPeriodFromGenericSortedList(t time.Time, SortedList interface{}) (index int, err error)
- func GetPeriodFromSortedList(t time.Time, SortedList []Period) (index int, ok bool)
- func GetUnixFloat(t1 time.Time) float64
- func IsSameDay(t1 time.Time, t2 time.Time, loc *time.Location) bool
- func ModBySecond(t1 time.Time) time.Time
- func MonthAndDayFormat(t time.Time) string
- func MustFromLocalMysqlFormat(timeString string) time.Time
- func MustFromMysqlFormat(timeString string) time.Time
- func MustFromMysqlFormatDefaultTZ(timeString string) time.Time
- func MustFromMysqlFormatInLocation(timeString string, loc *time.Location) time.Time
- func MustLoadZone(name string) (loc *time.Location)
- func MustNotTimeout(f func(), dur time.Duration)
- func MustParseAutoInDefault(sTime string) (t time.Time)
- func MustParseAutoInLocal(sTime string) (t time.Time)
- func MysqlNowFromDefaultNower() string
- func MysqlUsNowFromDefaultNower() string
- func NowFromDefaultNower() time.Time
- func NowWithFileNameFormatV2() string
- func ParseAutoInDefault(sTime string) (t time.Time, err error)
- func ParseAutoInLocal(sTime string) (t time.Time, err error)
- func ParseAutoInLocation(sTime string, loc *time.Location) (t time.Time, err error)
- func PeriodListSort(PeriodList PeriodListInterface)
- func PeriodSort(p []Period)
- func SelectPeriodFromSortedPeriodList(t time.Time, PeriodList PeriodListInterface) (index int, ok bool)
- func SetFixNowFromString(s string)
- func SetNowerToDefault()
- func Timeout(f func(), dur time.Duration) (hasTimeout bool)
- func ToDate(t time.Time) time.Time
- func ToDateString(t time.Time) string
- func ToLocal(t time.Time) time.Time
- type FixedNower
- type MonthDate
- type Nower
- type Period
- type PeriodGetter
- type PeriodHour
- type PeriodList
- func (p PeriodList) Append(period Period) PeriodList
- func (p PeriodList) IsIncludeOverlap() bool
- func (p PeriodList) Len() int
- func (p PeriodList) Less(i, j int) bool
- func (p PeriodList) SelectFromTime(t time.Time) (OriginIndex int, ok bool)
- func (p PeriodList) SetAtIndex(period Period, i int)
- func (p PeriodList) Sort()
- func (p PeriodList) Swap(i, j int)
- type PeriodListElement
- type PeriodListInterface
- type PeriodSlice
- type TimeRecoverInt
Constants ¶
View Source
const ( FormatMysqlZero = "0000-00-00 00:00:00" FormatMysql = "2006-01-02 15:04:05" FormatMysqlUs = "2006-01-02 15:04:05.999999" FormatFileName = "2006-01-02_15-04-05" //适合显示在文件上面的日期格式 @deprecated FormatFileNameV2 = "2006-01-02-15-04-05" //版本2,更规整,方便使用正则取出 FormatDateMysql = "2006-01-02" Iso3339Hour = "2006-01-02T15" Iso3339Minute = "2006-01-02T15:04" Iso3339Second = "2006-01-02T15:04:05" AppleJsonFormat = "2006-01-02 15:04:05 Etc/MST" //仅解决GMT的这个特殊情况.其他不管,如果苹果返回的字符串换时区了就悲剧了 FormatMysqlMinute = "2006-01-02 15:04" FormatMysqlMouthAndDay = "01-02" FormatMysqlYearAndMoney = "2006-01" )
View Source
const (
Day = 24 * time.Hour
)
Variables ¶
View Source
var BeijingZone = time.FixedZone("CST", 8*60*60)
View Source
var DefaultNower tDefaultNower
@deprecated
View Source
var DefaultTimeZone = BeijingZone
View Source
var ESTZone = time.FixedZone("EST", -5*60*60) // Eastern Standard Time(加拿大)
View Source
var ErrTimeOut = errors.New("time out")
View Source
var MysqlEnd = "9999-12-31 23:59:59"
View Source
var MysqlStart = "0000-01-01 00:00:00"
View Source
var NotFoundError = errors.New("not found")
View Source
var ParseFormatGuessList = []string{ FormatMysqlZero, FormatMysql, FormatDateMysql, Iso3339Hour, Iso3339Minute, Iso3339Second, time.RFC3339, time.RFC3339Nano, }
View Source
var ReflectTypePeriodGetter = reflect.TypeOf((*PeriodGetter)(nil)).Elem()
Functions ¶
func DateSubToDay ¶
规整到日期然后相减,返回天数
func FromUnixFloat ¶
func GetPeriodFromGenericSortedList ¶
实现1,反射
func GetPeriodFromSortedList ¶
SortedList should sort by start time and should not overlap each other
func GetUnixFloat ¶
func MonthAndDayFormat ¶
func MustFromLocalMysqlFormat ¶
local time
func MustFromMysqlFormatDefaultTZ ¶
使用默认时区解释mysql 数据结构
func MustLoadZone ¶
golang 的时区实现看上去很复杂,而且有系统依赖,此处添加一个简单时区枚举,不考虑夏令时,也不考虑时区变化
func MustNotTimeout ¶
func MustParseAutoInDefault ¶
func MysqlNowFromDefaultNower ¶
func MysqlNowFromDefaultNower() string
func MysqlUsNowFromDefaultNower ¶
func MysqlUsNowFromDefaultNower() string
func NowFromDefaultNower ¶
func NowWithFileNameFormatV2 ¶
func NowWithFileNameFormatV2() string
func ParseAutoInLocation ¶
auto guess format from ParseFormatGuessList
func PeriodListSort ¶
func PeriodListSort(PeriodList PeriodListInterface)
func PeriodSort ¶
func PeriodSort(p []Period)
func SelectPeriodFromSortedPeriodList ¶
func SelectPeriodFromSortedPeriodList(t time.Time, PeriodList PeriodListInterface) (index int, ok bool)
func SetFixNowFromString ¶
func SetFixNowFromString(s string)
func SetNowerToDefault ¶
func SetNowerToDefault()
func ToDateString ¶
Types ¶
type FixedNower ¶
func (FixedNower) Now ¶
func (nower FixedNower) Now() time.Time
type Nower ¶
var NowTime Nower = tDefaultNower{}
func GetDefaultNower ¶
func GetDefaultNower() Nower
func NewFixedNower ¶
type Period ¶
a period time start from Start,end to End, start must before or equal end
type PeriodGetter ¶
type PeriodGetter interface {
GetPeriod() Period
}
type PeriodList ¶
type PeriodList []PeriodListElement
实现3,数据结构分离
func (PeriodList) Append ¶
func (p PeriodList) Append(period Period) PeriodList
向后追加一个时间段,index为追加前的长度
func (PeriodList) Len ¶
func (p PeriodList) Len() int
func (PeriodList) Less ¶
func (p PeriodList) Less(i, j int) bool
func (PeriodList) SelectFromTime ¶
func (p PeriodList) SelectFromTime(t time.Time) (OriginIndex int, ok bool)
sort it first
func (PeriodList) SetAtIndex ¶
func (p PeriodList) SetAtIndex(period Period, i int)
func (PeriodList) Sort ¶
func (p PeriodList) Sort()
func (PeriodList) Swap ¶
func (p PeriodList) Swap(i, j int)
type PeriodListElement ¶
type PeriodListInterface ¶
实现2,interface
type PeriodSlice ¶
type PeriodSlice []Period
func (PeriodSlice) Len ¶
func (p PeriodSlice) Len() int
func (PeriodSlice) Less ¶
func (p PeriodSlice) Less(i, j int) bool
func (PeriodSlice) Swap ¶
func (p PeriodSlice) Swap(i, j int)
type TimeRecoverInt ¶
类似于体力一样的,每隔一定时间就会恢复一点(加一点)的值, 没有负值,不会超过最大值 如果执行时间向前退,不会报错
func (*TimeRecoverInt) Full ¶
func (t *TimeRecoverInt) Full(now time.Time)
func (*TimeRecoverInt) Sync ¶
func (t *TimeRecoverInt) Sync(now time.Time)
Click to show internal directories.
Click to hide internal directories.