Documentation ¶
Index ¶
- Variables
- func EndOfDay(t time.Time) time.Time
- func EndOfToday() time.Time
- func Interval(ctx context.Context, duration time.Duration) (chan struct{}, context.CancelFunc)
- func Local() time.Time
- func MeasureDuration(fn func()) time.Duration
- func MustParse(datestr string) time.Time
- func NowMillis() int64
- func ParseAny(datestr string) (time.Time, error)
- func ParseFormat(datestr string) (string, error)
- func ParseIn(datestr string, loc *time.Location) (time.Time, error)
- func ParseLocal(datestr string) (time.Time, error)
- func ParseStrict(datestr string) (time.Time, error)
- func RunInterval(ctx context.Context, duration time.Duration, fn func()) context.CancelFunc
- func StartOfDay(t time.Time) time.Time
- func StartOfToday() time.Time
- func Tomorrow() time.Time
- func UTC() time.Time
- func Yesterday() time.Time
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAmbiguousMMDD for date formats such as 04/02/2014 the mm/dd vs dd/mm are // ambiguous, so it is an error for strict parse rules. ErrAmbiguousMMDD = fmt.Errorf("err: this date has ambiguous mm/dd vs dd/mm type format") )
Functions ¶
func EndOfToday ¶
func Interval ¶
Interval return a chan chan emit event every duration and a cancel function to cancel interval.
func MeasureDuration ¶
MeasureDuration will measure duration of an operation.
func MustParse ¶
MustParse parse a date, and panic if it can't be parsed. Used for testing. Not recommended for most use-cases.
func ParseAny ¶
ParseAny parse an unknown date format, detect the layout. Normal parse. Equivalent Timezone rules as time.Parse(). NOTE: please see readme on mmdd vs ddmm ambiguous dates.
func ParseFormat ¶
ParseFormat parse's an unknown date-time string and returns a layout string that can parse this (and exact same format) other date-time strings.
layout, err := dateparse.ParseFormat("2013-02-01 00:00:00") // layout = "2006-01-02 15:04:05"
func ParseIn ¶
ParseIn with Location, equivalent to time.ParseInLocation() timezone/offset rules. Using location arg, if timezone/offset info exists in the datestring, it uses the given location rules for any zone interpretation. That is, MST means one thing when using America/Denver and something else in other locations.
func ParseLocal ¶
ParseLocal Given an unknown date format, detect the layout, using time.Local, parse.
Set Location to time.Local. Same as ParseIn Location but lazily uses the global time.Local variable for Location argument.
denverLoc, _ := time.LoadLocation("America/Denver") time.Local = denverLoc t, err := dateparse.ParseLocal("3/1/2014")
Equivalent to:
t, err := dateparse.ParseIn("3/1/2014", denverLoc)
func ParseStrict ¶
ParseStrict parse an unknown date format. IF the date is ambigous mm/dd vs dd/mm then return an error. These return errors: 3.3.2014 , 8/8/71 etc
func RunInterval ¶
RunInterval run user-defined function every duration until cancel.
func StartOfToday ¶
Types ¶
This section is empty.