gxtime

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: Apache-2.0 Imports: 10 Imported by: 22

README

go-strftime

go implementation of strftime

Example

package main

import (
	"fmt"
	"time"

	strftime "github.com/jehiah/go-strftime"
)

func main() {
	t := time.Unix(1340244776, 0)
	utc, _ := time.LoadLocation("UTC")
	t = t.In(utc)
	fmt.Println(strftime.Format("%Y-%m-%d %H:%M:%S", t))
	// Output:
	// 2012-06-21 02:12:56
}

Documentation

Overview

Package gxtime encapsulates some golang.time functions

Package gxtime encapsulates some golang.time functions refer to github.com/jinzhu/now

Package gxtime encapsulates some golang.time functions

Package gxtime encapsulates some golang.time functions refer to github.com/jehiah/go-strftime

Package gxtime encapsulates some golang.time functions

Package gxtime encapsulates some golang.time functions

Package gxtime encapsulates some golang.time functions

Package gxtime encapsulates some golang.time functions ref: https://github.com/AlexStocks/go-practice/blob/master/time/siddontang_time_wheel.go

Example
time.Now() // 2013-11-18 17:51:49.123456789 Mon

BeginningOfMinute() // 2013-11-18 17:51:00 Mon
BeginningOfHour()   // 2013-11-18 17:00:00 Mon
BeginningOfDay()    // 2013-11-18 00:00:00 Mon
BeginningOfWeek()   // 2013-11-17 00:00:00 Sun

FirstDayMonday = true // Set Monday as first day
BeginningOfWeek()     // 2013-11-18 00:00:00 Mon
BeginningOfMonth()    // 2013-11-01 00:00:00 Fri
BeginningOfQuarter()  // 2013-10-01 00:00:00 Tue
BeginningOfYear()     // 2013-01-01 00:00:00 Tue

EndOfMinute() // 2013-11-18 17:51:59.999999999 Mon
EndOfHour()   // 2013-11-18 17:59:59.999999999 Mon
EndOfDay()    // 2013-11-18 23:59:59.999999999 Mon
EndOfWeek()   // 2013-11-23 23:59:59.999999999 Sat

FirstDayMonday = true // Set Monday as first day
EndOfWeek()           // 2013-11-24 23:59:59.999999999 Sun
EndOfMonth()          // 2013-11-30 23:59:59.999999999 Sat
EndOfQuarter()        // 2013-12-31 23:59:59.999999999 Tue
EndOfYear()           // 2013-12-31 23:59:59.999999999 Tue

// Use another time
t := time.Date(2013, 02, 18, 17, 51, 49, 123456789, time.UTC)
NewGxTime(t).EndOfMonth() // 2013-02-28 23:59:59.999999999 Thu

Monday()      // 2013-11-18 00:00:00 Mon
Sunday()      // 2013-11-24 00:00:00 Sun
EndOfSunday() // 2013-11-24 23:59:59.999999999 Sun
Output:

Index

Examples

Constants

View Source
const (
	ADD_TIMER   timerAction = 1
	DEL_TIMER   timerAction = 2
	RESET_TIMER timerAction = 3
)

Variables

View Source
var (
	ErrTimeChannelFull   = fmt.Errorf("timer channel full")
	ErrTimeChannelClosed = fmt.Errorf("timer channel closed")
)
View Source
var FirstDayMonday bool
View Source
var TimeFormats = []string{"1/2/2006", "1/2/2006 15:4:5", "2006-1-2 15:4:5", "2006-1-2 15:4", "2006-1-2", "1-2", "15:4:5", "15:4", "15", "15:4:5 Jan 2, 2006 MST", "2006-01-02 15:04:05.999999999 -0700 MST"}

Functions

func After added in v0.2.0

func After(d time.Duration) <-chan time.Time

func BeginningOfDay added in v0.3.0

func BeginningOfDay() time.Time

func BeginningOfHour added in v0.3.0

func BeginningOfHour() time.Time

func BeginningOfMinute added in v0.3.0

func BeginningOfMinute() time.Time

func BeginningOfMonth added in v0.3.0

func BeginningOfMonth() time.Time

func BeginningOfQuarter added in v0.3.0

func BeginningOfQuarter() time.Time

func BeginningOfWeek added in v0.3.0

func BeginningOfWeek() time.Time

func BeginningOfYear added in v0.3.0

func BeginningOfYear() time.Time

func Between added in v0.3.0

func Between(time1, time2 string) bool

func EndOfDay added in v0.3.0

func EndOfDay() time.Time

func EndOfHour added in v0.3.0

func EndOfHour() time.Time

func EndOfMinute added in v0.3.0

func EndOfMinute() time.Time

func EndOfMonth added in v0.3.0

func EndOfMonth() time.Time

func EndOfQuarter added in v0.3.0

func EndOfQuarter() time.Time

func EndOfSunday added in v0.3.0

func EndOfSunday() time.Time

func EndOfWeek added in v0.3.0

