Skip to content

Conversation

@ericmooney-at-angel
Copy link

@ericmooney-at-angel ericmooney-at-angel commented Feb 18, 2025

Summary of changes

With recent versions of Elixir, a runtime warning comes up when using first..last notation when first is greater than last.
Example:

warning: Range.new/2 and first..last default to a step of -1 when last < first. Use Range.new(first, last, -1) or first..last//-1, or pass 1 if that was your intention
  (tzdata 1.1.2) lib/tzdata/util.ex:99: Tzdata.Util.first_weekday_of_month_at_most/4
  (tzdata 1.1.2) lib/tzdata/period_builder.ex:356: anonymous fn/2 in Tzdata.PeriodBuilder.sort_rules_by_time/2
  (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
  (tzdata 1.1.2) lib/tzdata/period_builder.ex:356: Tzdata.PeriodBuilder.sort_rules_by_time/2
  (tzdata 1.1.2) lib/tzdata/period_builder.ex:228: Tzdata.PeriodBuilder.calc_rule_periods/8

This change simply uses the explicit Range.new/3 operator specifying -1 for the step.

Related doc:
https://hexdocs.pm/elixir/1.15.0/Range.html#new/2

Because of the simplicity and small size of this change, I thought it appropriate to merge into @nathany-copia 's excellent ongoing work to bring Timex up to date.

@ericmooney-at-angel
Copy link
Author

Ah, please disregard, missed that this was already in this branch w/ the //-1 notation.

@nathany-copia
Copy link
Member

Yup, see bitwalker#772

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants