Module: TimeFormatterHelper
- Included in:
- HL7::Message::Segment
- Defined in:
- lib/helpers/time_formatter_helper.rb
Defined Under Namespace
Classes: ValueTypeNotSupportedError
Instance Method Summary collapse
-
#hl7_formatted_date(value) ⇒ Object
Get an HL7 timestamp (type TS) for a Date instance.
-
#hl7_formatted_timestamp(value, fraction_digits = 0) ⇒ Object
Get an HL7 timestamp (type TS) for a Time or DateTime instance.
Instance Method Details
#hl7_formatted_date(value) ⇒ Object
Get an HL7 timestamp (type TS) for a Date instance.
21 22 23 24 25 |
# File 'lib/helpers/time_formatter_helper.rb', line 21 def hl7_formatted_date(value) raise ValueTypeNotSupportedError, "Value must be an instance of Date" unless value.is_a?(Date) value.strftime("%Y%m%d") end |
#hl7_formatted_timestamp(value, fraction_digits = 0) ⇒ Object
Get an HL7 timestamp (type TS) for a Time or DateTime instance.
- fraction_digits
-
specifies a number of digits of fractional seconds. Its default value is 0.
(Time.parse('01:23'))
=> "20091202012300"
(Time.now, 3)
=> "20091202153652.302"
14 15 16 17 18 |
# File 'lib/helpers/time_formatter_helper.rb', line 14 def (value, fraction_digits = 0) raise ValueTypeNotSupportedError, "Value must be an instance of Time or DateTime" unless value.is_a?(Time) || value.is_a?(DateTime) value.strftime("%Y%m%d%H%M%S") + hl7_formatted_fractions(value, fraction_digits) end |