module Cronic

Overview

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

Defined in:

cronic.cr:3
cronic.cr:78
cronic/date.cr
cronic/definition.cr
cronic/enums.cr
cronic/handlers.cr
cronic/parser.cr
cronic/repeaters/repeater_day.cr
cronic/repeaters/repeater_day_name.cr
cronic/repeaters/repeater_day_portion.cr
cronic/repeaters/repeater_fortnight.cr
cronic/repeaters/repeater_hour.cr
cronic/repeaters/repeater_minute.cr
cronic/repeaters/repeater_month.cr
cronic/repeaters/repeater_month_name.cr
cronic/repeaters/repeater_quarter.cr
cronic/repeaters/repeater_quarter_name.cr
cronic/repeaters/repeater_season.cr
cronic/repeaters/repeater_season_name.cr
cronic/repeaters/repeater_second.cr
cronic/repeaters/repeater_time.cr
cronic/repeaters/repeater_week.cr
cronic/repeaters/repeater_weekday.cr
cronic/repeaters/repeater_weekend.cr
cronic/repeaters/repeater_year.cr
cronic/season.cr
cronic/seq_matcher.cr
cronic/span.cr
cronic/tag.cr
cronic/tags/grabber.cr
cronic/tags/ordinal.cr
cronic/tags/pointer.cr
cronic/tags/repeater.cr
cronic/tags/scalar.cr
cronic/tags/separator.cr
cronic/tags/sign.cr
cronic/tags/time_zone.cr
cronic/time.cr
cronic/token.cr
cronic/tokenizer.cr
cronic/version.cr

Constant Summary

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 Method Summary

Class Method Detail

def self.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.


[View source]
def self.debug #

Enable debug-mode printing for Cronic


[View source]
def self.debug=(debug) #

Enable debug-mode printing for Cronic


[View source]
def self.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.


[View source]
def self.parse?(*args, **kwargs) : Time | Nil #

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


[View source]
def self.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.


[View source]