Method: Origami::Date.parse

Defined in:
lib/origami/string.rb

.parse(str) ⇒ Object

:nodoc:

Raises:



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/origami/string.rb', line 395

def self.parse(str) #:nodoc:
    raise InvalidDateError, "Not a valid Date string" unless str =~ REGEXP_TOKEN

    date =
    {
        year: $~['year'].to_i
    }

    date[:month] = $~['month'].to_i if $~['month']
    date[:day] = $~['day'].to_i if $~['day']
    date[:hour] = $~['hour'].to_i if $~['hour']
    date[:min] = $~['min'].to_i if $~['min']
    date[:sec] = $~['sec'].to_i if $~['sec']

    if %w[+ -].include?($~['ut'])
        utc_offset = $~['ut_hour_off'].to_i * 3600 + $~['ut_min_off'].to_i * 60
        utc_offset = -utc_offset if $~['ut'] == '-'

        date[:utc_offset] = utc_offset
    end

    Origami::Date.new(date)
end