module

Cronic

Parse natural language dates and times into Time or Cronic::Timespan objects.

Examples:

require "cronic"

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

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

Cronic.parse("monday", context: PointerDir::Past)
# => Mon Aug 21 12:00:00 PDT 2006

Constants

SEASON_ADJUSTS = {Season::Spring => [0, 3, 20, 0, 6, 20], Season::Summer => [0, 6, 21, 0, 9, 22], Season::Autumn => [0, 9, 23, 0, 12, 21], Season::Winter => [0, 12, 22, 1, 3, 19]}
VERSION = "0.10.2"

Class methods

construct(year : Int32, month : Int32 = 1, day : Int32 = 1, hour : Int32 = 0, minute : Int32 = 0, second : Int32 = 0, offset = nil) : Time

Construct a new Time object determining possible month overflows and leap years. Accounts for overflows in the values

  • year - Int32 year.
  • month - Int32 month.
  • day - Int32 day.
  • hour - Int32 hour.
  • minute - Int32 minute.
  • second - Int32 second.

Returns a new Time object constructed from these params.

Source
debug

Enable debug-mode printing for Cronic

Source
debug=(debug)

Enable debug-mode printing for Cronic

Source
parse(text, guess : Guess = Guess::Middle, **kwargs) : Time

Parses a text String containing a natural language date or time.

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

Source
parse?(*args, **kwargs) : Time | Nil

Parses like self.parse, but will return nil if a ParseError is raised

Source
parse_span(text, **kwargs) : Timespan

Parses a text String containing natural language date or time.

Similar to self.parse, but returns a Cronic::Timespan of the begin-end time for the generated time-span instead of guessing a specific time-point during that range.

Source

Nested types