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
-
#days ⇒ Object
Returns the value of attribute days.
-
#fractional_second ⇒ Object
Returns the value of attribute fractional_second.
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#minutes ⇒ Object
Returns the value of attribute minutes.
-
#months ⇒ Object
Returns the value of attribute months.
-
#negative ⇒ Object
RM 1.1.0 (SPECRM-96): a leading '-' before 'P' negates the whole duration (e.g. "-P10D", 10 days before an unstated origin point).
-
#seconds ⇒ Object
Returns the value of attribute seconds.
-
#weeks ⇒ Object
Returns the value of attribute weeks.
-
#years ⇒ Object
Returns the value of attribute years.
Instance Method Summary collapse
Methods included from TimeDefinitions
valid_day?, valid_hour?, valid_minute?, valid_month?, valid_second?, valid_year?
Instance Attribute Details
#days ⇒ Object
Returns the value of attribute days.
619 620 621 |
# File 'lib/openehr/assumed_library_types.rb', line 619 def days @days end |
#fractional_second ⇒ Object
Returns the value of attribute fractional_second.
620 621 622 |
# File 'lib/openehr/assumed_library_types.rb', line 620 def fractional_second @fractional_second end |
#hours ⇒ Object
Returns the value of attribute hours.
620 621 622 |
# File 'lib/openehr/assumed_library_types.rb', line 620 def hours @hours end |
#minutes ⇒ Object
Returns the value of attribute minutes.
620 621 622 |
# File 'lib/openehr/assumed_library_types.rb', line 620 def minutes @minutes end |
#months ⇒ Object
Returns the value of attribute months.
619 620 621 |
# File 'lib/openehr/assumed_library_types.rb', line 619 def months @months end |
#negative ⇒ Object
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.
625 626 627 |
# File 'lib/openehr/assumed_library_types.rb', line 625 def negative @negative end |
#seconds ⇒ Object
Returns the value of attribute seconds.
620 621 622 |
# File 'lib/openehr/assumed_library_types.rb', line 620 def seconds @seconds end |
#weeks ⇒ Object
Returns the value of attribute weeks.
619 620 621 |
# File 'lib/openehr/assumed_library_types.rb', line 619 def weeks @weeks end |
#years ⇒ Object
Returns the value of attribute years.
619 620 621 |
# File 'lib/openehr/assumed_library_types.rb', line 619 def years @years end |
Instance Method Details
#as_string ⇒ Object
691 692 693 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 |
# File 'lib/openehr/assumed_library_types.rb', line 691 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
631 632 633 |
# File 'lib/openehr/assumed_library_types.rb', line 631 def negative? @negative == true end |
#to_seconds ⇒ Object
721 722 723 724 725 726 727 728 729 730 |
# File 'lib/openehr/assumed_library_types.rb', line 721 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 |