class MicroMicro::Parsers::DateTimeParser
Constants
- CAPTURE_NAMES
- DATE_REGEXP_PATTERN
@see microformats.org/wiki/value-class-pattern#Date_and_time_parsing
Regexp pattern matching YYYY-MM-DD and YYY-DDD
- TIMEZONE_REGEXP_PATTERN
Regexp pattern matching +/-(XX:YY|XXYY|XX) or the literal string Z
- TIME_REGEXP_PATTERN
Regexp pattern matching HH:MM and HH:MM:SS
Attributes
string[R]
Public Class Methods
new(string)
click to toggle source
@param string [String]
# File lib/micro_micro/parsers/date_time_parser.rb, line 16 def initialize(string) @string = string end
values_from(string)
click to toggle source
@param string [String] @return [Hash{Symbol => String, nil}]
# File lib/micro_micro/parsers/date_time_parser.rb, line 70 def self.values_from(string) string&.match(/^(?:#{DATE_REGEXP_PATTERN})?(?:\s?#{TIME_REGEXP_PATTERN}(?:#{TIMEZONE_REGEXP_PATTERN})?)?$/)&.named_captures.to_h.symbolize_keys end
Public Instance Methods
normalized_calendar_date()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 25 def normalized_calendar_date @normalized_calendar_date ||= "#{year}-#{month}-#{day}" if year? && month? && day? end
normalized_date()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 29 def normalized_date @normalized_date ||= normalized_calendar_date || normalized_ordinal_date end
normalized_hours()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 33 def normalized_hours @normalized_hours ||= begin return unless hours? return (hours.to_i + 12).to_s if abbreviation&.tr('.', '')&.downcase == 'pm' format('%<hours>02d', hours: hours) end end
normalized_minutes()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 42 def normalized_minutes @normalized_minutes ||= minutes || '00' end
normalized_ordinal_date()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 46 def normalized_ordinal_date @normalized_ordinal_date ||= "#{year}-#{ordinal}" if year? && ordinal? end
normalized_time()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 50 def normalized_time @normalized_time ||= [normalized_hours, normalized_minutes, seconds].compact.join(':') if normalized_hours end
normalized_timezone()
click to toggle source
# File lib/micro_micro/parsers/date_time_parser.rb, line 54 def normalized_timezone @normalized_timezone ||= zulu || offset&.tr(':', '') end
value()
click to toggle source
@return [String]
# File lib/micro_micro/parsers/date_time_parser.rb, line 59 def value @value ||= "#{normalized_date} #{normalized_time}#{normalized_timezone}".strip if normalized_date || normalized_time || normalized_timezone end
values()
click to toggle source
@return [Hash{Symbol => String, nil}]
# File lib/micro_micro/parsers/date_time_parser.rb, line 64 def values @values ||= self.class.values_from(string) end