Skip to main content

Date_Range.reverse

reverse

Group: Selections

Documentation

Reverses the range, returning a vector with the same elements as the original range, but in the opposite order.

Examples

Reverse a range of dates.

      (Date.new 2020 10 01).up_to (Date.new 2020 10 31) . reverse

Remarks

Returning a Vector

This method cannot return back a Date_Range, as some ranges are not reversible. For example, the range (Date.new 2020 02 29).up_to (Date.new 2023) . with_step Date_Period.Year will have 2022-02-28 as its last entry. But if we create a range starting at 2022-02-28 and going backwards by a year, its last element will be 2020-02-28 and not 2020-02-29 as in the original. Thus, to preserve the contents we need to return a vector.