Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for Faker::Date with separate examples #2061

Merged
merged 2 commits into from Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions doc/default/date.md
Expand Up @@ -3,11 +3,15 @@
```ruby
# Random date between dates
# Keyword arguments: from, to
Faker::Date.between(from: 2.days.ago, to: Date.today) #=> "Wed, 24 Sep 2014"
Faker::Date.between(from: '2014-09-23', to: '2014-09-25') #=> #<Date: 2014-09-24>
# If used with Rails (the Active Support gem), additional options are available:
Faker::Date.between(from: 2.days.ago, to: Date.today) #=> #<Date: 2014-09-24>

# Random date between dates except for certain date
# Keyword arguments: from, to, excepted
Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today) #=> "Wed, 24 Sep 2014"
Faker::Date.between_except(from: '2014-09-23', to: '2015-09-25', excepted: '2015-01-24') #=> #<Date: 2014-10-03>
# If used with Rails (the Active Support gem), additional options are available:
Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today) #=> #<Date: 2014-10-03>

# Random date in the future (up to maximum of N days)
# Keyword arguments: days
Expand Down
16 changes: 10 additions & 6 deletions lib/faker/default/date.rb
Expand Up @@ -10,9 +10,11 @@ class << self
# @param to [Date, String] The end of the usable date range.
# @return [Date]
#
# @example
# Faker::Date.between(from: 2.days.ago, to: Date.today)
# #=> #<Date: 2014-09-24>
# @example if used with or without Rails (Active Support)
# Faker::Date.between(from: '2014-09-23', to: '2014-09-25') #=> #<Date: 2014-09-24>
#
# @example if used with Rails (Active Support)
# Faker::Date.between(from: 2.days.ago, to: Date.today) #=> #<Date: 2014-09-24>
#
# @faker.version 1.0.0
def between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from:, to:)
Expand All @@ -37,9 +39,11 @@ def between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, from:, to:)
# @param excepted [Date, String] A date to exclude.
# @return [Date]
#
# @example
# Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today)
# #=> #<Date: 2014-10-03>
# @example if used with or without Rails (Active Support)
# Faker::Date.between_except(from: '2014-09-23', to: '2015-09-25', excepted: '2015-01-24') #=> #<Date: 2014-10-03>
#
# @example if used with Rails (Active Support)
# Faker::Date.between_except(from: 1.year.ago, to: 1.year.from_now, excepted: Date.today) #=> #<Date: 2014-10-03>
#
# @faker.version 1.6.2
def between_except(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_excepted = NOT_GIVEN, from:, to:, excepted:)
Expand Down