floraison / et-orbi

Time zones for fugit and rufus-scheduler. Urbi et Orbi.
MIT License
24 stars 11 forks source link

rweek is different for different timezones #39

Closed igoshevski closed 2 weeks ago

igoshevski commented 2 weeks ago

I am exploring the modulo extension in fugit when I realized that for different timezones I get different cron next_time value.

For ex.

irb(main):017:0> Time.zone = "UTC" 
=> "UTC"
irb(main):018:0> Fugit::Cron.parse("02 10 * * tue%2").next_time(Time.parse("2024-09-05")).to_s
=> "2024-09-10 10:02:00 +0000"
irb(main):019:0> Time.zone = "Eastern Time (US & Canada)"
=> "Eastern Time (US & Canada)"
irb(main):020:0> Fugit::Cron.parse("02 10 * * tue%2").next_time(Time.parse("2024-09-05")).to_s
=> "2024-09-17 10:02:00 -0400"

I was able to trace the issue back to EtOrbi and the rweek attribute

irb(main):024:0> EtOrbi.make_time('2024-09-10 00:00:00', 'UTC').rweek
=> 298
irb(main):025:0> EtOrbi.make_time('2024-09-10 00:00:00', 'America/New_York').rweek
=> 297

My understanding is that no matter what the timezone is, rweek should represent the number of weeks from 2019-01-01 til the date in question in the timezone itself. Or maybe I do not understand how this works.

fugit 1.11.0 et-orbi 1.2.11

Thanks!

jmettraux commented 2 weeks ago
  # "reference week", used in fugit for cron modulo notation
  #
  def rweek

    @rweek ||=
      begin
        ref = EtOrbi.make_time('2019-01-01 12:00:00', @zone)
        noon = EtOrbi.make_time(strftime('%F 12:00:00'), @zone)
        ((noon - ref) / WEEK_S).floor + 1
      end
  end

Hello,

this is by design. Monday 5am in UTC is not the say time point as Monday 5am in Kamchtaka. rweek as see above takes as reference 2019-01-01 noon in the current zone, not some arbitrary zone.

It is to be expected that the same cron string produces different series of time points when run for different time zones.

Kind regards.