From 0dbb2d500c81d14c73fe74bf298123d9178a429c Mon Sep 17 00:00:00 2001 From: k-asm Date: Wed, 11 Dec 2024 12:25:00 +0900 Subject: [PATCH] use Range.new/3 explicitly passing the step of -1 --- CHANGELOG.md | 1 + lib/parse/datetime/helpers.ex | 6 +++--- test/duration_test.exs | 2 +- test/shift_test.exs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b0e35f1..e7021e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added `cycled` option for `Timex.between?/4` to support time-range checks that pass through midnight - Add Croatian translation - Changed charlists from the deprecated `''` to `~c""` +- Changed negative range to pass the step of default value for suppressing deprecation warnings ### Fixed diff --git a/lib/parse/datetime/helpers.ex b/lib/parse/datetime/helpers.ex index f481106d..33fed705 100644 --- a/lib/parse/datetime/helpers.ex +++ b/lib/parse/datetime/helpers.ex @@ -159,13 +159,13 @@ defmodule Timex.Parse.DateTime.Helpers do case {padding, min_width, max_width} do {:zeroes, _, nil} -> Text.integer() - {:zeroes, min, max} -> choice(Enum.map(max..min, &fixed_integer(&1))) + {:zeroes, min, max} -> choice(Enum.map(max..min//-1, &fixed_integer(&1))) {:spaces, -1, nil} -> skip(spaces()) |> Text.integer() {:spaces, min, nil} -> skip(spaces()) |> fixed_integer(min) - {:spaces, _, max} -> skip(spaces()) |> choice(Enum.map(max..1, &fixed_integer(&1))) + {:spaces, _, max} -> skip(spaces()) |> choice(Enum.map(max..1//-1, &fixed_integer(&1))) {_, -1, nil} -> Text.integer() {_, min, nil} -> fixed_integer(min) - {_, min, max} -> choice(Enum.map(max..min, &fixed_integer(&1))) + {_, min, max} -> choice(Enum.map(max..min//-1, &fixed_integer(&1))) end end end diff --git a/test/duration_test.exs b/test/duration_test.exs index 7c999bb0..bedb0a2f 100644 --- a/test/duration_test.exs +++ b/test/duration_test.exs @@ -125,7 +125,7 @@ defmodule DurationTests do # Just make sure that Timex.Duration.measure is called at least once in the tests test "measure/1" do - reversed_list = Enum.to_list(100_000..1) + reversed_list = Enum.to_list(100_000..1//-1) assert {%Duration{} = d, ^reversed_list} = Duration.measure(fn -> Enum.reverse(1..100_000) end) diff --git a/test/shift_test.exs b/test/shift_test.exs index f82b0148..aa75637b 100644 --- a/test/shift_test.exs +++ b/test/shift_test.exs @@ -19,7 +19,7 @@ defmodule ShiftTests do property "is always lower than input date for negative shift values" do check all( input_date <- PropertyHelpers.date_time_generator(:struct), - shift <- StreamData.integer(-1..-1000), + shift <- StreamData.integer(-1..-1000//-1), unit <- StreamData.member_of(@units) ) do date = Timex.shift(input_date, [{unit, shift}])