Conversation
whatyouhide
left a comment
There was a problem hiding this comment.
Fantastic start. Left some small comments 🙃
lib/stream_data.ex
Outdated
| @doc """ | ||
| Generates arbitrary (past and future) dates. | ||
|
|
||
| Generated values shrink towards `Date.utc_today/0`. | ||
| """ | ||
| @spec date() :: t(Date.t()) | ||
| def date do | ||
| date([]) | ||
| end |
There was a problem hiding this comment.
Can we remove this in favor of [] options in the other clause? That way for example we can say :origin defaults to Date.utc_today/0.
There was a problem hiding this comment.
Good point. I've updated the PR.
lib/stream_data.ex
Outdated
|
|
||
| ## Options | ||
|
|
||
| * `:origin` - (`Date`) if present, generated values will shrink towards this date. Cannot be combined with `:min` or `:max`. |
There was a problem hiding this comment.
Let's replace types with links, here it would be:
| * `:origin` - (`Date`) if present, generated values will shrink towards this date. Cannot be combined with `:min` or `:max`. | |
| * `:origin` - (`t:Date.t/0`) if present, generated values will shrink towards this date. Cannot be combined with `:min` or `:max`. |
lib/stream_data.ex
Outdated
|
|
||
| Values will shrink towards `date_range.first`. | ||
|
|
||
| ## Calendar support |
There was a problem hiding this comment.
| ## Calendar support | |
| ## Calendar Support |
lib/stream_data.ex
Outdated
| StreamData.integer(0..diff) |> StreamData.map(&Date.add(min, &1)) | ||
|
|
||
| _ -> | ||
| raise ArgumentError, "invalid arguments" |
There was a problem hiding this comment.
I meant in the error message 🙃
There was a problem hiding this comment.
I thought for sure I had done that. Sorry for the inconvenience, it should be updated now.
lib/stream_data.ex
Outdated
|
|
||
| {min = %Date{}, max = %Date{}, nil} -> | ||
| if Date.before?(max, min) do | ||
| raise ArgumentError, "max must not be before min" |
There was a problem hiding this comment.
Let's show the given options.
| raise ArgumentError, "max must not be before min" | |
| raise ArgumentError, """ | |
| expected :max to be after or equal to :min, got: | |
| * min: #{inspect(min)} | |
| * max: #{inspect(max)} | |
| """ |
There was a problem hiding this comment.
Great suggestion.
1f74ec7 to
7000142
Compare
|
Great suggestions all. I have updated the PR. |
lib/stream_data.ex
Outdated
| StreamData.integer(0..diff) |> StreamData.map(&Date.add(min, &1)) | ||
|
|
||
| _ -> | ||
| raise ArgumentError, "invalid arguments" |
There was a problem hiding this comment.
I meant in the error message 🙃
This is a reimplementation of the date generators by @Qqwy in whatyouhide#161. As such, it is a (partial) implementation for whatyouhide#129. The tests and documentation are entirely copy-pasted from his PR, but the actual implementation is entirely new. As noted by @whatyouhide in a comment to the original PR, I've opted to use the new `Date.add` function for most of the cases. I think the resulting implementation is a bit easier to follow. I have not added Time, DateTime or NaiveDateTime, though I think we could probably do something for those that follow this skeleton. Co-authored-by: Qqwy / Marten <w-m@wmcode.nl> Co-authored-by: Andrea Leopardi <an.leopardi@gmail.com>
ebb9549 to
432d0b5
Compare
Pull Request Test Coverage Report for Build 432d0b5f93da6aa321bfe87ed72583e56be123ca-PR-218Details
💛 - Coveralls |
|
Thank you @Munksgaard 🫶 |
This is a reimplementation of the date generators by @Qqwy in #161. As such, it is a (partial) implementation for #129.
The tests and documentation are entirely copy-pasted from his PR, but the actual implementation is entirely new. As noted by @whatyouhide in a comment to the original PR, I've opted to use the new
Date.addfunction for most of the cases.I think the resulting implementation is a bit easier to follow. I have not added Time, DateTime or NaiveDateTime, though I think we could probably do something for those that follow this skeleton.