Changed NextTimeFromCronString() to NextTimeFromString()

This commit is contained in:
gorhill 2013-08-30 08:12:14 -04:00
parent 7613fbf12f
commit c805a2ea5c
3 changed files with 8 additions and 8 deletions

View File

@ -82,7 +82,7 @@ Import the library:
Simplest way: Simplest way:
nextTime := cronexpression.NextTimeFromCronString("0 0 29 2 *", time.Now()) nextTime := cronexpression.NextTimeFromString("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".
@ -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.NextTimeFromCronString("* * * * * 1980", time.Now())) cronexpression.NoMatch(cronexpression.NextTimeFromString("* * * * * 1980", time.Now()))
will return `true`, whereas will return `true`, whereas
cronexpression.NoMatch(cronexpression.NextTimeFromCronString("* * * * * 2050", time.Now())) cronexpression.NoMatch(cronexpression.NextTimeFromString("* * * * * 2050", time.Now()))
will return `false` (as of 2013-08-29...) will return `false` (as of 2013-08-29...)

View File

@ -100,26 +100,26 @@ func NewCronExpression(cronLine string) *CronExpression {
/******************************************************************************/ /******************************************************************************/
// NextTimeFromCronString() returns the time stamp following fromTime which // NextTimeFromString() returns the time stamp following fromTime which
// satisfies the cron expression cronLine. If no matching time stamp is found, // satisfies the cron expression cronLine. If no matching time stamp is found,
// using NoMatch() with the returned time stamp as argument will return true. // using NoMatch() with the returned time stamp as argument will return true.
// //
// 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 NextTimeFromCronString(cronLine string, fromTime time.Time) time.Time { func NextTimeFromString(cronLine string, fromTime time.Time) time.Time {
cronexpr := NewCronExpression(cronLine) cronexpr := NewCronExpression(cronLine)
return cronexpr.NextTime(fromTime) return cronexpr.NextTime(fromTime)
} }
/******************************************************************************/ /******************************************************************************/
// NextTimeNFromCronString() returns the n time stamps following fromTime which // NextTimeNFromString() returns the n time stamps following fromTime which
// satisfy the cron expression cronLine. An empty list is returned if // satisfy the cron expression cronLine. An empty list is returned if
// there is no matching time stamp. // there is no matching time stamp.
// //
// 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 NextTimeNFromCronString(cronLine string, fromTime time.Time, n int) []time.Time { func NextTimeNFromString(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)
} }

View File

@ -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.NextTimeFromCronString(test.expr, from) next := cronexpression.NextTimeFromString(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)