Module: Doing::ChronifyString

Included in:
String
Defined in:
lib/doing/chronify/string.rb

Overview

Chronify methods for strings

Instance Method Summary collapse

Instance Method Details

#chronify(**options) ⇒ DateTime

Converts input string into a Time object when input takes on the following formats: - interval format e.g. '1d2h30m', '45m' etc. - a semantic phrase e.g. 'yesterday 5:30pm' - a strftime e.g. '2016-03-15 15:32:04 PDT'

Parameters:

  • options

    Additional options

Options Hash (**options):

  • :future (Boolean)

    assume future date (default: false)

  • :guess (Symbol)

    :begin or :end to assume beginning or end of arbitrary time range

Returns:

  • (DateTime)

    result

Raises:

#chronify_qtyInteger

Converts simple strings into seconds that can be added to a Time object

Input string can be HH:MM or XX[dhm][XXhm][XXm]

Returns:

  • (Integer)

    seconds

#expand_date_tags(additional_tags = nil) ⇒ Object

Convert (chronify) natural language dates within configured date tags (tags whose value is expected to be a date). Modifies string in place.

Parameters:

  • additional_tags (Array) (defaults to: nil)

    An array of additional tags to consider date_tags

#is_range?Boolean

Returns:

  • (Boolean)

#split_date_rangeArray<DateTime>

Splits a range string and returns an array of DateTime objects as [start, end]. If only one date is given, end time is nil.

Examples:

Process a natural language date range

"mon 3pm to mon 5pm".split_date_range

Returns:

  • (Array<DateTime>)

    Start and end dates as array

#time_string(format: :dhm) ⇒ Object

Convert DD:HH:MM to a natural language string

Parameters:

  • format (Symbol) (defaults to: :dhm)

    The format to output (:dhm, :hm, :m, :clock, :natural)

#to_secondsInteger

Convert DD:HH:MM to seconds

Returns:

  • (Integer)

    rounded number of seconds

Raises: