Skip to content

Commit

Permalink
Prepare Faker::Time.between deprecation (faker-ruby#1287)
Browse files Browse the repository at this point in the history
* Prepare Faker::Time.between deprecation [1282](faker-ruby#1282)

* Prepare Faker::Time.between deprecation (documentation)

* Prepare Faker::Time.between deprecation (documentation)
  • Loading branch information
microweb10 authored and vbrazo committed Jun 20, 2018
1 parent b9fd393 commit 70d798d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -123,6 +123,8 @@
### Deprecation
- [PR #1264](https://github.com/stympy/faker/pull/1264) Prepare Faker::Name.job_titles and Faker::Name.title for deprecation
- Removing these methods as they are available in `Faker::Job`
- [PR #1287](https://github.com/stympy/faker/pull/1287) Prepare Faker::Time.between for deprecation
- This method will only return Time Objects. For DateTime Objects there will be a new class Faker::DateTime

## [v1.8.7](https://github.com/stympy/faker/tree/v1.8.7) (2017-12-22)
[Full Changelog](https://github.com/stympy/faker/compare/v1.8.6...v1.8.7)
Expand Down
9 changes: 9 additions & 0 deletions doc/time.md
Expand Up @@ -21,4 +21,13 @@ Faker::Time.forward(23, :morning) # => "2014-09-26 06:54:47 -0700"

# Random time in the past (up to maximum of N days)
Faker::Time.backward(14, :evening) #=> "2014-09-17 19:56:33 -0700"

# Option by default is :all, and it will return a DateTime object
# If you want to get a Time object between 2 times you have to specify the option :between
# Random time in the las 3 hours
Faker::Time.between(3.hours.ago, Time.now, :between) #=> "Wed, 20 Jun 2018 10:30:02 UTC +00:00"
```

### NOTE

* Faker.Time.between will be deprecated. After deprecation it will only return Time objects. For DateTime objects there wil be a new class Faker::DateTime
4 changes: 4 additions & 0 deletions lib/faker/time.rb
Expand Up @@ -11,6 +11,8 @@ class Time < Faker::Date
}.freeze

class << self
extend Gem::Deprecate

def between(from, to, period = :all, format = nil)
time = period == :between ? rand(from..to) : date_with_random_time(super(from, to), period)
time_with_format(time, format)
Expand Down Expand Up @@ -46,6 +48,8 @@ def minutes
def seconds
sample((0..59).to_a)
end

deprecate :between, 'Faker::Time.between', 2018, 9
end
end
end

0 comments on commit 70d798d

Please sign in to comment.