parse-cron icon indicating copy to clipboard operation
parse-cron copied to clipboard

Preserve the timezone of the source when returning the time object

Open manu3569 opened this issue 4 years ago • 3 comments

Thanks for this handy gem.

For my use case, I needed to be able to support a source time with a time zone that is different from the local one. This change preserves the time zone on the returned time object.

This breaks the use case where an alternate time_source class is passed in that does not support the new method with the same signature as the one for Time.new.

manu3569 avatar Feb 13 '21 23:02 manu3569

AFAICT this PR also fixes a major bug: the cron parser skips the "fallback" hour of DST because the next method jumps from "00:59:00 PDT" to "01:00:00 PST" as it does not track the timezone. With this PR:

2021-11-07 00:55:00 -0700
2021-11-07 00:56:00 -0700
2021-11-07 00:57:00 -0700
2021-11-07 00:58:00 -0700
2021-11-07 00:59:00 -0700
2021-11-07 01:00:00 -0700
2021-11-07 01:01:00 -0700
2021-11-07 01:02:00 -0700
2021-11-07 01:03:00 -0700
...snip...
2021-11-07 01:55:00 -0700
2021-11-07 01:56:00 -0700
2021-11-07 01:57:00 -0700
2021-11-07 01:58:00 -0700
2021-11-07 01:59:00 -0700
2021-11-07 02:00:00 -0700
2021-11-07 01:01:00 -0800
2021-11-07 01:02:00 -0800
2021-11-07 01:03:00 -0800
2021-11-07 01:04:00 -0800

mperham avatar Nov 18 '21 01:11 mperham

Without the PR:

2021-11-07 00:55:00 -0700
2021-11-07 00:56:00 -0700
2021-11-07 00:57:00 -0700
2021-11-07 00:58:00 -0700
2021-11-07 00:59:00 -0700
2021-11-07 01:00:00 -0800
2021-11-07 01:01:00 -0800
2021-11-07 01:02:00 -0800
2021-11-07 01:03:00 -0800
...snip...
2021-11-07 01:57:00 -0800
2021-11-07 01:58:00 -0800
2021-11-07 01:59:00 -0800
2021-11-07 02:00:00 -0800
2021-11-07 01:01:00 -0800
2021-11-07 01:02:00 -0800
2021-11-07 01:03:00 -0800
2021-11-07 01:04:00 -0800

mperham avatar Nov 18 '21 01:11 mperham

Awesome. Glad to hear that the timezone addition fixes DST issues.

manu3569 avatar Nov 18 '21 12:11 manu3569