method

_parse_time

Importance_0
v1_8_6_287 - Show latest stable - 0 notes - Class: Date
_parse_time(str, e) private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/date/format.rb, line 681
  def self._parse_time(str, e) # :nodoc:
    if str.sub!(
                /(
                   (?:
                     \d+\s*:\s*\d+
                     (?:
                       \s*:\s*\d+(?:[,.]\d*)?
                     )?
                   |
                     \d+\s*h(?:\s*\d+m?(?:\s*\d+s?)?)?
                   )
                   (?:
                     \s*
                     [ap](?:m\b|\.m\.)
                   )?
                 |
                   \d+\s*[ap](?:m\b|\.m\.)
                 )
                 (?:
                   \s*
                   (
                     (?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
                   |
                     [a-z.\s]+(?:standard|daylight)\stime\b
                   |
                     [a-z]+(?:\sdst)?\b
                   )
                 )?
                /inx,
                ' ')

      t = $1
      e.zone = $2 if $2

      t =~ /\A(\d+)h?
              (?:\s*:?\s*(\d+)m?
                (?:
                  \s*:?\s*(\d+)(?:[,.](\d+))?s?
                )?
              )?
            (?:\s*([ap])(?:m\b|\.m\.))?/inx

      e.hour = $1.to_i
      e.min = $2.to_i if $2
      e.sec = $3.to_i if $3
      e.sec_fraction = $4.to_i.to_r / (10**$4.size) if $4

      if $5
        e.hour %= 12
        if $5.downcase == 'p'
          e.hour += 12
        end
      end
      true
    end
  end
Register or log in to add new notes.