Skip to content

Commit

Permalink
use Range.new/3 explicitly passing the step of -1
Browse files Browse the repository at this point in the history
  • Loading branch information
k-asm committed Dec 11, 2024
1 parent 17806a9 commit 0dbb2d5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/parse/datetime/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/duration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/shift_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}])
Expand Down

0 comments on commit 0dbb2d5

Please sign in to comment.