Class: OpenEHR::AssumedLibraryTypes::ISO8601Time
- Inherits:
-
Object
- Object
- OpenEHR::AssumedLibraryTypes::ISO8601Time
- Includes:
- Comparable, ISO8601TimeModule
- Defined in:
- lib/openehr/assumed_library_types.rb
Constant Summary
Constants included from TimeDefinitions
TimeDefinitions::DAYS_IN_LEAP_YEAR, TimeDefinitions::DAYS_IN_MONTH, TimeDefinitions::DAYS_IN_WEEK, TimeDefinitions::DAYS_IN_YEAR, TimeDefinitions::HOURS_IN_DAY, TimeDefinitions::MAX_DAYS_IN_MONTH, TimeDefinitions::MAX_DAYS_IN_YEAR, TimeDefinitions::MINUTES_IN_HOUR, TimeDefinitions::MONTH_IN_YEAR, TimeDefinitions::NOMINAL_DAYS_IN_MONTH, TimeDefinitions::NOMINAL_DAYS_IN_YEAR, TimeDefinitions::SECONDS_IN_MINUTE
Instance Attribute Summary
Attributes included from ISO8601TimeModule
#fractional_second, #hour, #minute, #second
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(string) ⇒ ISO8601Time
constructor
A new instance of ISO8601Time.
Methods included from ISO8601TimeModule
#as_string, #has_fractional_second?, #is_decimal_sign_comma?, #is_extended?, #is_partial?, #minute_unknown?, #second_unknown?, #timezone, #timezone=, #to_second
Methods included from TimeDefinitions
valid_day?, valid_hour?, valid_minute?, valid_month?, valid_second?, valid_year?
Constructor Details
#initialize(string) ⇒ ISO8601Time
Returns a new instance of ISO8601Time.
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# 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 |
Class Method Details
.valid_iso8601_time?(s) ⇒ Boolean
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Object
418 419 420 |
# File 'lib/openehr/assumed_library_types.rb', line 418 def <=>(other) self.to_second <=> other.to_second end |