renaming cronexpression to cronexpr

This commit is contained in:
gorhill 2013-08-31 09:00:46 -04:00
parent 83135b3c5c
commit 022ba1e5bf
1 changed files with 10 additions and 12 deletions

View File

@ -1,7 +1,5 @@
cronexpression for Go Golang Cron expression parser
===================== =============================
Cron expression parser in Go language (golang).
Given a cron expression and a time stamp, you can get the next time stamp which satisfies the cron expression. Given a cron expression and a time stamp, you can get the next time stamp which satisfies the cron expression.
In another project, I decided to use cron expression syntax to encode scheduling information. Thus this standalone library to parse and apply time stamps to cron expressions. In another project, I decided to use cron expression syntax to encode scheduling information. Thus this standalone library to parse and apply time stamps to cron expressions.
@ -66,41 +64,41 @@ Other details
Install Install
------- -------
go get github.com/gorhill/cronexpression go get github.com/gorhill/cronexpr
Usage Usage
----- -----
Import the library: Import the library:
import "github.com/gorhill/cronexpression" import "github.com/gorhill/cronexpr"
import "time" import "time"
Simplest way: Simplest way:
nextTime := cronexpression.Parse("0 0 29 2 *").Next(time.Now()) nextTime := cronexpr.Parse("0 0 29 2 *").Next(time.Now())
Assuming `time.Now()` is "2013-08-29 09:28:00", then `nextTime` will be "2016-02-29 00:00:00". Assuming `time.Now()` is "2013-08-29 09:28:00", then `nextTime` will be "2016-02-29 00:00:00".
You can keep the returned Expression pointer around if you want to reuse it: You can keep the returned Expression pointer around if you want to reuse it:
expr := cronexpression.Parse("0 0 29 2 *") expr := cronexpr.Parse("0 0 29 2 *")
nextTime := expr.Next(time.Now()) nextTime := expr.Next(time.Now())
... ...
nextTime = expr.Next(nextTime) nextTime = expr.Next(nextTime)
Use `time.IsZero()` to find out whether a valid time was returned. For example, Use `time.IsZero()` to find out whether a valid time was returned. For example,
cronexpression.Parse("* * * * * 1980").Next(time.Now()).IsZero() cronexpr.Parse("* * * * * 1980").Next(time.Now()).IsZero()
will return `true`, whereas will return `true`, whereas
cronexpression.Parse("* * * * * 2050").Next(time.Now()).IsZero() cronexpr.Parse("* * * * * 2050").Next(time.Now()).IsZero()
will return `false` (as of 2013-08-29...) will return `false` (as of 2013-08-29...)
You may also query for `n` next time stamps: You may also query for `n` next time stamps:
cronexpression.Parse("0 0 29 2 *").NextN(time.Now(), 5) cronexpr.Parse("0 0 29 2 *").NextN(time.Now(), 5)
which returns a slice of time.Time objects, containing the following time stamps (as of 2013-08-30): which returns a slice of time.Time objects, containing the following time stamps (as of 2013-08-30):
@ -112,4 +110,4 @@ which returns a slice of time.Time objects, containing the following time stamps
API API
--- ---
<http://godoc.org/github.com/gorhill/cronexpression> <http://godoc.org/github.com/gorhill/cronexpr>