module DataMagic::DateTranslation
Public Instance Methods
date_between(from = nil, to = nil, format = '%D')
click to toggle source
return random date within the range
# File lib/data_magic/date_translation.rb, line 84 def date_between(from = nil, to = nil, format = '%D') raise ArgumentError, 'Invalid date format' if from.to_s.empty? || to.to_s.empty? start_date = from.nil? ? Date.today.strftime(format) : Date.strptime(from, format) end_date = to.nil? ? Date.today.strftime(format) : Date.strptime(to, format) Faker::Date.between(from: start_date, to: end_date).strftime(format) end
Also aliased as: dm_date_between
day_of_week()
click to toggle source
return a day of the week
# File lib/data_magic/date_translation.rb, line 65 def day_of_week randomize(Date::DAYNAMES) end
Also aliased as: dm_day_of_week
day_of_week_abbr()
click to toggle source
# File lib/data_magic/date_translation.rb, line 70 def day_of_week_abbr randomize(Date::ABBR_DAYNAMES) end
Also aliased as: dm_day_of_week_abbr
month()
click to toggle source
return a month
# File lib/data_magic/date_translation.rb, line 49 def month randomize(Date::MONTHNAMES[1..-1]) end
Also aliased as: dm_month
month_abbr()
click to toggle source
return a month abbreviation
# File lib/data_magic/date_translation.rb, line 57 def month_abbr randomize(Date::ABBR_MONTHNAMES[1..-1]) end
Also aliased as: dm_month_abbr
today(format = '%D')
click to toggle source
return today’s date
@param String
the format to use for the date. Default is %D
See ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime for details of the formats
# File lib/data_magic/date_translation.rb, line 13 def today(format = '%D') Date.today.strftime(format) end
Also aliased as: dm_today
tomorrow(format = '%D')
click to toggle source
return tomorrow’s date
@param String
the format to use for the date. Default is %D
See ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime for details of the formats
# File lib/data_magic/date_translation.rb, line 26 def tomorrow(format = '%D') tomorrow = Date.today + 1 tomorrow.strftime(format) end
Also aliased as: dm_tomorrow
yesterday(format = '%D')
click to toggle source
return yesterday’s date
@param String
the format to use for the date. Default is %D
See ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-i-strftime for details of the formats
# File lib/data_magic/date_translation.rb, line 40 def yesterday(format = '%D') yesterday = Date.today - 1 yesterday.strftime(format) end
Also aliased as: dm_yesterday