func EndOfWeek() time.Time

func EndOfYear added in v0.3.0

func EndOfYear() time.Time

func Format added in v0.2.0

func Format(format string, t time.Time) string

go implementation of strftime This is an alternative to time.Format because no one knows what date 040305 is supposed to create when used as a 'layout' string this takes standard strftime format options. For a complete list of format options see http://strftime.org/

Example
t := time.Unix(1340244776, 0)
utc, _ := time.LoadLocation("UTC")
t = t.In(utc)
fmt.Println(Format("%Y-%m-%d %H:%M:%S", t))
Output:

2012-06-21 02:12:56

func Future

func Future(sec int, f func())

func GetEndtime added in v0.3.2

func GetEndtime(format string) time.Time

func Init added in v0.2.0

func Init()

to init a default timer wheel

func Monday added in v0.3.0

func Monday() time.Time

func MustParse added in v0.3.0

func MustParse(strs ...string) time.Time

func MustParseInLocation added in v0.3.0

func MustParseInLocation(loc *time.Location, strs ...string) time.Time

func Now added in v0.3.0

func Now() time.Time

func Parse added in v0.3.0

func Parse(strs ...string) (time.Time, error)

func ParseInLocation added in v0.3.0

func ParseInLocation(loc *time.Location, strs ...string) (time.Time, error)

func Sleep added in v0.2.0

func Sleep(d time.Duration)

func Sunday added in v0.3.0

func Sunday() time.Time

func Tick added in v0.2.0

func Tick(d time.Duration) <-chan time.Time

返回的channel无法被close

func Time2Unix

func Time2Unix(t time.Time) int64

注意把time转换成unix的时候有精度损失,只返回了秒值,没有用到纳秒值

func Time2UnixNano added in v0.2.0

func Time2UnixNano(t time.Time) int64

func TimeDayDuratioin added in v0.3.0

func TimeDayDuratioin(day float64) time.Duration

func TimeHourDuratioin added in v0.3.0

func TimeHourDuratioin(hour float64) time.Duration

func TimeMicrosecondDuration

func TimeMicrosecondDuration(m float64) time.Duration

func TimeMillisecondDuration

func TimeMillisecondDuration(m float64) time.Duration

func TimeMinuteDuration added in v0.3.0

func TimeMinuteDuration(minute float64) time.Duration

func TimeNanosecondDuration

func TimeNanosecondDuration(n float64) time.Duration

func TimeSecondDuration

func TimeSecondDuration(sec float64) time.Duration

func Unix2Time

func Unix2Time(unix int64) time.Time

func UnixNano2Time added in v0.2.0

func UnixNano2Time(nano int64) time.Time

func UnixString2Time

func UnixString2Time(unix string) time.Time

func YMD

func YMD(year int, month int, day int, hour int, minute int, sec int) int

desc: convert year-month-day-hour-minute-seccond to int in second @month: 1 ~ 12 @hour: 0 ~ 23 @minute: 0 ~ 59

func YMDPrint

func YMDPrint(sec int, nsec int) string

func YMDUTC

func YMDUTC(year int, month int, day int, hour int, minute int, sec int) int

@YMD in UTC timezone

Types

type CountWatch

type CountWatch struct {
	// contains filtered or unexported fields
}

func (*CountWatch) Count

func (w *CountWatch) Count() int64

func (*CountWatch) Reset

func (w *CountWatch) Reset()

func (*CountWatch) Start

func (w *CountWatch) Start()

type GxTime added in v0.3.0

type GxTime struct {
	time.Time
}

parse time string

func NewGxTime added in v0.3.0

func NewGxTime(t time.Time) *GxTime

func (*GxTime) BeginningOfDay added in v0.3.0

func (now *GxTime) BeginningOfDay() time.Time

func (*GxTime) BeginningOfHour added in v0.3.0

func (now *GxTime) BeginningOfHour() time.Time

func (*GxTime) BeginningOfMinute added in v0.3.0

func (now *GxTime) BeginningOfMinute() time.Time

func (*GxTime) BeginningOfMonth added in v0.3.0

func (now *GxTime) BeginningOfMonth() time.Time

func (*GxTime) BeginningOfQuarter added in v0.3.0

func (now *GxTime) BeginningOfQuarter() time.Time

func (*GxTime) BeginningOfWeek added in v0.3.0

func (now *GxTime) BeginningOfWeek() time.Time

func (*GxTime) BeginningOfYear added in v0.3.0

func (now *GxTime) BeginningOfYear() time.Time

func (*GxTime) Between added in v0.3.0

func (now *GxTime) Between(time1, time2 string) bool

func (*GxTime) EndOfDay added in v0.3.0

func (now *GxTime) EndOfDay() time.Time

func (*GxTime) EndOfHour added in v0.3.0

func (now *GxTime) EndOfHour() time.Time

func (*GxTime) EndOfMinute added in v0.3.0

func (now *GxTime) EndOfMinute() time.Time

