From c294711f094c941a9b61a473162cee35b9f01c74 Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Mon, 20 Dec 2021 20:17:31 +0100 Subject: [PATCH 1/9] WIP date generator. --- lib/stream_data.ex | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index e06d125..d62dbc8 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -1883,6 +1883,31 @@ defmodule StreamData do end) end + def date(options \\ [min: nil, max: nil, origin: Date.utc_today(), calendar: Calendar.ISO]) do + case {options[:min], options[:max]} do + {nil, nil} -> + # TODO any date + any_date(options[:origin], options[:calendar]) + {nil, max = %Date{}} -> + # TODO past dates + :todo + {min = %Date{}, nil} -> + # TODO future dates + :todo + {min = %Date{}, max = %Date{}} -> + # TODO between two dates + :todo + end + end + + defp any_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do + {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + StreamData.map(integer(), fn offset -> + {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + Date.new!(year, month, day, calendar) + end) + end + @doc """ Generates iolists. From 21f6ef75977c79185e46b3b38575722b3459b3fb Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Mon, 20 Dec 2021 21:09:51 +0100 Subject: [PATCH 2/9] Documentation for the date generator. --- lib/stream_data.ex | 90 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index d62dbc8..e38ad90 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -1883,20 +1883,66 @@ defmodule StreamData do end) end - def date(options \\ [min: nil, max: nil, origin: Date.utc_today(), calendar: Calendar.ISO]) do - case {options[:min], options[:max]} do + @doc """ + Generates arbitrary (past and future) dates. + + Generated values shrink towards `Date.utc_today/0`. + """ + def date do + date([]) + end + + @doc """ + NOTE still under construction + Generates dates according to the given `options` or `date_range`. + + When given a `Date.Range`, (c.f. `Date.range/2`), will generate dates in the given range. + Values will shrink towards `date_range.first`. + + Alternatively, a keyword list of options can be passed in: + + ## Options + + * `:origin` - (`Date`) if present, generated values will shrink towards this date. Cannot be combined with `:min` or `:max`. + + * `:min` - (`Date`) if present, only dates _after_ this date will be generated. Values will shrink towards this date. + + * `:max` - (`Date`) if present, only dates _before_ this date will be generated. Values will shrink towards this date. + + If both `:min` and `:max` are provided, dates between the two mentioned dates will be generated. + They will shrink towards `:min`. + + If no options are provided, will work just like `StreamData.date/0`. + + ## Calendar support + + This generator works with `Calendar.ISO` and any other calendar + which implements the `c:naive_datetime_to_iso_days/7` + and `c:naive_datetime_from_iso_days/2` callbacks. + """ + @spec date(Date.Range.t() | keyword()) :: t(Date.t()) + def date(options_or_date_range \\ []) + def date(date_range = %Date.Range{}) do + # TODO step + date_between_bounds(date_range.first, date_range.last, date_range.first.calendar) + end + def date(options) when is_list(options) do + min = Access.get(options, :min, nil) + max = Access.get(options, :max, nil) + origin = Access.get(options, :origin, Date.utc_today()) + case {min, max} do {nil, nil} -> # TODO any date - any_date(options[:origin], options[:calendar]) + any_date(origin, origin.calendar) {nil, max = %Date{}} -> - # TODO past dates - :todo + past_date(max, max.calendar) {min = %Date{}, nil} -> - # TODO future dates - :todo + future_date(min, min.calendar) {min = %Date{}, max = %Date{}} -> - # TODO between two dates - :todo + if min.calendar != max.calendar do + raise ArgumentError, "Two dates with incompatible calendars were passed to `StreamData.date/1`" + end + date_between_bounds(min, max, min.calendar) end end @@ -1908,6 +1954,32 @@ defmodule StreamData do end) end + defp past_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do + {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + StreamData.map(positive_integer(), fn offset -> + {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days - offset, day_fraction}) + Date.new!(year, month, day, calendar) + end) + end + + defp future_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do + {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + StreamData.map(positive_integer(), fn offset -> + {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + Date.new!(year, month, day, calendar) + end) + end + + defp date_between_bounds(min, max, calendar \\ Calendar.ISO) do + {min_iso_days, min_day_fraction} = calendar.naive_datetime_to_iso_days(min.year, min.month, min.day, 0, 0, 0, {0, 0}) + {max_iso_days, _max_day_fraction} = calendar.naive_datetime_to_iso_days(max.year, max.month, max.day, 0, 0, 0, {0, 0}) + + StreamData.map(StreamData.integer(min_iso_days..max_iso_days), fn iso_days -> + {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days, min_day_fraction}) + Date.new!(year, month, day, calendar) + end) + end + @doc """ Generates iolists. From ca6a213f62f5e3ecf44e540d23788a760453f4d3 Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Mon, 20 Dec 2021 21:14:44 +0100 Subject: [PATCH 3/9] running mix format --- lib/stream_data.ex | 48 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index e38ad90..498c775 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -1922,60 +1922,84 @@ defmodule StreamData do """ @spec date(Date.Range.t() | keyword()) :: t(Date.t()) def date(options_or_date_range \\ []) + def date(date_range = %Date.Range{}) do - # TODO step - date_between_bounds(date_range.first, date_range.last, date_range.first.calendar) + member_of(date_range) end + def date(options) when is_list(options) do min = Access.get(options, :min, nil) max = Access.get(options, :max, nil) origin = Access.get(options, :origin, Date.utc_today()) + case {min, max} do {nil, nil} -> # TODO any date any_date(origin, origin.calendar) + {nil, max = %Date{}} -> past_date(max, max.calendar) + {min = %Date{}, nil} -> future_date(min, min.calendar) + {min = %Date{}, max = %Date{}} -> if min.calendar != max.calendar do - raise ArgumentError, "Two dates with incompatible calendars were passed to `StreamData.date/1`" + raise ArgumentError, + "Two dates with incompatible calendars were passed to `StreamData.date/1`" end + date_between_bounds(min, max, min.calendar) end end defp any_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do - {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + {iso_days, day_fraction} = + calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + StreamData.map(integer(), fn offset -> - {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + {year, month, day, _hour, _minute, _second, _second_fraction} = + calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + Date.new!(year, month, day, calendar) end) end defp past_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do - {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + {iso_days, day_fraction} = + calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + StreamData.map(positive_integer(), fn offset -> - {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days - offset, day_fraction}) + {year, month, day, _hour, _minute, _second, _second_fraction} = + calendar.naive_datetime_from_iso_days({iso_days - offset, day_fraction}) + Date.new!(year, month, day, calendar) end) end defp future_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do - {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + {iso_days, day_fraction} = + calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + StreamData.map(positive_integer(), fn offset -> - {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + {year, month, day, _hour, _minute, _second, _second_fraction} = + calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + Date.new!(year, month, day, calendar) end) end defp date_between_bounds(min, max, calendar \\ Calendar.ISO) do - {min_iso_days, min_day_fraction} = calendar.naive_datetime_to_iso_days(min.year, min.month, min.day, 0, 0, 0, {0, 0}) - {max_iso_days, _max_day_fraction} = calendar.naive_datetime_to_iso_days(max.year, max.month, max.day, 0, 0, 0, {0, 0}) + {min_iso_days, min_day_fraction} = + calendar.naive_datetime_to_iso_days(min.year, min.month, min.day, 0, 0, 0, {0, 0}) + + {max_iso_days, _max_day_fraction} = + calendar.naive_datetime_to_iso_days(max.year, max.month, max.day, 0, 0, 0, {0, 0}) StreamData.map(StreamData.integer(min_iso_days..max_iso_days), fn iso_days -> - {year, month, day, _hour, _minute, _second, _second_fraction} = calendar.naive_datetime_from_iso_days({iso_days, min_day_fraction}) + {year, month, day, _hour, _minute, _second, _second_fraction} = + calendar.naive_datetime_from_iso_days({iso_days, min_day_fraction}) + Date.new!(year, month, day, calendar) end) end From 259c0b4852936aae429f9ab751c8931caaf2fb76 Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Thu, 30 Dec 2021 21:18:01 +0100 Subject: [PATCH 4/9] Remove optional parameters of private functions (which were used for easier development) --- lib/stream_data.ex | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index 366a425..05c1caa 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -1925,14 +1925,8 @@ defmodule StreamData do end @doc """ - NOTE still under construction Generates dates according to the given `options` or `date_range`. - When given a `Date.Range`, (c.f. `Date.range/2`), will generate dates in the given range. - Values will shrink towards `date_range.first`. - - Alternatively, a keyword list of options can be passed in: - ## Options * `:origin` - (`Date`) if present, generated values will shrink towards this date. Cannot be combined with `:min` or `:max`. @@ -1946,14 +1940,19 @@ defmodule StreamData do If no options are provided, will work just like `StreamData.date/0`. + ## Date.Range + + Alternatively, when given a `Date.Range`, (c.f. `Date.range/2`), will generate dates in the given range. + Values will shrink towards `date_range.first`. + ## Calendar support This generator works with `Calendar.ISO` and any other calendar - which implements the `c:naive_datetime_to_iso_days/7` - and `c:naive_datetime_from_iso_days/2` callbacks. + which implements the callbacks + `c:naive_datetime_to_iso_days/7` and `c:naive_datetime_from_iso_days/2`. """ @spec date(Date.Range.t() | keyword()) :: t(Date.t()) - def date(options_or_date_range \\ []) + def date(options_or_date_range) def date(date_range = %Date.Range{}) do member_of(date_range) @@ -1985,7 +1984,7 @@ defmodule StreamData do end end - defp any_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do + defp any_date(origin, calendar) do {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) @@ -1997,7 +1996,7 @@ defmodule StreamData do end) end - defp past_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do + defp past_date(origin, calendar) do {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) @@ -2009,7 +2008,7 @@ defmodule StreamData do end) end - defp future_date(origin \\ Date.utc_today(), calendar \\ Calendar.ISO) do + defp future_date(origin, calendar) do {iso_days, day_fraction} = calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) @@ -2021,7 +2020,7 @@ defmodule StreamData do end) end - defp date_between_bounds(min, max, calendar \\ Calendar.ISO) do + defp date_between_bounds(min, max, calendar) do {min_iso_days, min_day_fraction} = calendar.naive_datetime_to_iso_days(min.year, min.month, min.day, 0, 0, 0, {0, 0}) From 53c3fe65daaf10826356835690683c7a286665b5 Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Thu, 30 Dec 2021 21:33:59 +0100 Subject: [PATCH 5/9] Extracting common functionality from the Date generator's internal helper functions --- lib/stream_data.ex | 61 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index 05c1caa..9cea155 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -533,6 +533,7 @@ defmodule StreamData do require Integer lower_stepless = Integer.floor_div(left, step) upper_stepless = Integer.floor_div(right, step) + if lower_stepless > upper_stepless do raise "cannot generate elements from an empty range" end @@ -1942,7 +1943,9 @@ defmodule StreamData do ## Date.Range - Alternatively, when given a `Date.Range`, (c.f. `Date.range/2`), will generate dates in the given range. + Alternatively a `Date.Range` can be given. This will generate dates in the given range, + and with the supplied `date_range.step`. + Values will shrink towards `date_range.first`. ## Calendar support @@ -1965,7 +1968,6 @@ defmodule StreamData do case {min, max} do {nil, nil} -> - # TODO any date any_date(origin, origin.calendar) {nil, max = %Date{}} -> @@ -1985,54 +1987,49 @@ defmodule StreamData do end defp any_date(origin, calendar) do - {iso_days, day_fraction} = - calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) - - StreamData.map(integer(), fn offset -> - {year, month, day, _hour, _minute, _second, _second_fraction} = - calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + {iso_days, day_fraction} = extract_date(origin, calendar) - Date.new!(year, month, day, calendar) + map(integer(), fn offset -> + construct_date!(iso_days + offset, day_fraction, calendar) end) end defp past_date(origin, calendar) do - {iso_days, day_fraction} = - calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) + {iso_days, day_fraction} = extract_date(origin, calendar) - StreamData.map(positive_integer(), fn offset -> - {year, month, day, _hour, _minute, _second, _second_fraction} = - calendar.naive_datetime_from_iso_days({iso_days - offset, day_fraction}) - - Date.new!(year, month, day, calendar) + map(positive_integer(), fn offset -> + construct_date!(iso_days - offset, day_fraction, calendar) end) end defp future_date(origin, calendar) do - {iso_days, day_fraction} = - calendar.naive_datetime_to_iso_days(origin.year, origin.month, origin.day, 0, 0, 0, {0, 0}) - - StreamData.map(positive_integer(), fn offset -> - {year, month, day, _hour, _minute, _second, _second_fraction} = - calendar.naive_datetime_from_iso_days({iso_days + offset, day_fraction}) + {iso_days, day_fraction} = extract_date(origin, calendar) - Date.new!(year, month, day, calendar) + map(positive_integer(), fn offset -> + construct_date!(iso_days + offset, day_fraction, calendar) end) end defp date_between_bounds(min, max, calendar) do - {min_iso_days, min_day_fraction} = - calendar.naive_datetime_to_iso_days(min.year, min.month, min.day, 0, 0, 0, {0, 0}) + {min_iso_days, min_day_fraction} = extract_date(min, calendar) + {max_iso_days, _max_day_fraction} = extract_date(max, calendar) - {max_iso_days, _max_day_fraction} = - calendar.naive_datetime_to_iso_days(max.year, max.month, max.day, 0, 0, 0, {0, 0}) + map(integer(min_iso_days..max_iso_days), fn iso_days -> + construct_date!(iso_days, min_day_fraction, calendar) + end) + end - StreamData.map(StreamData.integer(min_iso_days..max_iso_days), fn iso_days -> - {year, month, day, _hour, _minute, _second, _second_fraction} = - calendar.naive_datetime_from_iso_days({iso_days, min_day_fraction}) + @compile {:inline, extract_date: 2} + defp extract_date(date, calendar) do + calendar.naive_datetime_to_iso_days(date.year, date.month, date.day, 0, 0, 0, {0, 0}) + end - Date.new!(year, month, day, calendar) - end) + @compile {:inline, construct_date!: 3} + defp construct_date!(iso_days, day_fraction, calendar) do + {year, month, day, _hour, _minute, _second, _second_fraction} = + calendar.naive_datetime_from_iso_days({iso_days, day_fraction}) + + Date.new!(year, month, day, calendar) end @doc """ From 8aca3908ba89dbab1dbdaed4b5d9f00b8e94284b Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Thu, 30 Dec 2021 21:34:55 +0100 Subject: [PATCH 6/9] Use clearer wording in error message for Date generators, and clean up code slightly --- lib/stream_data.ex | 10 ++++----- test/stream_data_test.exs | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index 9cea155..7ad8144 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -1937,7 +1937,7 @@ defmodule StreamData do * `:max` - (`Date`) if present, only dates _before_ this date will be generated. Values will shrink towards this date. If both `:min` and `:max` are provided, dates between the two mentioned dates will be generated. - They will shrink towards `:min`. + Values will shrink towards `:min`. If no options are provided, will work just like `StreamData.date/0`. @@ -1962,9 +1962,9 @@ defmodule StreamData do end def date(options) when is_list(options) do - min = Access.get(options, :min, nil) - max = Access.get(options, :max, nil) - origin = Access.get(options, :origin, Date.utc_today()) + min = Keyword.get(options, :min, nil) + max = Keyword.get(options, :max, nil) + origin = Keyword.get(options, :origin, Date.utc_today()) case {min, max} do {nil, nil} -> @@ -1979,7 +1979,7 @@ defmodule StreamData do {min = %Date{}, max = %Date{}} -> if min.calendar != max.calendar do raise ArgumentError, - "Two dates with incompatible calendars were passed to `StreamData.date/1`" + "Two dates with different calendars were passed to `StreamData.date/1`" end date_between_bounds(min, max, min.calendar) diff --git a/test/stream_data_test.exs b/test/stream_data_test.exs index 8ebde83..dba5616 100644 --- a/test/stream_data_test.exs +++ b/test/stream_data_test.exs @@ -323,6 +323,53 @@ defmodule StreamDataTest do end end + describe "date/0" do + property "generates any dates" do + check all date <- date() do + assert %Date{} = date + end + end + end + + describe "date/1" do + property "without options, generates any dates" do + check all date <- date([]) do + assert %Date{} = date + end + end + + property "with a :min option, generates dates after it" do + check all minimum <- date(), + date <- date(min: minimum) do + assert Date.compare(date, minimum) in [:eq, :gt] + end + end + + property "with a :max option, generates dates before it" do + check all maximum <- date(), + date <- date(max: maximum) do + assert Date.compare(date, maximum) in [:lt, :eq] + end + end + + property "with both a :min and a :max option, generates dates in-between the bounds" do + check all minimum <- date(), + maximum <- date(min: minimum), + date <- date(min: minimum, max: maximum) do + assert Enum.member?(Date.range(minimum, maximum), date) + end + end + + property "with a Date.Range, generates dates in-between the bounds" do + check all minimum <- date(), + maximum <- date(min: minimum), + range = Date.range(minimum, maximum), + date <- date(range) do + assert Enum.member?(range, date) + end + end + end + property "byte/0" do check all value <- byte() do assert value in 0..255 From 8ac84d31416fb8b0055e2f7888b486fce7a80d2c Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Thu, 30 Dec 2021 22:40:16 +0100 Subject: [PATCH 7/9] Remove blank line which has nothing to do with this PR --- lib/stream_data.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index 7ad8144..5df4b0b 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -533,7 +533,6 @@ defmodule StreamData do require Integer lower_stepless = Integer.floor_div(left, step) upper_stepless = Integer.floor_div(right, step) - if lower_stepless > upper_stepless do raise "cannot generate elements from an empty range" end From 311f3cbfd33541529d95e14081a9f7f01162d1d3 Mon Sep 17 00:00:00 2001 From: Marten/Qqwy Date: Thu, 30 Dec 2021 22:40:57 +0100 Subject: [PATCH 8/9] mix format --- lib/stream_data.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index 5df4b0b..7ad8144 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -533,6 +533,7 @@ defmodule StreamData do require Integer lower_stepless = Integer.floor_div(left, step) upper_stepless = Integer.floor_div(right, step) + if lower_stepless > upper_stepless do raise "cannot generate elements from an empty range" end From 017c5b00ce01225b1eeecafe644973bc42d99fa7 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 18 Jan 2022 18:52:15 +0100 Subject: [PATCH 9/9] Apply suggestions from code review --- lib/stream_data.ex | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/stream_data.ex b/lib/stream_data.ex index 7ad8144..3e2a12b 100644 --- a/lib/stream_data.ex +++ b/lib/stream_data.ex @@ -1921,6 +1921,7 @@ defmodule StreamData do Generated values shrink towards `Date.utc_today/0`. """ + @spec date() :: t(Date.t()) def date do date([]) end @@ -1939,9 +1940,9 @@ defmodule StreamData do If both `:min` and `:max` are provided, dates between the two mentioned dates will be generated. Values will shrink towards `:min`. - If no options are provided, will work just like `StreamData.date/0`. + If no options are provided, will work just like `date/0`. - ## Date.Range + ## `Date.Range` Alternatively a `Date.Range` can be given. This will generate dates in the given range, and with the supplied `date_range.step`. @@ -1952,7 +1953,7 @@ defmodule StreamData do This generator works with `Calendar.ISO` and any other calendar which implements the callbacks - `c:naive_datetime_to_iso_days/7` and `c:naive_datetime_from_iso_days/2`. + `c:Calendar.naive_datetime_to_iso_days/7` and `c:Calendar.naive_datetime_from_iso_days/2`. """ @spec date(Date.Range.t() | keyword()) :: t(Date.t()) def date(options_or_date_range) @@ -1979,7 +1980,7 @@ defmodule StreamData do {min = %Date{}, max = %Date{}} -> if min.calendar != max.calendar do raise ArgumentError, - "Two dates with different calendars were passed to `StreamData.date/1`" + "dates with different calendars were passed to StreamData.date/1" end date_between_bounds(min, max, min.calendar)