Closed gee-forr closed 3 years ago
Many thanks for this gem, it truly is wonderful.
Thanks, maybe it deserves a star.
Hello,
thanks for the feature request.
It turns out that parsing every monday to friday 8am and 5pm will correctly parse the day range supplied
require 'fugit'
p Fugit::Nat.parse('every monday to friday 8am and 5pm')
# ==>
# #<Fugit::Cron:0x00000d59c7723430
# @original="0 8,17 * * 1-5", @cron_s=nil,
# @seconds=[0], @minutes=[0], @hours=[8, 17], @monthdays=nil,
# @months=nil, @weekdays=[[1], [2], [3], [4], [5]],
# @zone=nil, @timezone=nil>
This isn't a range, it's a parsed cron expression (potential point in time, not ranges in time).
every monday to friday 8am to 5pm
returns anil
Yes, because it doesn't understand such hour ranges.
I tried with
multi: true
and still get anil
returned.
multi: true
is for cases where outputting a single Fugit::Cron
instance isn't sufficient, for example:
Fugit::Nat.parse('every day at 16:15 and 18:30', multi: true)
# ==> [
# #<Fugit::Cron:0x0000024a34af05e8 @original="15 16 * * *", @cron_s=nil,
# @seconds=[0], @minutes=[15], @hours=[16], @monthdays=nil, @months=nil,
# @weekdays=nil, @zone=nil, @timezone=nil>,
# #<Fugit::Cron:0x0000024a05183b38 @original="30 18 * * *", @cron_s=nil,
# @seconds=[0], @minutes=[30], @hours=[18], @monthdays=nil, @months=nil,
# @weekdays=nil, @zone=nil, @timezone=nil>]
Fugit::Nat.parse('every weekday 8am to 5pm')
I was expecting to get a fugit cron object back that looks a little something like this?
#<Fugit::Cron:0x000055f7859a1ca8 @original="* 8-17 * * 1-5" ...>`
It might not be feasible to include every minute of every hour in the 8am-5pm range, but any help getting a string like this to parse would be very helpful.
That I can do, "* 8-17 * * 1-5"
, monday to friday, every minute from 08:00 to 17:59. I can modify fugit to understand the to
between "8am" and "5pm". But then, maybe, what you really mean is "8am until 5pm"?
There is currently no concept of time ranges in fugit. I am not sure if I have the spare time to add that and then maintain that for the next ten years.
Should "every weekday 8am to 5pm"
sounds neat, but for some people (like you) it should parse to a time range, for others it should parse to "every weekday, 08:00, 09:00, 10:00, ..., 17:00", for others it should parse to " 8-17 * 1-5".
Maybe:
"every weekday 8am to 5pm" => "0 8-17 * * 1-5"
"every weekday 8am to 5pm on the hour" => "0 8-17 * * 1-5"
"every weekday 8am to 5pm on the minute" => "* 8-17 * * 1-5"
"every weekday 8am to 5pm on minute 10 and 30" => "10,30 8-17 * * 1-5"
I'll think about it.
Hi @jmettraux
Sure - totally understand that cron is about points in time, not ranges. Being able to parse every weekday 8am to 5pm
would be perfect.
P.S - I always forget about starring projects I use and admire, thanks for the reminder :)
P.S - I always forget about starring projects I use and admire, thanks for the reminder :)
Thanks a lot! It helps!
@gee-forr
Hello,
what do you think of this piece of spec:
{
'every weekday 8am to 5pm' => '0 8-17 * * 1-5',
'every weekday 8am to 5pm on the hour' => '0 8-17 * * 1-5',
'every weekday 8am to 5pm on the minute' => '* 8-16 * * 1-5',
'every weekday 8am to 5pm on minute 10 and 30' => '10,30 8-16 * * 1-5',
'every hour, 8am to 5pm' => '0 8-17 * * *',
'every hour, from 8am to 5pm' => '0 8-17 * * *',
'every minute, 8am to 5pm' => '* 8-16 * * *',
'every minute from 8am to 5pm' => '* 8-16 * * *',
}
?
Closing.
Issue description
Hello there, I'm wondering if fugit supports natural parsing of both days and weeks? We're looking for a way to define blocks of time where people are or aren't available. Below is a simple example.
How to reproduce
Expected behaviour
I was expecting to get a fugit cron object back that looks a little something like this?
It might not be feasible to include every minute of every hour in the 8am-5pm range, but any help getting a string like this to parse would be very helpful. Many thanks for this gem, it truly is wonderful.
Context
Please replace the content of this section with the output of the following commands:
Additional context
It turns out that parsing
every monday to friday 8am and 5pm
will correctly parse the day range supplied, but change the hours from a list;8am and 5pm
to a range;8am to 5pm
returns a nil.I tried with
multi: true
and still get anil
returned.