class OpenEHR::AssumedLibraryTypes::ISO8601Time

Public Class Methods

new(string) click to toggle source
# File lib/openehr/assumed_library_types.rb, line 389
def initialize(string)
  /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?$/ =~ string
  if $2.nil?
    self.minute = nil
  else
    self.minute = $2.to_i
  end
  if $4.nil?
    self.second = nil
  else
    self.second = $4.to_i
  end
  if $1.nil?
    raise ArgumentError, 'data invalid'
  else
    self.hour = $1.to_i
  end
  if $7.nil?
    self.fractional_second = nil
  else
    self.fractional_second = ("0." + $7).to_f
  end
  if $8.nil?
    self.timezone = nil
  else
    self.timezone = $8
  end
end
valid_iso8601_time?(s) click to toggle source
# File lib/openehr/assumed_library_types.rb, line 422
      def self.valid_iso8601_time?(s)
        if /^(\d{2}):?(\d{2})?(:?)(\d{2})?((\.|,)(\d+))?(Z|([+-](\d{2}):?(\d{2})))?$/ =~ s
# ISO 8601 regular expression by H. Yuki
#  http://digit.que.ne.jp/work/wiki.cgi?Perl%E3%83%A1%E3%83%A2%2FW3C%E5%BD%A2%E5%BC%8F%E3%81%AE%E6%97%A5%E6%99%82%E3%81%AE%E8%A7%A3%E6%9E%90
# (\d{4})(?:-(\d{2})(?:-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d))?)?(Z|([+-]\d{2}):(\d{2}))?)?)?)?
          hh = $1; mm = $2; ss = $4; msec = $7; tz = $8
          if hh.to_i == HOURS_IN_DAY and (mm.nil? or mm.to_i == 0) and (ss.nil? or ss.to_i == 0) and (msec.nil? or msec.to_i==0)
            return true
          end
          if hh.nil? or (hh.to_i < 0 or hh.to_i >= HOURS_IN_DAY)
            return false
          end
          if !mm.nil? 
            if !TimeDefinitions.valid_minute?(mm.to_i)
              return false
            end
          end
          if !ss.nil? 
            if !TimeDefinitions.valid_second?(ss.to_i)
              return false
            end
          end
          unless tz.nil?
            timezone = Timezone.new(tz)
            if timezone.hour < 0 or timezone.hour >= HOURS_IN_DAY
              return false
            end
            if timezone.minute < 0 or timezone.minute >= MINUTES_IN_HOUR
              return false
            end
            return true
          else
            return false
          end
        end
      end

Public Instance Methods

<=>(other) click to toggle source
# File lib/openehr/assumed_library_types.rb, line 418
def <=>(other)
  self.to_second <=> other.to_second
end