rossta / montrose

Recurring events library for Ruby. Enumerable recurrence objects and convenient chainable interface.
https://rossta.net/montrose/
MIT License
842 stars 52 forks source link

Normalize Representations #131

Closed juni0r closed 3 years ago

juni0r commented 3 years ago

The use of convenience parameters such as :between leads to ambiguous representations and breaks chaining. Consider the following case:

r0 = Montrose.daily(at: '8:00', between: Time.parse('2020-10-12')..Time.parse('2020-10-15'))

r1 = r0.starts(Time.parse('2020-10-08'))

r0.take(1)
#=> [2020-10-12 08:00:00 +0200]

r1.take(1)
#=> [2020-10-12 08:00:00 +0200]

This is apparently because the internal representation (and serialization) of r1 looks like this:

{
  :every => :day,
  :starts => 2020-10-08 00:00:00 +0200,
  :until => 2020-10-15 00:00:00 +0200, 
  :between => 2020-10-12 00:00:00 +0200..2020-10-15 00:00:00 +0200,
  :at=>[[8, 0, 0]]
}

Changing :starts does not affect the value of :between which was used to build r0, hence the internal representation of the object becomes ambiguous.

A solution would be to normalize the representation and not to store convenience parameters such as :between but only the derived parameters (in this case :starts and :until).

rossta commented 3 years ago

Thanks for the report. This issue should be addressed in the next release.