gxtime

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2018 License: Apache-2.0 Imports: 9 Imported by: 24

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

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

Index

Examples

Constants

View Source
const (
	MAX_MS     = 1000
	MAX_SECOND = 60
	MAX_MINUTE = 60
	MAX_HOUR   = 24
	MAX_DAY    = 31
	MS         = 1e6
	SECOND_MS  = 1 * MAX_MS * MS
	MINUTE_MS  = 1 * MAX_SECOND * SECOND_MS
	HOUR_MS    = 1 * MAX_MINUTE * MINUTE_MS
	DAY_MS     = 1 * MAX_HOUR * HOUR_MS
	// ticker interval不能设置到这种精度,
	// 实际运行时ticker的时间间隔会在1.001ms上下浮动,
	// 当ticker interval小于1ms的时候,会导致TimerWheel.hand
	// 和timeWheel.inc不增长,造成时间错乱:例如本来
	// 1.5s运行的函数在持续2.1s之后才被执行
	// MINIMUM_DIFF = 1.001 * MS
	MINIMUM_DIFF = 10 * MS
)
View Source
const (
	ADD_TIMER   timerAction = 1
	DEL_TIMER   timerAction = 2
	RESET_TIMER timerAction = 3
)
View Source
const (
	MAX_TIMER_LEVEL = 5
)

Variables

View Source
var (
	ErrTimeChannelFull   = fmt.Errorf("timer channel full")
	ErrTimeChannelClosed = fmt.Errorf("timer channel closed")
)

Functions

func After added in v0.2.0

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

func DAY_NUM added in v0.2.0

func DAY_NUM(expire int64) int64

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 HOUR_NUM added in v0.2.0

func HOUR_NUM(expire int64) int64

func Init added in v0.2.0

func Init()

to init a default timer wheel

func MINUTE_NUM added in v0.2.0

func MINUTE_NUM(expire int64) int64

func MS_NUM added in v0.2.0

func MS_NUM(expire int64) int64

func SECOND_NUM added in v0.2.0

func SECOND_NUM(expire int64) int64

func Sleep added in v0.2.0

func Sleep(d time.Duration)

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 TimeMicrosecondDuration

func TimeMicrosecondDuration(m int) time.Duration

func TimeMillisecondDuration

func TimeMillisecondDuration(m int) time.Duration

func TimeNanosecondDuration

func TimeNanosecondDuration(n int) time.Duration

func TimeSecondDuration

func TimeSecondDuration(sec int) 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 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
const (
	ETimerOnce TimerType = 0X1 << 0
	ETimerLoop TimerType = 0X1 << 1
)

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) 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 gxsync.Empty

func (*Wheel) Now

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

func (*Wheel) Stop

func (w *Wheel) Stop()

Jump to

Keyboard shortcuts

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