Changed NextTimeFromString() to NextTime()
This commit is contained in:
parent
c805a2ea5c
commit
22a2cb9e99
|
@ -82,11 +82,11 @@ Import the library:
|
||||||
|
|
||||||
Simplest way:
|
Simplest way:
|
||||||
|
|
||||||
nextTime := cronexpression.NextTimeFromString("0 0 29 2 *", time.Now())
|
nextTime := cronexpression.NextTime("0 0 29 2 *", 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".
|
||||||
|
|
||||||
If you need to reuse many times a cron expression in your code, it is more efficient
|
If you need to reuse many times the same cron expression in your code, it is more efficient
|
||||||
to create a `CronExpression` object once and keep a copy of it for reuse:
|
to create a `CronExpression` object once and keep a copy of it for reuse:
|
||||||
|
|
||||||
cronexpr := cronexpression.NewCronExpression("0 0 29 2 *")
|
cronexpr := cronexpression.NewCronExpression("0 0 29 2 *")
|
||||||
|
@ -95,11 +95,11 @@ to create a `CronExpression` object once and keep a copy of it for reuse:
|
||||||
|
|
||||||
Use `cronexpression.NoMatch()` to find out whether a valid time was returned. For example,
|
Use `cronexpression.NoMatch()` to find out whether a valid time was returned. For example,
|
||||||
|
|
||||||
cronexpression.NoMatch(cronexpression.NextTimeFromString("* * * * * 1980", time.Now()))
|
cronexpression.NoMatch(cronexpression.NextTime("* * * * * 1980", time.Now()))
|
||||||
|
|
||||||
will return `true`, whereas
|
will return `true`, whereas
|
||||||
|
|
||||||
cronexpression.NoMatch(cronexpression.NextTimeFromString("* * * * * 2050", time.Now()))
|
cronexpression.NoMatch(cronexpression.NextTime("* * * * * 2050", time.Now()))
|
||||||
|
|
||||||
will return `false` (as of 2013-08-29...)
|
will return `false` (as of 2013-08-29...)
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ func NewCronExpression(cronLine string) *CronExpression {
|
||||||
//
|
//
|
||||||
// If the same cron expression must be used repeatedly, it is better to use
|
// If the same cron expression must be used repeatedly, it is better to use
|
||||||
// NewCronExpression() in order to avoid overhead of cron expression parsing.
|
// NewCronExpression() in order to avoid overhead of cron expression parsing.
|
||||||
func NextTimeFromString(cronLine string, fromTime time.Time) time.Time {
|
func NextTime(cronLine string, fromTime time.Time) time.Time {
|
||||||
cronexpr := NewCronExpression(cronLine)
|
cronexpr := NewCronExpression(cronLine)
|
||||||
return cronexpr.NextTime(fromTime)
|
return cronexpr.NextTime(fromTime)
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func NextTimeFromString(cronLine string, fromTime time.Time) time.Time {
|
||||||
//
|
//
|
||||||
// If the same cron expression must be used repeatedly, it is better to use
|
// If the same cron expression must be used repeatedly, it is better to use
|
||||||
// NewCronExpression() in order to avoid overhead of cron expression parsing.
|
// NewCronExpression() in order to avoid overhead of cron expression parsing.
|
||||||
func NextTimeNFromString(cronLine string, fromTime time.Time, n int) []time.Time {
|
func NextTimeN(cronLine string, fromTime time.Time, n int) []time.Time {
|
||||||
cronexpr := NewCronExpression(cronLine)
|
cronexpr := NewCronExpression(cronLine)
|
||||||
return cronexpr.NextTimeN(fromTime, n)
|
return cronexpr.NextTimeN(fromTime, n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ func TestCronExpressions(t *testing.T) {
|
||||||
for _, test := range crontests {
|
for _, test := range crontests {
|
||||||
for _, times := range test.times {
|
for _, times := range test.times {
|
||||||
from, _ := time.Parse("2006-01-02 15:04:05", times.from)
|
from, _ := time.Parse("2006-01-02 15:04:05", times.from)
|
||||||
next := cronexpression.NextTimeFromString(test.expr, from)
|
next := cronexpression.NextTime(test.expr, from)
|
||||||
nextstr := next.Format(test.layout)
|
nextstr := next.Format(test.layout)
|
||||||
if nextstr != times.next {
|
if nextstr != times.next {
|
||||||
t.Errorf("(\"%s\").NextTime(\"%s\") = \"%s\", got \"%s\"", test.expr, times.from, times.next, nextstr)
|
t.Errorf("(\"%s\").NextTime(\"%s\") = \"%s\", got \"%s\"", test.expr, times.from, times.next, nextstr)
|
||||||
|
|
Loading…
Reference in New Issue