Giter Site home page Giter Site logo

Comments (4)

jmettraux avatar jmettraux commented on July 24, 2024

Hello,

for comparison:

then in the UTC timezone:

require 'fugit'

ENV['TZ'] = 'UTC'

t0 = Time.parse('2022-09-20 09:00:00 +0000')

#> Fugit.do_parse("0 * * * * Asia/Tokyo").next_time.to_s
#=> "2022-09-20 10:00:00 +0000"

p Fugit.do_parse('0 * * * *').next_time(t0).to_s
p Fugit.do_parse('0 * * * *').next_time(t0).utc.to_s
  # ==> "2022-09-20 10:00:00 Z"
  # ==> "2022-09-20 10:00:00 UTC"
p Fugit.do_parse('0 * * * * Asia/Tokyo').next_time(t0).to_s
p Fugit.do_parse('0 * * * * Asia/Tokyo').next_time(t0).utc.to_s
  # ==> "2022-09-20 10:00:00 Z"
  # ==> "2022-09-20 10:00:00 UTC"


#> Fugit.do_parse("0 */1 * * * Asia/Tokyo").next_time.to_s
#=> "2022-09-20 10:00:00 +0000"

p Fugit.do_parse('0 */1 * * *').next_time(t0).to_s
p Fugit.do_parse('0 */1 * * *').next_time(t0).utc.to_s
  # ==> "2022-09-20 10:00:00 Z"
  # ==> "2022-09-20 10:00:00 UTC"
p Fugit.do_parse('0 */1 * * * Asia/Tokyo').next_time(t0).to_s
p Fugit.do_parse('0 */1 * * * Asia/Tokyo').next_time(t0).utc.to_s
  # ==> "2022-09-20 10:00:00 Z"
  # ==> "2022-09-20 10:00:00 UTC"


#> Fugit.do_parse("0 0/1 * * * Asia/Tokyo").next_time.to_s
#=> "2022-09-20 15:00:00 +0000"

p Fugit.do_parse('0 0/1 * * *').next_time(t0).to_s
p Fugit.do_parse('0 0/1 * * *').next_time(t0).utc.to_s
  # ==> "2022-09-21 00:00:00 Z"
  # ==> "2022-09-21 00:00:00 UTC"
p Fugit.do_parse('0 0/1 * * * Asia/Tokyo').next_time(t0).to_s
p Fugit.do_parse('0 0/1 * * * Asia/Tokyo').next_time(t0).utc.to_s
  # ==> "2022-09-20 15:00:00 Z"
  # ==> "2022-09-20 15:00:00 UTC"

and in the Tokyo timezone:

require 'fugit'

ENV['TZ'] = 'Asia/Tokyo'

t0 = Time.parse('2022-09-20 09:00:00 +0000')


#> Fugit.do_parse("0 * * * * Asia/Tokyo").next_time.to_s
#=> "2022-09-20 10:00:00 +0000"

p Fugit.do_parse('0 * * * *').next_time(t0).to_s
p Fugit.do_parse('0 * * * *').next_time(t0).utc.to_s
  # ==> "2022-09-20 19:00:00 +0900"
  # ==> "2022-09-20 10:00:00 UTC"
p Fugit.do_parse('0 * * * * Asia/Tokyo').next_time(t0).to_s
p Fugit.do_parse('0 * * * * Asia/Tokyo').next_time(t0).utc.to_s
  # ==> "2022-09-20 19:00:00 +0900"
  # ==> "2022-09-20 10:00:00 UTC"


#> Fugit.do_parse("0 */1 * * * Asia/Tokyo").next_time.to_s
#=> "2022-09-20 10:00:00 +0000"

p Fugit.do_parse('0 */1 * * *').next_time(t0).to_s
p Fugit.do_parse('0 */1 * * *').next_time(t0).utc.to_s
  # ==> "2022-09-20 19:00:00 +0900"
  # ==> "2022-09-20 10:00:00 UTC"
p Fugit.do_parse('0 */1 * * * Asia/Tokyo').next_time(t0).to_s
p Fugit.do_parse('0 */1 * * * Asia/Tokyo').next_time(t0).utc.to_s
  # ==> "2022-09-20 19:00:00 +0900"
  # ==> "2022-09-20 10:00:00 UTC"


#> Fugit.do_parse("0 0/1 * * * Asia/Tokyo").next_time.to_s
#=> "2022-09-20 15:00:00 +0000"

p Fugit.do_parse('0 0/1 * * *').next_time(t0).to_s
p Fugit.do_parse('0 0/1 * * *').next_time(t0).utc.to_s
  # ==> "2022-09-21 00:00:00 +0900"
  # ==> "2022-09-20 15:00:00 UTC"
p Fugit.do_parse('0 0/1 * * * Asia/Tokyo').next_time(t0).to_s
p Fugit.do_parse('0 0/1 * * * Asia/Tokyo').next_time(t0).utc.to_s
  # ==> "2022-09-21 00:00:00 +0900"
  # ==> "2022-09-20 15:00:00 UTC"

However when combined with a timezone, it seems like they aren't equivalent anymore, at least for Fugit:

How so? In the two batch of tests I ran above, fugit gives equivalent results with and without a timezone given in the cron string.

from fugit.

jmettraux avatar jmettraux commented on July 24, 2024

this is probably what you are trying to hint at, I see the problem, but it is not linked to the timezone.

require 'fugit'

p Fugit.do_parse('0 * * * *').hours            # ==> nil
p Fugit.do_parse('0 * * * * Asia/Tokyo').hours # ==> nil
p Fugit.do_parse('0 /1 * * *').hours            # ==> nil
p Fugit.do_parse('0 /1 * * * Asia/Tokyo').hours # ==> nil
p Fugit.do_parse('0 0/1 * * *').hours            # ==> [ 0 ]
p Fugit.do_parse('0 0/1 * * * Asia/Tokyo').hours # ==> [ 0 ]

# nil indicates that the cron should trigger at every hour
# [ 0 ] indicates that the cron should trigger at hour 0

from fugit.

JosephHalter avatar JosephHalter commented on July 24, 2024

I see the problem, but it is not linked to the timezone [...]

You're correct indeed. Thank you for the very quick fix, I'll update the gem to the new version as soon as you release it 👍

from fugit.

jmettraux avatar jmettraux commented on July 24, 2024

Just released fugit 1.7.1 https://rubygems.org/gems/fugit/versions/1.7.1

Thanks a lot!

from fugit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.