diff --git a/CHANGELOG.md b/CHANGELOG.md index ef1e56ea..3955ee91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,11 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format. ## Unreleased ### Added + - `Faker.Fruits.En` - add english fruits [[@KevinDaSilvaS](https://github.com/KevinDaSilvaS)] ### Changed + - `Faker.Commerce.PtBr` - add more products in product_name_product [[@igorgbr](https://github.com/igorgbr)] - `Faker.Fruits.PtBr` - fix typo in nectarina [[@KevinDaSilvaS](https://github.com/KevinDaSilvaS)] - `Faker.Internet.image_url/0` - switched unresponsive placeholder.it with picsum.photos [[@almirsarajcic](https://github.com/almirsarajcic)] @@ -22,6 +24,8 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format. ### Removed ### Fixed + +- `Faker.date_of_birth` - fix invalid dates due to leap year [[igas](https://github.com/igas)] - `Faker.Currency.code/0` remove duplicates/replace old currencies [[@yassinrais](https://github.com/yassinrais)] - `Faker.Adress.PtBr` - fix model documentation [[@laraujo7](https://github.com/laraujo7)] - `Faker.Address.En/0` corrected formatting for US and Britian [[@atavistock](https://github.com/atavistock)] @@ -31,6 +35,7 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format. ## 0.17.0 ### Added + - `Faker.Internet.StatusCode` [[@emmetreza](https://github.com/emmetreza)] - CI workflow using GitHub Actions [[@anthonator](https://github.com/anthonator)] - `Faker.Cat.PtBr` [[@f-francine](https://github.com/f-francine)] @@ -39,6 +44,7 @@ Change log itself follows [Keep a CHANGELOG](http://keepachangelog.com) format. - `Faker.Commerce.PtBr` [[@f-francine](https://github.com/f-francine)] ### Changed + - `Faker.Vehicles` add makes and models that are multi-word, refactor existing fns [[jersearls](https://github.com/jersearls)] - `Faker.Avatar` switch to `https` to prevent redirect [[igas](https://github.com/igas)] - Updated build badge for GitHub Actions [[@anthonator](https://github.com/anthonator)] diff --git a/lib/faker/date.ex b/lib/faker/date.ex index 775ddd0d..c2a2d453 100644 --- a/lib/faker/date.ex +++ b/lib/faker/date.ex @@ -18,10 +18,10 @@ defmodule Faker.Date do earliest_year = today.year - (age + 1) - {:ok, earliest_date} = Date.new(earliest_year, today.month, today.day) + {:ok, earliest_date} = safe_date(earliest_year, today.month, today.day) earliest_date = Date.add(earliest_date, 1) - {:ok, latest_date} = Date.new(earliest_year + 1, today.month, today.day) + {:ok, latest_date} = safe_date(earliest_year + 1, today.month, today.day) date_range = Date.range(earliest_date, latest_date) @@ -72,4 +72,11 @@ defmodule Faker.Date do |> Faker.DateTime.between(to) |> DateTime.to_date() end + + defp safe_date(year, month, day) do + case Date.new(year, month, day) do + {:ok, date} -> {:ok, date} + {:error, :invalid_date} -> safe_date(year, month, day - 1) + end + end end