func (*GxTime) EndOfMonth added in v0.3.0

func (now *GxTime) EndOfMonth() time.Time

func (*GxTime) EndOfQuarter added in v0.3.0

func (now *GxTime) EndOfQuarter() time.Time

func (*GxTime) EndOfSunday added in v0.3.0

func (now *GxTime) EndOfSunday() time.Time

func (*GxTime) EndOfWeek added in v0.3.0

func (now *GxTime) EndOfWeek() time.Time

func (*GxTime) EndOfYear added in v0.3.0

func (now *GxTime) EndOfYear() time.Time

func (*GxTime) Monday added in v0.3.0

func (now *GxTime) Monday() time.Time

func (*GxTime) MustParse added in v0.3.0

func (now *GxTime) MustParse(strs ...string) (t time.Time)

func (*GxTime) Parse added in v0.3.0

func (now *GxTime) Parse(strs ...string) (t time.Time, err error)

func (*GxTime) Sunday added in v0.3.0

func (now *GxTime) Sunday() time.Time

type Ticker added in v0.2.0

type Ticker struct {
	C  <-chan time.Time
	ID TimerID
	// contains filtered or unexported fields
}

func NewTicker added in v0.2.0

func NewTicker(d time.Duration) *Ticker

func TickFunc added in v0.2.0

func TickFunc(d time.Duration, f func()) *Ticker

func (*Ticker) Reset added in v0.2.0

func (t *Ticker) Reset(d time.Duration)

func (*Ticker) Stop added in v0.2.0

func (t *Ticker) Stop()

type Timer added in v0.2.0

type Timer struct {
	C  <-chan time.Time
	ID TimerID
	// contains filtered or unexported fields
}

func AfterFunc added in v0.2.0

func AfterFunc(d time.Duration, f func()) *Timer

func NewTimer added in v0.2.0

func NewTimer(d time.Duration) *Timer

func (*Timer) Reset added in v0.2.0

func (t *Timer) Reset(d time.Duration)

func (*Timer) Stop added in v0.2.0

func (t *Timer) Stop()

type TimerFunc added in v0.2.0

type TimerFunc func(ID TimerID, expire time.Time, arg interface{}) error

if the return error is not nil, the related timer will be closed.

type TimerID added in v0.2.0

type TimerID = uint64

type TimerType added in v0.2.0

type TimerType int32

type TimerWheel added in v0.2.0

type TimerWheel struct {
	// contains filtered or unexported fields
}

timer based on multiple wheels

func NewTimerWheel added in v0.2.0

func NewTimerWheel() *TimerWheel

func (*TimerWheel) AddTimer added in v0.2.0

func (w *TimerWheel) AddTimer(f TimerFunc, typ TimerType, period int64, arg interface{}) (*Timer, error)

异步通知timerWheel添加一个timer,有可能失败

func (*TimerWheel) After added in v0.2.0

func (w *TimerWheel) After(d time.Duration) <-chan time.Time

func (*TimerWheel) AfterFunc added in v0.2.0

func (w *TimerWheel) AfterFunc(d time.Duration, f func()) *Timer

func (*TimerWheel) Close added in v0.2.0

func (w *TimerWheel) Close()

func (*TimerWheel) NewTicker added in v0.2.0

func (w *TimerWheel) NewTicker(d time.Duration) *Ticker

func (*TimerWheel) NewTimer added in v0.2.0

func (w *TimerWheel) NewTimer(d time.Duration) *Timer

func (*TimerWheel) Now added in v0.3.0

func (w *TimerWheel) Now() time.Time

func (*TimerWheel) Sleep added in v0.2.0

func (w *TimerWheel) Sleep(d time.Duration)

func (*TimerWheel) Stop added in v0.2.0

func (w *TimerWheel) Stop()

func (*TimerWheel) Tick added in v0.2.0

func (w *TimerWheel) Tick(d time.Duration) <-chan time.Time

func (*TimerWheel) TickFunc added in v0.2.0

func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker

func (*TimerWheel) TimerNumber added in v0.2.0

func (w *TimerWheel) TimerNumber() int

type Wheel

type Wheel struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewWheel

func NewWheel(span time.Duration, buckets int) *Wheel

func (*Wheel) After

func (w *Wheel) After(timeout time.Duration) <-chan struct{}

func (*Wheel) Now

func (w *Wheel) Now() time.Time

func (*Wheel) Stop

func (w *Wheel) Stop()

Directories

Path Synopsis
Package gxtime encapsulates some golang.time functions refers from https://github.com/senseyeio/spaniel/blob/master/interval.go Package gxtime encapsulates some golang.time functions refer from https://github.com/senseyeio/spaniel/blob/master/timespan.go
Package gxtime encapsulates some golang.time functions refers from https://github.com/senseyeio/spaniel/blob/master/interval.go Package gxtime encapsulates some golang.time functions refer from https://github.com/senseyeio/spaniel/blob/master/timespan.go

Jump to

Keyboard shortcuts

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