bitwalker / timex

A complete date/time library for Elixir projects.
https://hexdocs.pm/timex
MIT License
1.75k stars 374 forks source link

feat: Add :cycled option to Timex.between?/4 for Time.t ranges that pass through midnight #726

Closed jrogov closed 1 year ago

jrogov commented 1 year ago

Summary of changes

Timex.between/4? is super helpful function, but it falls flat on comparisons for periodic events (think cron-like daily scheduling) that use Time.t to set up boundaries of such period.

I.e. check like 23:00 <= 01:00 <= 03:00 would return false, which is fine for default behaviour, but requires extra code for usecases like above.

This PR introduces function's option cycled: true that takes into account if start and end are on different sides of midnight and makes above comparisons possible with a single function call.

With default options (cycled: false), this change is backward compatible.

Checklist