### Home Classes Methods

### In Files

- lib/chronic.rb
- lib/chronic/sign.rb
- lib/chronic/date.rb
- lib/chronic/time.rb
- lib/chronic/handler.rb
- lib/chronic/time_zone.rb
- lib/chronic/scalar.rb
- lib/chronic/parser.rb
- lib/chronic/numerizer.rb
- lib/chronic/ordinal.rb
- lib/chronic/season.rb
- lib/chronic/grabber.rb
- lib/chronic/mini_date.rb
- lib/chronic/repeaters/repeater_month.rb
- lib/chronic/repeaters/repeater_day_name.rb
- lib/chronic/repeaters/repeater_minute.rb
- lib/chronic/repeaters/repeater_day.rb
- lib/chronic/repeaters/repeater_day_portion.rb
- lib/chronic/repeaters/repeater_season_name.rb
- lib/chronic/repeaters/repeater_season.rb
- lib/chronic/repeaters/repeater_weekday.rb
- lib/chronic/repeaters/repeater_week.rb
- lib/chronic/repeaters/repeater_fortnight.rb
- lib/chronic/repeaters/repeater_weekend.rb
- lib/chronic/repeaters/repeater_month_name.rb
- lib/chronic/repeaters/repeater_time.rb
- lib/chronic/repeaters/repeater_second.rb
- lib/chronic/repeaters/repeater_year.rb
- lib/chronic/repeaters/repeater_hour.rb
- lib/chronic/token.rb
- lib/chronic/separator.rb
- lib/chronic/handlers.rb
- lib/chronic/tag.rb
- lib/chronic/repeater.rb
- lib/chronic/pointer.rb
- lib/chronic/span.rb

### Namespace

- MODULE Chronic::Handlers
- CLASS Chronic::Date
- CLASS Chronic::Grabber
- CLASS Chronic::Handler
- CLASS Chronic::MiniDate
- CLASS Chronic::Numerizer
- CLASS Chronic::Ordinal
- CLASS Chronic::Parser
- CLASS Chronic::Pointer
- CLASS Chronic::Repeater
- CLASS Chronic::Scalar
- CLASS Chronic::Season
- CLASS Chronic::Separator
- CLASS Chronic::Sign
- CLASS Chronic::Span
- CLASS Chronic::Tag
- CLASS Chronic::Time
- CLASS Chronic::TimeZone
- CLASS Chronic::Token

### Methods

- ::construct
- ::parse

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Chronic
- Chronic::Date
- Chronic::Grabber
- Chronic::Handler
- Chronic::Handlers
- Chronic::MiniDate
- Chronic::Numerizer
- Chronic::Ordinal
- Chronic::Parser
- Chronic::Pointer
- Chronic::Repeater
- Chronic::Scalar
- Chronic::Season
- Chronic::Separator
- Chronic::Sign
- Chronic::Span
- Chronic::Tag
- Chronic::Time
- Chronic::TimeZone
- Chronic::Token

No matching classes.

# Chronic

Parse natural language dates and times into Time or Chronic::Span objects.

Examples:

    require 'chronic'

    Time.now   #=> Sun Aug 27 23:18:25 PDT 2006

    Chronic.parse('tomorrow')
      #=> Mon Aug 28 12:00:00 PDT 2006

    Chronic.parse('monday', :context => :past)
      #=> Mon Aug 21 12:00:00 PDT 2006

### Constants

VERSION

### Attributes

debug[RW]

Returns true when debug mode is enabled.

time_class[RW]

Examples:

    require 'chronic'
    require 'active_support/time'

    Time.zone = 'UTC'
    Chronic.time_class = Time.zone
    Chronic.parse('June 15 2006 at 5:54 AM')
      # => Thu, 15 Jun 2006 05:45:00 UTC +00:00

Returns The Time class Chronic uses internally.

### Public Class Methods

construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0, offset = nil) click to toggle source

Construct a new time object determining possible month overflows and leap years.

year - Integer year. month - Integer month. day - Integer day. hour - Integer hour. minute - Integer minute. second - Integer second.

Returns a new Time object constructed from these params.

    # File lib/chronic.rb, line 104
    def self.construct(year, month = 1, day = 1, hour = 0, minute = 0, second = 0, offset = nil)
      if second >= 60
        minute += second / 60
        second = second % 60
      end

      if minute >= 60
        hour += minute / 60
        minute = minute % 60
      end

      if hour >= 24
        day += hour / 24
        hour = hour % 24
      end

      # determine if there is a day overflow. this is complicated by our crappy calendar
      # system (non-constant number of days per month)
      day <= 56 || raise("day must be no more than 56 (makes month resolution easier)")
      if day > 28 # no month ever has fewer than 28 days, so only do this if necessary
        days_this_month = ::Date.leap?(year) ? Date::MONTH_DAYS_LEAP[month] : Date::MONTH_DAYS[month]
        if day > days_this_month
          month += day / days_this_month
          day = day % days_this_month
        end
      end

      if month > 12
        if month % 12 == 0
          year += (month - 12) / 12
          month = 12
        else
          year += month / 12
          month = month % 12
        end
      end
      if Chronic.time_class.name == "Date"
        Chronic.time_class.new(year, month, day)
      elsif not Chronic.time_class.respond_to?(:new) or (RUBY_VERSION.to_f < 1.9 and Chronic.time_class.name == "Time")
        Chronic.time_class.local(year, month, day, hour, minute, second)
      else
        offset = Time::normalize_offset(offset) if Chronic.time_class.name == "DateTime"
        Chronic.time_class.new(year, month, day, hour, minute, second, offset)
      end
    end

parse(text, options = {}) click to toggle source

Parses a string containing a natural language date or time.

If the parser can find a date or time, either a Time or Chronic::Span will be returned (depending on the value of `:guess`). If no date or time can be found, `nil` will be returned.

text - The String text to parse. opts - An optional Hash of configuration options passed to Parser::new.

    # File lib/chronic.rb, line 89
    def self.parse(text, options = {})
      Parser.new(options).parse(text)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.