floraison / fugit

time tools (cron, parsing, durations, ...) for Ruby, rufus-scheduler, and flor
MIT License
355 stars 29 forks source link

Support for timezone offsets #9

Closed Tolsto closed 5 years ago

Tolsto commented 5 years ago

Do you plan to support timezone offsets in the future? Currently, the following examples do not work:

Fugit::Cron.parse("29 9 16 * * UTC/+11")
Fugit::Cron.parse("29 9 16 * * Etc/GMT-11")
jmettraux commented 5 years ago

Hello,

thanks for pointing that out.

require 'tzinfo'

p begin ::TZInfo::Timezone.get('+11') rescue nil; end         # ==> nil
p begin ::TZInfo::Timezone.get('+1100') rescue nil; end       # ==> nil
p begin ::TZInfo::Timezone.get('UTC/+11') rescue nil; end     # ==> nil
p begin ::TZInfo::Timezone.get('Etc/GMT-11') rescue nil; end  # ==> #<TZInfo::DataTimezone: Etc/GMT-11>

require 'fugit'

p Fugit::VERSION  # ==> '1.1.5'

p Fugit::Cron.parse('29 9 16 * * +11')         # ==> nil
p Fugit::Cron.parse('29 9 16 * * +1100')       # ==> #<Fugit::Cron:...>
p Fugit::Cron.parse('29 9 16 * * UTC/+11')     # ==> nil
p Fugit::Cron.parse('29 9 16 * * Etc/GMT-11')  # ==> nil

I can't find UTC/+11 in the list of tz database time zones and TZInfo doesn't know about it. If you have a need for it, please tell me. (By the way are you on Windows?)

That leaves me Etc/GMT-11 to enable.

jmettraux commented 5 years ago

Hello @Tolsto,

please tell me if the changes I made fix the issue for you.

If you really need UTC/+11, please tell me why you need it.

Thanks in advance.

Tolsto commented 5 years ago

Thanks for the fast reply @jmettraux You are right, UTC/+11 doesn't exist. Sorry for the bad example. I'm not on Windows but Linux. Your new code works for me. However, only for negative offsets. Something like Etc/GMT+5 still doesn't work.

jmettraux commented 5 years ago

Hello @Tolsto,

my bad. The above commit should solve that.

Thanks for the rapid feedback you gave me.

Tolsto commented 5 years ago

Thank you, I can confirm that it works now. Do you already know when you'll publish the next release that will include this?

jmettraux commented 5 years ago

You're welcome.

I'm thinking about releasing tomorrow, along with an et-orbi accommodation for the same Etc/GMT+11 and friends. I hope that matches your schedule.

Tolsto commented 5 years ago

:+1:

jmettraux commented 5 years ago

Fugit 1.1.6 is out.

Thanks again!