gxtime

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

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

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

func BeginningOfDay

func BeginningOfDay() time.Time

func BeginningOfHour

func BeginningOfHour() time.Time

func BeginningOfMinute

func BeginningOfMinute() time.Time

func BeginningOfMonth

func BeginningOfMonth() time.Time

func BeginningOfQuarter

func BeginningOfQuarter() time.Time

func BeginningOfWeek

func BeginningOfWeek() time.Time

func BeginningOfYear

func BeginningOfYear() time.Time

func Between

func Between(time1, time2 string) bool

func EndOfDay

func EndOfDay() time.Time

func EndOfHour

func EndOfHour() time.Time

func EndOfMinute

func EndOfMinute() time.Time

func EndOfMonth

func EndOfMonth() time.Time

func EndOfQuarter

func EndOfQuarter() time.Time

func EndOfSunday

func EndOfSunday() time.Time

func EndOfWeek

func EndOfWeek() time.Time

func EndOfYear

func EndOfYear() time.Time

func Format

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

func GetEndtime(format string) time.Time

func Init

func Init()

to init a default timer wheel

func Monday

func Monday() time.Time

func MustParse

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

func MustParseInLocation

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

func Now

func Now() time.Time

func Parse

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

func ParseInLocation

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

func Sleep

func Sleep(d time.Duration)

func Sunday

func Sunday() time.Time

func Tick

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

返回的channel无法被close

func Time2Unix

func Time2Unix(t time.Time) int64

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

func Time2UnixNano

func Time2UnixNano(t time.Time) int64

func TimeDayDuratioin

func TimeDayDuratioin(day float64) time.Duration

func TimeHourDuratioin

func TimeHourDuratioin(hour float64) time.Duration

func TimeMicrosecondDuration

func TimeMicrosecondDuration(m float64) time.Duration

func TimeMillisecondDuration

func TimeMillisecondDuration(m float64) time.Duration

func TimeMinuteDuration

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

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

type GxTime struct {
	time.Time
}

parse time string

func NewGxTime

func NewGxTime(t time.Time) *GxTime

func (*GxTime) BeginningOfDay

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

func (*GxTime) BeginningOfHour

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

func (*GxTime) BeginningOfMinute

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

func (*GxTime) BeginningOfMonth

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

func (*GxTime) BeginningOfQuarter

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

func (*GxTime) BeginningOfWeek

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

func (*GxTime) BeginningOfYear

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

func (*GxTime) Between

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

func (*GxTime) EndOfDay

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

func (*GxTime) EndOfHour

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

func (*GxTime) EndOfMinute

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

func (*GxTime) EndOfMonth

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

func (*GxTime) EndOfQuarter

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

func (*GxTime) EndOfSunday

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

func (*GxTime) EndOfWeek

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

func (*GxTime) EndOfYear

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

func (*GxTime) Monday

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

func (*GxTime) MustParse

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

func (*GxTime) Parse

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

func (*GxTime) Sunday

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

type Ticker

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

func NewTicker

func NewTicker(d time.Duration) *Ticker

func TickFunc

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

func (*Ticker) Reset

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

func (*Ticker) Stop

func (t *Ticker) Stop()

type Timer

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

func AfterFunc

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

func NewTimer

func NewTimer(d time.Duration) *Timer

func (*Timer) Reset

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

func (*Timer) Stop

func (t *Timer) Stop()

type TimerFunc

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

type TimerID = uint64

type TimerType

type TimerType int32

type TimerWheel

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

timer based on multiple wheels

func NewTimerWheel

func NewTimerWheel() *TimerWheel

func (*TimerWheel) AddTimer

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

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

func (*TimerWheel) After

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

func (*TimerWheel) AfterFunc

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

func (*TimerWheel) Close

func (w *TimerWheel) Close()

func (*TimerWheel) NewTicker

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

func (*TimerWheel) NewTimer

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

func (*TimerWheel) Now

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

func (*TimerWheel) Sleep

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

func (*TimerWheel) Stop

func (w *TimerWheel) Stop()

func (*TimerWheel) Tick

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

func (*TimerWheel) TickFunc

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

func (*TimerWheel) TimerNumber

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 refers from https://github.com/senseyeio/spaniel/blob/master/interval.go

Jump to

Keyboard shortcuts

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