faker-ruby/faker · error · ArgumentError
Day of week cannot be empty
Error message
Day of week cannot be empty
What it means
Error "Day of week cannot be empty" thrown in faker-ruby/faker.
Source
Thrown at lib/faker/default/date.rb:158
##
# Produce a random date at given day(s) of the week between two dates.
#
# @param day [Symbol, Array<Symbol>] # The day(s) of the week. See {DAYS_OF_WEEK}.
# @param from [Date, String] The start of the usable date range.
# @param to [Date, String] The end of the usable date range.
# @return [Date]
#
# @example if used with or without Rails (Active Support)
# Faker::Date.on_day_of_week_between(day: :tuesday, from: '2023-01-01', to: '2023-02-01') #=> #<Date: 2032-01-10>
#
# @example if used with Rails (Active Support)
# Faker::Date.on_day_of_week_between(day: [:saturday, :sunday], from: 1.month.ago, to: Date.today) #=> #<Date: 2014-09-24>
#
# @faker.version next
def on_day_of_week_between(day:, from:, to:)
days = [day].flatten
raise ArgumentError, 'Day of week cannot be empty' if days.empty?
# Convert given days of the week to numbers used by `Date#wday` method
numeric_weekdays = days.map do |d|
DAYS_OF_WEEK.index(d.to_sym.downcase) || raise(ArgumentError, "#{d} is not a valid day of the week")
end
from = get_date_object(from)
to = get_date_object(to)
date = Faker::Base.rand_in_range(from, to)
# If the initial date is not on one of the wanted days of the week...
unless numeric_weekdays.include? date.wday
# ...pick a date nearby that is on one of the wanted days of the week instead
date += sample(numeric_weekdays) - date.wday
# Move date 1 week earlier or later if the adjusted date is now outside the date range
date += 7 if date < from
date -= 7 if date > toView on GitHub (pinned to cca4184947)
When it happens
Trigger: Thrown at lib/faker/default/date.rb:158 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21).
Data as JSON: /api/errors/e4b895b8e4abd7ce.
Report an issue: GitHub.