class Chronic::Date

Constants

DAYS
DAY_SECONDS
FORTNIGHT_SECONDS
MONTHS
MONTH_DAYS
MONTH_DAYS_LEAP
MONTH_SECONDS
SEASON_SECONDS
WEEKEND_SECONDS
WEEK_SECONDS
YEAR_MONTHS
YEAR_SECONDS

Public Class Methods

could_be_day?(day) click to toggle source

Checks if given number could be day

# File lib/chronic/date.rb, line 38
def self.could_be_day?(day)
  day >= 1 && day <= 31
end
could_be_month?(month) click to toggle source

Checks if given number could be month

# File lib/chronic/date.rb, line 43
def self.could_be_month?(month)
  month >= 1 && month <= 12
end
could_be_year?(year) click to toggle source

Checks if given number could be year

# File lib/chronic/date.rb, line 48
def self.could_be_year?(year)
  year >= 1 && year <= 9999
end
make_year(year, bias) click to toggle source

Build a year from a 2 digit suffix.

year - The two digit Integer year to build from. bias - The Integer amount of future years to bias.

Examples:

make_year(96, 50) #=> 1996
make_year(79, 20) #=> 2079
make_year(00, 50) #=> 2000

Returns The Integer 4 digit year.

# File lib/chronic/date.rb, line 64
def self.make_year(year, bias)
  return year if year.to_s.size > 2
  start_year = Chronic.time_class.now.year - bias
  century = (start_year / 100) * 100
  full_year = century + year
  full_year += 100 if full_year < start_year
  full_year
end
month_overflow?(year, month, day) click to toggle source
# File lib/chronic/date.rb, line 73
def self.month_overflow?(year, month, day)
  if ::Date.leap?(year)
    day > Date::MONTH_DAYS_LEAP[month]
  else
    day > Date::MONTH_DAYS[month]
  end
end