Sha256: bbddd4976c91acee6ab63d4ac791003592182df884c70ae7b2d7282876eb998c
Contents?: true
Size: 1.77 KB
Versions: 8
Compression:
Stored size: 1.77 KB
Contents
require 'spec_helper' module XML module MappingExtensions class DateNodeSpecElem include ::XML::Mapping date_node :date, '@date', default_value: nil date_node :zulu_date, '@zulu_date', default_value: nil, zulu: true def self.from_str(date_str) xml_string = "<elem date='#{date_str}' zulu_date='#{date_str}'/>" doc = REXML::Document.new(xml_string) load_from_xml(doc.root) end end describe DateNode do def to_date(str) DateNodeSpecElem.from_str(str).date end def to_text(date) elem = DateNodeSpecElem.new elem.date = date xml = elem.save_to_xml xml.attributes['date'] end def to_zulu_text(date) elem = DateNodeSpecElem.new elem.zulu_date = date xml = elem.save_to_xml xml.attributes['zulu_date'] end it 'parses a date' do actual = to_date('2002-09-24') expected = Date.new(2002, 9, 24) expect(actual).to eq(expected) end it 'parses a UTC "zulu" date (time zone designator "Z")' do actual = to_date('2002-09-24Z') expected = Date.new(2002, 9, 24) expect(actual).to eq(expected) end it 'parses a date with a numeric timezone offset' do actual = to_date('2002-09-24-06:00') expected = Date.new(2002, 9, 24) expect(actual).to eq(expected) end it 'outputs a date' do expected = '2002-09-24' actual = to_text(Date.new(2002, 9, 24)) expect(actual).to eq(expected) end it 'outputs a UTC "zulu" date (time zone designator "Z")' do expected = '2002-09-24Z' actual = to_zulu_text(Date.new(2002, 9, 24)) expect(actual).to eq(expected) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems