floraison / fugit

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

Parse Nat support for 1st and last of the month #88

Closed delbetu closed 9 months ago

delbetu commented 9 months ago

@floraison We need to support this pattern in our project: every month on the 1st and last. It seems it should work but when executing the sort here:

         .collect { |e| e.uniq.sort.collect(&:to_s).join(',') }

It was throwing: `sort': comparison of String with 1 failed (ArgumentError)

It was doing something like this:

["L", 1].sort
(irb):1:in `sort': comparison of String with 1 failed (ArgumentError)

This PR substitutes sort with sort_by to conditionally handle non numeric values.

jmettraux commented 9 months ago

@delbetu Thanks for the patch!

You don't mind if I go with

letters_last = ->(x) { x.is_a?(Numeric) ? x : 9_999 }

?

I'd like the L to go last.

Thanks again!

delbetu commented 9 months ago

@delbetu Thanks for the patch!

You don't mind if I go with

letters_last = ->(x) { x.is_a?(Numeric) ? x : 9_999 }

?

I'd like the L to go last.

Thanks again!

@jmettraux sure! that is even better