robfig/cron — pull request #12 by lukescott (2014-01-18 01:29:15+00:00)
Title: Add support for DST

This addition takes DST into account and prevents jobs from being repeated or skipped.

Before:

```
0 0 2 * * *
Start: Sun, 09 Mar 2014 01:00:00 PST
+1 Hr: Sun, 09 Mar 2014 03:00:00 PDT
Next: Mon, 10 Mar 2014 02:00:00 PDT <-- Day skipped!!!
Next: Tue, 11 Mar 2014 02:00:00 PDT
Next: Wed, 12 Mar 2014 02:00:00 PDT
----------

0 0 1 * * *
Start: Sun, 02 Nov 2014 01:00:00 PDT
+1 Hr: Sun, 02 Nov 2014 01:00:00 PST
Next: Sun, 02 Nov 2014 01:00:00 PST <-- Day repeated!!!
Next: Sun, 02 Nov 2014 01:00:00 PST
Next: Sun, 02 Nov 2014 01:00:00 PST
----------

0 0 * * * *
Start: Sun, 09 Mar 2014 01:00:00 PST
+1 Hr: Sun, 09 Mar 2014 03:00:00 PDT
Next: Sun, 09 Mar 2014 03:00:00 PDT
Next: Sun, 09 Mar 2014 04:00:00 PDT
Next: Sun, 09 Mar 2014 05:00:00 PDT
----------

0 0 * * * *
Start: Sun, 02 Nov 2014 01:00:00 PDT
+1 Hr: Sun, 02 Nov 2014 01:00:00 PST
Next: Sun, 02 Nov 2014 01:00:00 PST <--- repeat!!!
Next: Sun, 02 Nov 2014 01:00:00 PST <--- repeat!!!
Next: Sun, 02 Nov 2014 01:00:00 PST <--- repeat!!!
----------
```

After:

```
0 0 2 * * *
Start: Sun, 09 Mar 2014 01:00:00 PST
+1 Hr: Sun, 09 Mar 2014 03:00:00 PDT
Next: Sun, 09 Mar 2014 03:00:00 PDT <-- next hour because 2:00 doesn't exist
Next: Mon, 10 Mar 2014 02:00:00 PDT
Next: Tue, 11 Mar 2014 02:00:00 PDT
----------

0 0 1 * * *
Start: Sun, 02 Nov 2014 01:00:00 PDT
+1 Hr: Sun, 02 Nov 2014 01:00:00 PST
Next: Mon, 03 Nov 2014 01:00:00 PST <-- task already run at 1:00, so 1:00 the next day
Next: Tue, 04 Nov 2014 01:00:00 PST
Next: Wed, 05 Nov 2014 01:00:00 PST
----------

0 0 * * * *
Start: Sun, 09 Mar 2014 01:00:00 PST
+1 Hr: Sun, 09 Mar 2014 03:00:00 PDT
Next: Sun, 09 Mar 2014 03:00:00 PDT
Next: Sun, 09 Mar 2014 04:00:00 PDT
Next: Sun, 09 Mar 2014 05:00:00 PDT
----------

0 0 * * * *
Start: Sun, 02 Nov 2014 01:00:00 PDT
+1 Hr: Sun, 02 Nov 2014 01:00:00 PST
Next: Sun, 02 Nov 2014 02:00:00 PST <-- no repeat
Next: Sun, 02 Nov 2014 03:00:00 PST
Next: Sun, 02 Nov 2014 04:00:00 PST
----------
```

Code used: https://gist.github.com/lukescott/8484861