From 11790c3506706eb8e8a38affcc2f1c16a506e793 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Thu, 3 Oct 2024 15:51:14 +0900 Subject: [PATCH] Ensure @yearly and friends accept a timezone --- lib/fugit/cron.rb | 16 ++++++++++++---- spec/cron_spec.rb | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/fugit/cron.rb b/lib/fugit/cron.rb index 13e5dce..6622da6 100644 --- a/lib/fugit/cron.rb +++ b/lib/fugit/cron.rb @@ -32,15 +32,23 @@ def new(original) def parse(s) return s if s.is_a?(self) + return nil unless s.is_a?(String) - s = SPECIALS[s] || s + s0 = s + s = s.strip - return nil unless s.is_a?(String) + s = + if s[0, 1] == '@' + ss = s.split(/\s+/, 2) + [ SPECIALS[ss[0]] || ss, *ss[1..-1] ].join(' ') + else + s + end #p s; Raabro.pp(Parser.parse(s, debug: 3), colors: true) - h = Parser.parse(s.strip) + h = Parser.parse(s) - self.allocate.send(:init, s, h) + self.allocate.send(:init, s0, h) end def do_parse(s) diff --git a/spec/cron_spec.rb b/spec/cron_spec.rb index e955939..8be88ee 100644 --- a/spec/cron_spec.rb +++ b/spec/cron_spec.rb @@ -1130,6 +1130,9 @@ class Fugit::Cron::TimeCursor [ '@noon', '0 12 * * *' ], [ '@hourly', '0 * * * *' ], + [ '@yearly Asia/Kuala_Lumpur', '0 0 1 1 * Asia/Kuala_Lumpur' ], + [ '@noon Asia/Jakarta', '0 12 * * * Asia/Jakarta' ], + # min hou dom mon dow [ '5 0 * * *', '5 0 * * *' ],