Skip to content

Commit

Permalink
Add day_of_week to Time (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvarley authored and marocchino committed Sep 19, 2017
1 parent c3551a7 commit c71e808
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions REFERENCE.md
Expand Up @@ -1919,6 +1919,7 @@
| `date` | 2015-11-08 00:00:00 +0900, 2012-08-27 00:00:00 +0900, 2014-01-31 00:00:00 +0900 |
| `datetime` | 2013-11-21 12:16:00 +0900, 2012-06-21 08:01:00 +0900, 2012-10-15 05:14:00 +0900 |
| `month` | July, August, June |
| `day_of_week` | Mon, Tue, Sat |

## FFaker::Tweet

Expand Down
5 changes: 5 additions & 0 deletions lib/ffaker/time.rb
Expand Up @@ -6,11 +6,16 @@ module Time
extend self

MONTHS = %w(January February March April May June July August September October November December).freeze
DAYS_OF_WEEK = %w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday).freeze

def month
fetch_sample(MONTHS)
end

def day_of_week(options = {})
fetch_sample(DAYS_OF_WEEK)[0..(options[:long] ? 10 : 2)]
end

def date(params = {})
years_back = params[:year_range] || 5
latest_year = params [:year_latest] || 0
Expand Down
10 changes: 9 additions & 1 deletion test/test_time.rb
Expand Up @@ -5,7 +5,7 @@
class TestFakerTime < Test::Unit::TestCase
include DeterministicHelper

assert_methods_are_deterministic(FFaker::Time, :date, :datetime, :month)
assert_methods_are_deterministic(FFaker::Time, :date, :datetime, :month, :day_of_week)

def setup
@tester = FFaker::Time
Expand All @@ -16,6 +16,14 @@ def test_date
assert_match(date_regex, @tester.date)
end

def test_day_of_week
day_of_week_short_regex = /\A(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\z/
day_of_week_long_regex = /\A(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\z/
assert_match(day_of_week_short_regex, @tester.day_of_week)
assert_match(day_of_week_long_regex, @tester.day_of_week(long: true))
assert_deterministic { @tester.day_of_week }
end

def test_date_hours_and_minutes
assert_match('04:20:00', @tester.date(hours: 4, minutes: 20))
assert_deterministic { @tester.date(hours: 4, minutes: 20) }
Expand Down

0 comments on commit c71e808

Please sign in to comment.