package now
import "time"
var WeekStartDay = time .Sunday
var TimeFormats = []string {
"2006" , "2006-1" , "2006-1-2" , "2006-1-2 15" , "2006-1-2 15:4" , "2006-1-2 15:4:5" , "1-2" ,
"15:4:5" , "15:4" , "15" ,
"15:4:5 Jan 2, 2006 MST" , "2006-01-02 15:04:05.999999999 -0700 MST" , "2006-01-02T15:04:05Z0700" , "2006-01-02T15:04:05Z07" ,
"2006.1.2" , "2006.1.2 15:04:05" , "2006.01.02" , "2006.01.02 15:04:05" , "2006.01.02 15:04:05.999999999" ,
"1/2/2006" , "1/2/2006 15:4:5" , "2006/01/02" , "20060102" , "2006/01/02 15:04:05" ,
time .ANSIC , time .UnixDate , time .RubyDate , time .RFC822 , time .RFC822Z , time .RFC850 ,
time .RFC1123 , time .RFC1123Z , time .RFC3339 , time .RFC3339Nano ,
time .Kitchen , time .Stamp , time .StampMilli , time .StampMicro , time .StampNano ,
}
type Config struct {
WeekStartDay time .Weekday
TimeLocation *time .Location
TimeFormats []string
}
var DefaultConfig *Config
func (config *Config ) With (t time .Time ) *Now {
return &Now {Time : t , Config : config }
}
func (config *Config ) Parse (strs ...string ) (time .Time , error ) {
if config .TimeLocation == nil {
return config .With (time .Now ()).Parse (strs ...)
} else {
return config .With (time .Now ().In (config .TimeLocation )).Parse (strs ...)
}
}
func (config *Config ) MustParse (strs ...string ) time .Time {
if config .TimeLocation == nil {
return config .With (time .Now ()).MustParse (strs ...)
} else {
return config .With (time .Now ().In (config .TimeLocation )).MustParse (strs ...)
}
}
type Now struct {
time .Time
*Config
}
func With (t time .Time ) *Now {
config := DefaultConfig
if config == nil {
config = &Config {
WeekStartDay : WeekStartDay ,
TimeFormats : TimeFormats ,
}
}
return &Now {Time : t , Config : config }
}
func New (t time .Time ) *Now {
return With (t )
}
func BeginningOfMinute () time .Time {
return With (time .Now ()).BeginningOfMinute ()
}
func BeginningOfHour () time .Time {
return With (time .Now ()).BeginningOfHour ()
}
func BeginningOfDay () time .Time {
return With (time .Now ()).BeginningOfDay ()
}
func BeginningOfWeek () time .Time {
return With (time .Now ()).BeginningOfWeek ()
}
func BeginningOfMonth () time .Time {
return With (time .Now ()).BeginningOfMonth ()
}
func BeginningOfQuarter () time .Time {
return With (time .Now ()).BeginningOfQuarter ()
}
func BeginningOfYear () time .Time {
return With (time .Now ()).BeginningOfYear ()
}
func EndOfMinute () time .Time {
return With (time .Now ()).EndOfMinute ()
}
func EndOfHour () time .Time {
return With (time .Now ()).EndOfHour ()
}
func EndOfDay () time .Time {
return With (time .Now ()).EndOfDay ()
}
func EndOfWeek () time .Time {
return With (time .Now ()).EndOfWeek ()
}
func EndOfMonth () time .Time {
return With (time .Now ()).EndOfMonth ()
}
func EndOfQuarter () time .Time {
return With (time .Now ()).EndOfQuarter ()
}
func EndOfYear () time .Time {
return With (time .Now ()).EndOfYear ()
}
func Monday (strs ...string ) time .Time {
return With (time .Now ()).Monday (strs ...)
}
func Sunday (strs ...string ) time .Time {
return With (time .Now ()).Sunday (strs ...)
}
func EndOfSunday () time .Time {
return With (time .Now ()).EndOfSunday ()
}
func Quarter () uint {
return With (time .Now ()).Quarter ()
}
func Parse (strs ...string ) (time .Time , error ) {
return With (time .Now ()).Parse (strs ...)
}
func ParseInLocation (loc *time .Location , strs ...string ) (time .Time , error ) {
return With (time .Now ().In (loc )).Parse (strs ...)
}
func MustParse (strs ...string ) time .Time {
return With (time .Now ()).MustParse (strs ...)
}
func MustParseInLocation (loc *time .Location , strs ...string ) time .Time {
return With (time .Now ().In (loc )).MustParse (strs ...)
}
func Between (time1 , time2 string ) bool {
return With (time .Now ()).Between (time1 , time2 )
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .