Module: OpenEHR::AssumedLibraryTypes::ISO8601DurationModule

Includes:
TimeDefinitions
Included in:
ISO8601Duration, RM::DataTypes::Quantity::DateTime::DvDuration
Defined in:
lib/openehr/assumed_library_types.rb

Overview

end of ISO8601Timezone

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 collapse

Instance Method Summary collapse

Methods included from TimeDefinitions

valid_day?, valid_hour?, valid_minute?, valid_month?, valid_second?, valid_year?

Instance Attribute Details

#daysObject

Returns the value of attribute days.



622
623
624
# File 'lib/openehr/assumed_library_types.rb', line 622

def days
  @days
end

#fractional_secondObject

Returns the value of attribute fractional_second.



623
624
625
# File 'lib/openehr/assumed_library_types.rb', line 623

def fractional_second
  @fractional_second
end

#hoursObject

Returns the value of attribute hours.



623
624
625
# File 'lib/openehr/assumed_library_types.rb', line 623

def hours
  @hours
end

#minutesObject

Returns the value of attribute minutes.



623
624
625
# File 'lib/openehr/assumed_library_types.rb', line 623

def minutes
  @minutes
end

#monthsObject

Returns the value of attribute months.



622
623
624
# File 'lib/openehr/assumed_library_types.rb', line 622

def months
  @months
end

#negativeObject

RM 1.1.0 (SPECRM-96): a leading '-' before 'P' negates the whole duration (e.g. "-P10D", 10 days before an unstated origin point). Components stay non-negative magnitudes - the sign applies to the duration as a whole, not each field - so it's tracked here.



628
629
630
# File 'lib/openehr/assumed_library_types.rb', line 628

def negative
  @negative
end

#secondsObject

Returns the value of attribute seconds.



623
624
625
# File 'lib/openehr/assumed_library_types.rb', line 623

def seconds
  @seconds
end

#weeksObject

Returns the value of attribute weeks.



622
623
624
# File 'lib/openehr/assumed_library_types.rb', line 622

def weeks
  @weeks
end

#yearsObject

Returns the value of attribute years.



622
623
624
# File 'lib/openehr/assumed_library_types.rb', line 622

def years
  @years
end

Instance Method Details

#as_stringObject



694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/openehr/assumed_library_types.rb', line 694

def as_string
  str = negative? ? '-P' : 'P'
  unless @years.nil?
    str += @years.to_s + 'Y'
  end
  unless @months.nil?
    str += @months.to_s + 'M'
  end
  unless @weeks.nil?
    str += @weeks.to_s + 'W'
  end
  unless @days.nil?
    str += @days.to_s + 'D'
  end
  unless @hours.nil?
    str += 'T' + @hours.to_s + 'H'
    unless @minutes.nil?
      str += @minutes.to_s + 'M'
      unless @seconds.nil?
        str += @seconds.to_s
        unless @fractional_second.nil?
          str += @fractional_second.to_s[1 .. -1]
        end
        str += 'S'
      end
    end
  end
  return str
end

#negative?Boolean

Returns:

  • (Boolean)


634
635
636
# File 'lib/openehr/assumed_library_types.rb', line 634

def negative?
  @negative == true
end

#to_secondsObject



724
725
726
727
728
729
730
731
732
733
# File 'lib/openehr/assumed_library_types.rb', line 724

def to_seconds
  days = (nilthenzero(@years)*TimeDefinitions::DAYS_IN_YEAR) +
    (nilthenzero(@months)*TimeDefinitions::DAYS_IN_MONTH) +
    (nilthenzero(@weeks)*TimeDefinitions::DAYS_IN_WEEK) + 
    nilthenzero(@days)
  seconds_with_fractional = (((((days*TimeDefinitions::HOURS_IN_DAY) + nilthenzero(@hours))*TimeDefinitions::MINUTES_IN_HOUR)+nilthenzero(@minutes))*TimeDefinitions::SECONDS_IN_MINUTE) +
    nilthenzero(@seconds) +
    @fractional_second.to_f
  return negative? ? -seconds_with_fractional : seconds_with_fractional
end