Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour with DST? #53

Closed
andyundso opened this issue Mar 22, 2021 · 5 comments
Closed

Strange behaviour with DST? #53

andyundso opened this issue Mar 22, 2021 · 5 comments
Assignees

Comments

@andyundso
Copy link

Issue description

First of all, I'm based in Switzerland. Our clock will change next week to summer time. We use Fugit in a project to allow users schedule background jobs. We have a test suite that has a test where a job should run each week with the instruction every monday at midnight. We compare the result of Fugit with an expected value to make sure our scheduler works.

Now, instructing Fugit to give the next date for said schedule strangely gives a date in two weeks instead of next week. Other hours seem to work fine:

irb(main):003:0> Fugit.parse("every monday at 3am").next_time.to_s
=> "2021-03-29 03:00:00 +0200"
irb(main):004:0> Fugit.parse("every monday at 2am").next_time.to_s
=> "2021-03-29 02:00:00 +0200"
irb(main):005:0> Fugit.parse("every monday at 1am").next_time.to_s
=> "2021-03-29 01:00:00 +0200"
irb(main):006:0> Fugit.parse("every monday at midnight").next_time.to_s
=> "2021-04-05 00:00:00 +0200"

I'm not sure if it is related to DST and if this is supposed to happen (I don't know cron too well).

How to reproduce

See above.

Error and error backtrace (if any)

Not needed, as no error will be printed.

Expected behaviour

next_time should print Mon, 29 Mar 2021 00:00:00 CEST +02:00.

Context

Please replace the content of this section with the output of the following commands:

uname -a
bundle exec ruby -v
bundle exec ruby -e "p [ :env_tz, ENV['TZ'] ]"
bundle exec ruby -r et-orbi -e "EtOrbi._make_info"
bundle exec ruby -r fugit -e "p Fugit::VERSION"

(It's supposed to look like

Linux apf-work-home 5.4.0-67-generic #75-Ubuntu SMP Fri Feb 19 18:03:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-linux]
[:env_tz, nil]
(secs:1616405592.3763082,utc~:"2021-03-22 09:33:12.3763082027435303",ltz~:"CET")
(etz:nil,tnz:"CET",tziv:"1.2.9",tzidv:nil,rv:"2.5.8",rp:"x86_64-linux",win:false,rorv:nil,astz:nil,eov:"1.2.4",eotnz:#<TZInfo::DataTimezone: Europe/Zurich>,eotnfz:"+0100",eotlzn:"Europe/Zurich",eotnfZ:"CET",debian:"Europe/Zurich",centos:nil,osx:"Europe/Zurich")
"1.4.2"

)

@jmettraux jmettraux self-assigned this Mar 22, 2021
@jmettraux
Copy link
Member

Hello,

thanks for the report. I am working on it.

As a workaround, you could use "every tuesday at 00:00" as seen in

fugit/spec/cron_spec.rb

Lines 265 to 288 in 49b6670

it 'correctly increments into DST (gh-53 c)' do
in_zone 'Europe/Zurich' do
#c = Fugit::Nat.parse('every monday at midnight')
#c = Fugit::Cron.parse('0 0 * * 2')
c = Fugit::Nat.parse('every tuesday at 00:00')
t = EtOrbi::EoTime.parse('2021-03-14 12:00:00')
points =
4.times.collect do
t = c.next_time(t)
tu = t.dup.utc
"#{t.strftime('%F_%H:%M_%Z')}__#{tu.strftime('%F_%H:%M_%Z')}"
end
expect(points.join("\n")).to eq(%w[
2021-03-16_00:00_CET__2021-03-15_23:00_UTC
2021-03-23_00:00_CET__2021-03-22_23:00_UTC
2021-03-30_00:00_CEST__2021-03-29_22:00_UTC
2021-04-06_00:00_CEST__2021-04-05_22:00_UTC
].join("\n"))
end
end

I think I am guilty of interpreting "every monday at midnight" as "every monday at 00:00". I need to straighten that.

Now, I still have to double-check, the entrance into DST is done at 02:00, it should make a 00:00 schedule skip.

transition

jmettraux added a commit that referenced this issue Mar 22, 2021
Interpret as "Every Monday at 00:00"
Embrace the mistake :-( for now
@jmettraux
Copy link
Member

@andyundso

Hello, could you please tell me if the above fix suits you? If yes, I will release 1.4.3.

require 'fugit'

ENV['TZ'] = 'Europe/Zurich'

t0 = Time.parse('2021-03-22 13:00')

p Fugit.parse('every monday at midnight').next_time(t0).to_s
  # ==>     "2021-03-29 00:00:00 +0200"
  # and not "2021-04-05 00:00:00 +0200"

Best regards.

@andyundso
Copy link
Author

andyundso commented Mar 23, 2021

Good morning @jmettraux

Many thanks for the quick reaction. I tested the master branch with our test and now it works. I think you can release 1.4.3.

Best regards, Andy

@jmettraux
Copy link
Member

It's released https://rubygems.org/gems/fugit/versions/1.4.3

Thanks again!

jmettraux added a commit that referenced this issue Mar 25, 2021
@jmettraux
Copy link
Member

@andyundso

Hello,

for the sake of completeness, I added a spec for when leaving the DST (October) and it failed. I have fixed the problem and released 1.4.4. 550e571

Please upgrade before October.

Best regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants