# frozen_string_literal: truemoduleFakerclassDate<Baseclass<<self### Produce a random date between two dates.## @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.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.0defbetween(legacy_from=NOT_GIVEN,legacy_to=NOT_GIVEN,from:,to:)warn_for_deprecated_argumentsdo|keywords|keywords<<:fromiflegacy_from!=NOT_GIVENkeywords<<:toiflegacy_to!=NOT_GIVENendfrom=get_date_object(from)to=get_date_object(to)Faker::Base.rand_in_range(from,to)end# rubocop:disable Metrics/ParameterLists### Produce a random date between two dates.## @param from [Date, String] The start of the usable date range.# @param to [Date, String] The end of the usable date range.# @param excepted [Date, String] A date to exclude.# @return [Date]## @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.2defbetween_except(legacy_from=NOT_GIVEN,legacy_to=NOT_GIVEN,legacy_excepted=NOT_GIVEN,from:,to:,excepted:)warn_for_deprecated_argumentsdo|keywords|keywords<<:fromiflegacy_from!=NOT_GIVENendwarn_for_deprecated_argumentsdo|keywords|keywords<<:toiflegacy_to!=NOT_GIVENendwarn_for_deprecated_argumentsdo|keywords|keywords<<:exceptediflegacy_excepted!=NOT_GIVENendraiseArgumentError,'From date, to date and excepted date must not be the same'iffrom==to&&to==exceptedexcepted=get_date_object(excepted)loopdodate=between(from: from,to: to)breakdate.to_dateifdate!=exceptedendend# rubocop:enable Metrics/ParameterLists### Produce a random date in the future (up to N days).## @param days [Integer] The maximum number of days to go into the future.# @return [Date]## @example# Faker::Date.forward(days: 23) #=> #<Date: 2014-10-03>## @faker.version 1.0.0defforward(legacy_days=NOT_GIVEN,days: 365)warn_for_deprecated_argumentsdo|keywords|keywords<<:daysiflegacy_days!=NOT_GIVENendfrom=::Date.today+1to=::Date.today+daysbetween(from: from,to: to).to_dateend### Produce a random date in the past (up to N days).## @param days [Integer] The maximum number of days to go into the past.# @return [Date]## @example# Faker::Date.backward(days: 14) #=> #<Date: 2019-09-12>## @faker.version 1.0.0defbackward(legacy_days=NOT_GIVEN,days: 365)warn_for_deprecated_argumentsdo|keywords|keywords<<:daysiflegacy_days!=NOT_GIVENendfrom=::Date.today-daysto=::Date.today-1between(from: from,to: to).to_dateend### Produce a random date in the past (up to N days).## @param min_age [Integer] The minimum age that the birthday would imply.# @param max_age [Integer] The maximum age that the birthday would imply.# @return [Date]## @example# Faker::Date.birthday(min_age: 18, max_age: 65) #=> #<Date: 1986-03-28>## @faker.version 1.4.3defbirthday(legacy_min_age=NOT_GIVEN,legacy_max_age=NOT_GIVEN,min_age: 18,max_age: 65)warn_for_deprecated_argumentsdo|keywords|keywords<<:min_ageiflegacy_min_age!=NOT_GIVENendwarn_for_deprecated_argumentsdo|keywords|keywords<<:max_ageiflegacy_max_age!=NOT_GIVENendt=::Date.todayfrom=birthday_date(t,max_age)to=birthday_date(t,min_age)between(from: from,to: to).to_dateend### Produces a date in the year and/or month specified.## @param month [Integer] represents the month of the date# @param year [Integer] represents the year of the date# @return [Date]## @example# Faker::Date.in_date_period #=> #<Date: 2019-09-01>## @example# Faker::Date.in_date_period(year: 2018, month: 2) #=> #<Date: 2018-02-26>## @example# Faker::Date.in_date_period(month: 2) #=> #<Date: 2019-02-26>## @faker.version 2.13.0defin_date_period(month: nil,year: ::Date.today.year)from=::Date.new(year,month||1,1)to=::Date.new(year,month||12,::Date.civil(year,month||12,-1).day)between(from: from,to: to).to_dateendprivatedefbirthday_date(date,age)year=date.year-ageday=ifdate.day==29&&date.month==2&&!::Date.leap?(year)28elsedate.dayend::Date.new(year,date.month,day)enddefget_date_object(date)date=::Date.parse(date)ifdate.is_a?(::String)date=date.to_dateifdate.respond_to?(:to_date)dateendendendend