iso8601 0.12.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/iso8601.gemspec +3 -41
 - data/lib/iso8601/version.rb +1 -1
 - metadata +8 -34
 - data/CHANGELOG.md +0 -114
 - data/docs/date-time.md +0 -86
 - data/docs/duration.md +0 -76
 - data/docs/time-interval.md +0 -120
 - data/spec/iso8601/date_spec.rb +0 -91
 - data/spec/iso8601/date_time_spec.rb +0 -154
 - data/spec/iso8601/days_spec.rb +0 -44
 - data/spec/iso8601/duration_spec.rb +0 -299
 - data/spec/iso8601/hours_spec.rb +0 -44
 - data/spec/iso8601/minutes_spec.rb +0 -44
 - data/spec/iso8601/months_spec.rb +0 -98
 - data/spec/iso8601/seconds_spec.rb +0 -44
 - data/spec/iso8601/time_interval_spec.rb +0 -520
 - data/spec/iso8601/time_spec.rb +0 -110
 - data/spec/iso8601/weeks_spec.rb +0 -46
 - data/spec/iso8601/years_spec.rb +0 -70
 - data/spec/spec_helper.rb +0 -12
 
    
        data/spec/iso8601/date_spec.rb
    DELETED
    
    | 
         @@ -1,91 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe ISO8601::Date do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should raise an error for any unknown pattern" do
         
     | 
| 
       5 
     | 
    
         
            -
                expect { ISO8601::Date.new('') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       6 
     | 
    
         
            -
                expect { ISO8601::Date.new('2') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       7 
     | 
    
         
            -
                expect { ISO8601::Date.new('20') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       8 
     | 
    
         
            -
                expect { ISO8601::Date.new('201') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       9 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       10 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       11 
     | 
    
         
            -
                expect { ISO8601::Date.new('20-05') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       12 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-0') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       13 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-0-09') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       14 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-1-09') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       15 
     | 
    
         
            -
                expect { ISO8601::Date.new('201001-09') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       16 
     | 
    
         
            -
                expect { ISO8601::Date.new('201-0109') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       17 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014-W15-02') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       18 
     | 
    
         
            -
              end
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
              it "should raise an error for a correct pattern but an invalid date" do
         
     | 
| 
       21 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-01-32') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       22 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-02-30') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       23 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-13-30') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       24 
     | 
    
         
            -
              end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
              it "should parse any allowed pattern" do
         
     | 
| 
       27 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010') }.to_not raise_error
         
     | 
| 
       28 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-05') }.to_not raise_error
         
     | 
| 
       29 
     | 
    
         
            -
                expect { ISO8601::Date.new('2010-05-09') }.to_not raise_error
         
     | 
| 
       30 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014-001') }.to_not raise_error
         
     | 
| 
       31 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014121') }.to_not raise_error
         
     | 
| 
       32 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014-W15') }.to_not raise_error
         
     | 
| 
       33 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014-W15-2') }.to_not raise_error
         
     | 
| 
       34 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014W15') }.to_not raise_error
         
     | 
| 
       35 
     | 
    
         
            -
                expect { ISO8601::Date.new('2014W152') }.to_not raise_error
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
              context 'reduced patterns' do
         
     | 
| 
       39 
     | 
    
         
            -
                it "should parse correctly reduced dates" do
         
     | 
| 
       40 
     | 
    
         
            -
                  reduced_date = ISO8601::Date.new('20100509')
         
     | 
| 
       41 
     | 
    
         
            -
                  expect(reduced_date.year).to eq(2010)
         
     | 
| 
       42 
     | 
    
         
            -
                  expect(reduced_date.month).to eq(5)
         
     | 
| 
       43 
     | 
    
         
            -
                  expect(reduced_date.day).to eq(9)
         
     | 
| 
       44 
     | 
    
         
            -
                end
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
              it "should return the right sign for the given year" do
         
     | 
| 
       48 
     | 
    
         
            -
                expect(ISO8601::Date.new('-2014-05-31').year).to eq(-2014)
         
     | 
| 
       49 
     | 
    
         
            -
                expect(ISO8601::Date.new('+2014-05-31').year).to eq(2014)
         
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
              it "should respond to delegated casting methods" do
         
     | 
| 
       53 
     | 
    
         
            -
                expect(ISO8601::Date.new('2014-12-11')).to respond_to(:to_s, :to_time, :to_date, :to_datetime)
         
     | 
| 
       54 
     | 
    
         
            -
              end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
              describe '#+' do
         
     | 
| 
       57 
     | 
    
         
            -
                it "should return the result of the addition of a number" do
         
     | 
| 
       58 
     | 
    
         
            -
                  expect((ISO8601::Date.new('2012-07-07') + 7).to_s).to eq('2012-07-14')
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
              end
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
              describe '#-' do
         
     | 
| 
       63 
     | 
    
         
            -
                it "should return the result of the subtraction" do
         
     | 
| 
       64 
     | 
    
         
            -
                  expect((ISO8601::Date.new('2012-07-07') - 7).to_s).to eq('2012-06-30')
         
     | 
| 
       65 
     | 
    
         
            -
                end
         
     | 
| 
       66 
     | 
    
         
            -
              end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
              describe '#to_a' do
         
     | 
| 
       69 
     | 
    
         
            -
                it "should return an array of atoms" do
         
     | 
| 
       70 
     | 
    
         
            -
                  expect(ISO8601::Date.new('2014-05-31').to_a).to eq([2014, 5, 31])
         
     | 
| 
       71 
     | 
    
         
            -
                end
         
     | 
| 
       72 
     | 
    
         
            -
              end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
              describe '#atoms' do
         
     | 
| 
       75 
     | 
    
         
            -
                it "should return an array of original atoms" do
         
     | 
| 
       76 
     | 
    
         
            -
                  expect(ISO8601::Date.new('2014-05-02').atoms).to eq([2014, 5, 2])
         
     | 
| 
       77 
     | 
    
         
            -
                  expect(ISO8601::Date.new('2014-05').atoms).to eq([2014, 5])
         
     | 
| 
       78 
     | 
    
         
            -
                  expect(ISO8601::Date.new('2014').atoms).to eq([2014])
         
     | 
| 
       79 
     | 
    
         
            -
                end
         
     | 
| 
       80 
     | 
    
         
            -
              end
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
              describe '#hash' do
         
     | 
| 
       83 
     | 
    
         
            -
                it "should return the date hash" do
         
     | 
| 
       84 
     | 
    
         
            -
                  subject = ISO8601::Date.new('2014-08-16')
         
     | 
| 
       85 
     | 
    
         
            -
                  contrast = ISO8601::Date.new('2014-08-16')
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
                  expect(subject).to respond_to(:hash)
         
     | 
| 
       88 
     | 
    
         
            -
                  expect(subject.hash).to eq(contrast.hash)
         
     | 
| 
       89 
     | 
    
         
            -
                end
         
     | 
| 
       90 
     | 
    
         
            -
              end
         
     | 
| 
       91 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,154 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe ISO8601::DateTime do
         
     | 
| 
       4 
     | 
    
         
            -
              it "should raise a ISO8601::Errors::UnknownPattern for any unknown pattern" do
         
     | 
| 
       5 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       6 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       7 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('20') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       8 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('201') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       9 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       10 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       11 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('20-05') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       12 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-0') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       13 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-0-09') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       14 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-1-09') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       15 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('201001-09') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       16 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('201-0109') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       17 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T103012+0400') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       18 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('20100509T10:30:12+04:00') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       19 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05T10:30:12Z') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       20 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010T10:30:12Z') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       21 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2014-W15-02T10:11:12Z') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              it "should raise a RangeError for a correct pattern but an invalid date" do
         
     | 
| 
       25 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-01-32') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       26 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-02-30') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       27 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-13-30') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       28 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-12-30T25:00:00') }.to raise_error(ISO8601::Errors::RangeError)
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
              it "should parse any allowed pattern" do
         
     | 
| 
       32 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010') }.to_not raise_error
         
     | 
| 
       33 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05') }.to_not raise_error
         
     | 
| 
       34 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09') }.to_not raise_error
         
     | 
| 
       35 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10') }.to_not raise_error
         
     | 
| 
       36 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30') }.to_not raise_error
         
     | 
| 
       37 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30:12') }.to_not raise_error
         
     | 
| 
       38 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30:12Z') }.to_not raise_error
         
     | 
| 
       39 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30:12+04') }.to_not raise_error
         
     | 
| 
       40 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30:12+04:00') }.to_not raise_error
         
     | 
| 
       41 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30:12-04:00') }.to_not raise_error
         
     | 
| 
       42 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2010-05-09T10:30:12-00:00') }.to_not raise_error
         
     | 
| 
       43 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('-2014-05-31T16:26:00Z') }.to_not raise_error
         
     | 
| 
       44 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2014-05-31T16:26:10.5Z') }.to_not raise_error
         
     | 
| 
       45 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2014-05-31T16:26:10,5Z') }.to_not raise_error
         
     | 
| 
       46 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('T10:30:12Z') }.to_not raise_error
         
     | 
| 
       47 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2014-001') }.to_not raise_error
         
     | 
| 
       48 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2014121') }.to_not raise_error
         
     | 
| 
       49 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('2014-121T10:11:12Z') }.to_not raise_error
         
     | 
| 
       50 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('20100509T103012+0400') }.to_not raise_error
         
     | 
| 
       51 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('20100509') }.to_not raise_error
         
     | 
| 
       52 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('T103012+0400') }.to_not raise_error
         
     | 
| 
       53 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('T103012+04') }.to_not raise_error
         
     | 
| 
       54 
     | 
    
         
            -
                expect { ISO8601::DateTime.new('T103012+04') }.to_not raise_error
         
     | 
| 
       55 
     | 
    
         
            -
              end
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
              context 'reduced patterns' do
         
     | 
| 
       58 
     | 
    
         
            -
                it "should parse correctly reduced dates" do
         
     | 
| 
       59 
     | 
    
         
            -
                  reduced_date = ISO8601::DateTime.new('20100509')
         
     | 
| 
       60 
     | 
    
         
            -
                  expect(reduced_date.year).to eq(2010)
         
     | 
| 
       61 
     | 
    
         
            -
                  expect(reduced_date.month).to eq(5)
         
     | 
| 
       62 
     | 
    
         
            -
                  expect(reduced_date.day).to eq(9)
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
                it "should parse correctly reduced times" do
         
     | 
| 
       65 
     | 
    
         
            -
                  reduced_time = ISO8601::DateTime.new('T101112Z')
         
     | 
| 
       66 
     | 
    
         
            -
                  expect(reduced_time.hour).to eq(10)
         
     | 
| 
       67 
     | 
    
         
            -
                  expect(reduced_time.minute).to eq(11)
         
     | 
| 
       68 
     | 
    
         
            -
                  expect(reduced_time.second).to eq(12)
         
     | 
| 
       69 
     | 
    
         
            -
                end
         
     | 
| 
       70 
     | 
    
         
            -
                it "should parse correctly reduced date times" do
         
     | 
| 
       71 
     | 
    
         
            -
                  reduced_datetime = ISO8601::DateTime.new('20140531T101112Z')
         
     | 
| 
       72 
     | 
    
         
            -
                  expect(reduced_datetime.year).to eq(2014)
         
     | 
| 
       73 
     | 
    
         
            -
                  expect(reduced_datetime.month).to eq(5)
         
     | 
| 
       74 
     | 
    
         
            -
                  expect(reduced_datetime.day).to eq(31)
         
     | 
| 
       75 
     | 
    
         
            -
                  expect(reduced_datetime.hour).to eq(10)
         
     | 
| 
       76 
     | 
    
         
            -
                  expect(reduced_datetime.minute).to eq(11)
         
     | 
| 
       77 
     | 
    
         
            -
                  expect(reduced_datetime.second).to eq(12)
         
     | 
| 
       78 
     | 
    
         
            -
                end
         
     | 
| 
       79 
     | 
    
         
            -
              end
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
              it "should return each atomic value" do
         
     | 
| 
       82 
     | 
    
         
            -
                dt = ISO8601::DateTime.new('2010-05-09T12:02:01+04:00')
         
     | 
| 
       83 
     | 
    
         
            -
                expect(dt.year).to eq(2010)
         
     | 
| 
       84 
     | 
    
         
            -
                expect(dt.month).to eq(5)
         
     | 
| 
       85 
     | 
    
         
            -
                expect(dt.day).to eq(9)
         
     | 
| 
       86 
     | 
    
         
            -
                expect(dt.hour).to eq(12)
         
     | 
| 
       87 
     | 
    
         
            -
                expect(dt.minute).to eq(2)
         
     | 
| 
       88 
     | 
    
         
            -
                expect(dt.second).to eq(1)
         
     | 
| 
       89 
     | 
    
         
            -
                expect(dt.zone).to eq('+04:00')
         
     | 
| 
       90 
     | 
    
         
            -
              end
         
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
              it "should return the right sign for the given year" do
         
     | 
| 
       93 
     | 
    
         
            -
                expect(ISO8601::DateTime.new('-2014-05-31T16:26:00Z').year).to eq(-2014)
         
     | 
| 
       94 
     | 
    
         
            -
                expect(ISO8601::DateTime.new('+2014-05-31T16:26:00Z').year).to eq(2014)
         
     | 
| 
       95 
     | 
    
         
            -
              end
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
              it "should respond to delegated casting methods" do
         
     | 
| 
       98 
     | 
    
         
            -
                dt = ISO8601::DateTime.new('2014-12-11T10:09:08Z')
         
     | 
| 
       99 
     | 
    
         
            -
                expect(dt).to respond_to(:to_s, :to_time, :to_date, :to_datetime)
         
     | 
| 
       100 
     | 
    
         
            -
              end
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
              describe '#+' do
         
     | 
| 
       103 
     | 
    
         
            -
                it "should return the result of the addition of a number" do
         
     | 
| 
       104 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20Z') + 10).to_s).to eq('2012-07-07T20:20:30+00:00')
         
     | 
| 
       105 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20.5Z') + 10).to_s).to eq('2012-07-07T20:20:30.5+00:00')
         
     | 
| 
       106 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20+02:00') + 10.09).to_s).to eq('2012-07-07T20:20:30.1+02:00')
         
     | 
| 
       107 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20+02:00') + 10.1).to_s).to eq('2012-07-07T20:20:30.1+02:00')
         
     | 
| 
       108 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20+02:00') + 10).second).to eq(30)
         
     | 
| 
       109 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20.5Z') + 10).second).to eq(30.5)
         
     | 
| 
       110 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20+02:00') + 10.09).second).to eq(30.1)
         
     | 
| 
       111 
     | 
    
         
            -
                end
         
     | 
| 
       112 
     | 
    
         
            -
              end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
              describe '#-' do
         
     | 
| 
       115 
     | 
    
         
            -
                it "should return the result of the subtraction of a number" do
         
     | 
| 
       116 
     | 
    
         
            -
                  expect((ISO8601::DateTime.new('2012-07-07T20:20:20Z') - 10).to_s).to eq('2012-07-07T20:20:10+00:00')
         
     | 
| 
       117 
     | 
    
         
            -
                end
         
     | 
| 
       118 
     | 
    
         
            -
              end
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
              describe '#to_a' do
         
     | 
| 
       121 
     | 
    
         
            -
                it "should return an array of atoms" do
         
     | 
| 
       122 
     | 
    
         
            -
                  dt = ISO8601::DateTime.new('2014-05-31T19:29:39Z').to_a
         
     | 
| 
       123 
     | 
    
         
            -
                  expect(dt).to be_kind_of(Array)
         
     | 
| 
       124 
     | 
    
         
            -
                  expect(dt).to eq([2014, 5, 31, 19, 29, 39, '+00:00'])
         
     | 
| 
       125 
     | 
    
         
            -
                end
         
     | 
| 
       126 
     | 
    
         
            -
              end
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
              describe '#hash' do
         
     | 
| 
       129 
     | 
    
         
            -
                it "should return the datetime hash" do
         
     | 
| 
       130 
     | 
    
         
            -
                  subject = ISO8601::DateTime.new('2014-08-16T20:11:10Z')
         
     | 
| 
       131 
     | 
    
         
            -
                  contrast = ISO8601::DateTime.new('2014-08-16T20:11:10Z')
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                  expect(subject.hash == contrast.hash).to be_truthy
         
     | 
| 
       134 
     | 
    
         
            -
                  expect(subject.hash).to eq(contrast.hash)
         
     | 
| 
       135 
     | 
    
         
            -
                end
         
     | 
| 
       136 
     | 
    
         
            -
              end
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
              describe '#==' do
         
     | 
| 
       139 
     | 
    
         
            -
                it "should identify loose precision datetimes" do
         
     | 
| 
       140 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014') == ISO8601::DateTime.new('2014')).to be_truthy
         
     | 
| 
       141 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014') == ISO8601::DateTime.new('2015')).to be_falsy
         
     | 
| 
       142 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10') == ISO8601::DateTime.new('2014-11')).to be_falsy
         
     | 
| 
       143 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10') == ISO8601::DateTime.new('2014-11')).to be_falsy
         
     | 
| 
       144 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10-11T12') == ISO8601::DateTime.new('2014-10-11T13')).to be_falsy
         
     | 
| 
       145 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10-11T12:13') == ISO8601::DateTime.new('2014-10-11T12:14')).to be_falsy
         
     | 
| 
       146 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10-11T12:13:10') == ISO8601::DateTime.new('2014-10-11T12:13:10.0')).to be_truthy
         
     | 
| 
       147 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10-11T12:13:10.1') == ISO8601::DateTime.new('2014-10-11T12:13:10.2')).to be_falsy
         
     | 
| 
       148 
     | 
    
         
            -
                end
         
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
                it "should identify as the same when two dates with different timezones are the same timestamp" do
         
     | 
| 
       151 
     | 
    
         
            -
                  expect(ISO8601::DateTime.new('2014-10-11T12:13:14Z') == ISO8601::DateTime.new('2014-10-11T13:13:14+01:00')).to be_truthy
         
     | 
| 
       152 
     | 
    
         
            -
                end
         
     | 
| 
       153 
     | 
    
         
            -
              end
         
     | 
| 
       154 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/iso8601/days_spec.rb
    DELETED
    
    | 
         @@ -1,44 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            RSpec.describe ISO8601::Days do
         
     | 
| 
       4 
     | 
    
         
            -
              describe 'Atomic' do
         
     | 
| 
       5 
     | 
    
         
            -
                let(:subject) { ISO8601::Days.new(1) }
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                it "should respond to the Atomic interface" do
         
     | 
| 
       8 
     | 
    
         
            -
                  expect(subject).to respond_to(:factor)
         
     | 
| 
       9 
     | 
    
         
            -
                  expect(subject).to respond_to(:to_seconds)
         
     | 
| 
       10 
     | 
    
         
            -
                  expect(subject).to respond_to(:symbol)
         
     | 
| 
       11 
     | 
    
         
            -
                  expect(subject).to respond_to(:to_i)
         
     | 
| 
       12 
     | 
    
         
            -
                  expect(subject).to respond_to(:to_f)
         
     | 
| 
       13 
     | 
    
         
            -
                  expect(subject).to respond_to(:to_s)
         
     | 
| 
       14 
     | 
    
         
            -
                  expect(subject).to respond_to(:value)
         
     | 
| 
       15 
     | 
    
         
            -
                  expect(subject).to respond_to(:<=>)
         
     | 
| 
       16 
     | 
    
         
            -
                  expect(subject).to respond_to(:eql?)
         
     | 
| 
       17 
     | 
    
         
            -
                  expect(subject).to respond_to(:hash)
         
     | 
| 
       18 
     | 
    
         
            -
                  expect(subject).to respond_to(:valid_atom?)
         
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
       20 
     | 
    
         
            -
              end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
              describe '#factor' do
         
     | 
| 
       23 
     | 
    
         
            -
                it "should return the Day factor" do
         
     | 
| 
       24 
     | 
    
         
            -
                  expect(ISO8601::Days.new(2).factor).to eq(86400)
         
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                it "should return the amount of seconds" do
         
     | 
| 
       28 
     | 
    
         
            -
                  expect(ISO8601::Days.new(2).to_seconds).to eq(172800)
         
     | 
| 
       29 
     | 
    
         
            -
                  expect(ISO8601::Days.new(-2).to_seconds).to eq(-172800)
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
              describe '#symbol' do
         
     | 
| 
       34 
     | 
    
         
            -
                it "should return the ISO symbol" do
         
     | 
| 
       35 
     | 
    
         
            -
                  expect(ISO8601::Days.new(1).symbol).to eq(:D)
         
     | 
| 
       36 
     | 
    
         
            -
                end
         
     | 
| 
       37 
     | 
    
         
            -
              end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
              describe '#hash' do
         
     | 
| 
       40 
     | 
    
         
            -
                it "should build hash identity by value" do
         
     | 
| 
       41 
     | 
    
         
            -
                  expect(ISO8601::Days.new(3).hash).to eq(ISO8601::Days.new(3).hash)
         
     | 
| 
       42 
     | 
    
         
            -
                end
         
     | 
| 
       43 
     | 
    
         
            -
              end
         
     | 
| 
       44 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,299 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'spec_helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            RSpec.describe ISO8601::Duration do
         
     | 
| 
       4 
     | 
    
         
            -
              let(:common_year) { ISO8601::DateTime.new('2010-01-01') }
         
     | 
| 
       5 
     | 
    
         
            -
              let(:leap_year) { ISO8601::DateTime.new('2000-01-01') }
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
              let(:common_february) { ISO8601::DateTime.new('2010-02-01') }
         
     | 
| 
       8 
     | 
    
         
            -
              let(:leap_february) { ISO8601::DateTime.new('2000-02-01') }
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              let(:common_november) { ISO8601::DateTime.new('2010-11-01') }
         
     | 
| 
       11 
     | 
    
         
            -
              let(:common_december) { ISO8601::DateTime.new('2010-12-01') }
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
              it "should raise a ISO8601::Errors::UnknownPattern for any unknown pattern" do
         
     | 
| 
       14 
     | 
    
         
            -
                expect { ISO8601::Duration.new('') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       15 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       16 
     | 
    
         
            -
                expect { ISO8601::Duration.new('PT') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       17 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1YT') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       18 
     | 
    
         
            -
                expect { ISO8601::Duration.new('T') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       19 
     | 
    
         
            -
                expect { ISO8601::Duration.new('PW') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       20 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1W') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       21 
     | 
    
         
            -
                expect { ISO8601::Duration.new('~P1Y') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       22 
     | 
    
         
            -
                expect { ISO8601::Duration.new('.P1Y') }.to raise_error(ISO8601::Errors::UnknownPattern)
         
     | 
| 
       23 
     | 
    
         
            -
              end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              it "should raise a ISO8601::Errors::InvalidFraction for any invalid patterns" do
         
     | 
| 
       26 
     | 
    
         
            -
                expect { ISO8601::Duration.new('PT10.5M10.5S') }.to raise_error(ISO8601::Errors::InvalidFractions)
         
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              it "should parse any allowed pattern" do
         
     | 
| 
       30 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y') }.to_not raise_error
         
     | 
| 
       31 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M') }.to_not raise_error
         
     | 
| 
       32 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1D') }.to_not raise_error
         
     | 
| 
       33 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H') }.to_not raise_error
         
     | 
| 
       34 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT0.5H') }.to_not raise_error
         
     | 
| 
       35 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT0,5H') }.to_not raise_error
         
     | 
| 
       36 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M') }.to_not raise_error
         
     | 
| 
       37 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H0.5M') }.to_not raise_error
         
     | 
| 
       38 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H0,5M') }.to_not raise_error
         
     | 
| 
       39 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S') }.to_not raise_error
         
     | 
| 
       40 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M1.0S') }.to_not raise_error
         
     | 
| 
       41 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M1,0S') }.to_not raise_error
         
     | 
| 
       42 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1W') }.to_not raise_error
         
     | 
| 
       43 
     | 
    
         
            -
                expect { ISO8601::Duration.new('+P1Y') }.to_not raise_error
         
     | 
| 
       44 
     | 
    
         
            -
                expect { ISO8601::Duration.new('-P1Y') }.to_not raise_error
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
              it "should raise a TypeError when the base is not a ISO8601::DateTime" do
         
     | 
| 
       48 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_seconds(common_year) }.to_not raise_error
         
     | 
| 
       49 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_seconds('2010-01-01') }.to raise_error(ISO8601::Errors::TypeError)
         
     | 
| 
       50 
     | 
    
         
            -
                expect { ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_seconds(2010) }.to raise_error(ISO8601::Errors::TypeError)
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              describe '#pattern' do
         
     | 
| 
       54 
     | 
    
         
            -
                it "should return the duration pattern" do
         
     | 
| 
       55 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').pattern).to eq('P1Y1M1DT1H1M1S')
         
     | 
| 
       56 
     | 
    
         
            -
                  expect(ISO8601::Duration.new(60).pattern).to eq('PT60S')
         
     | 
| 
       57 
     | 
    
         
            -
                  expect(ISO8601::Duration.new(-60).pattern).to eq('-PT60S')
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              describe '#to_s' do
         
     | 
| 
       62 
     | 
    
         
            -
                it "should return the duration as a string" do
         
     | 
| 
       63 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S').to_s).to eq('P1Y1M1DT1H1M1S')
         
     | 
| 
       64 
     | 
    
         
            -
                end
         
     | 
| 
       65 
     | 
    
         
            -
              end
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
              describe '#+' do
         
     | 
| 
       68 
     | 
    
         
            -
                it "should return the result of the addition" do
         
     | 
| 
       69 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + ISO8601::Duration.new('P1Y1M1DT1H1M1S')).to_s).to eq('P12Y2M2DT2H2M2S')
         
     | 
| 
       70 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to_s).to eq('P1Y1M1DT1H1M11S')
         
     | 
| 
       71 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S') + ISO8601::Duration.new('PT10S')).to be_an_instance_of(ISO8601::Duration)
         
     | 
| 
       72 
     | 
    
         
            -
                end
         
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
                it "should perform addition operation with Numeric class" do
         
     | 
| 
       75 
     | 
    
         
            -
                  day = 60 * 60 * 24
         
     | 
| 
       76 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + day).to_s).to eq('P11Y1M2DT1H1M1S')
         
     | 
| 
       77 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') + (2 * day).to_f).to_s).to eq('P11Y1M3DT1H1M1S')
         
     | 
| 
       78 
     | 
    
         
            -
                end
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                it "should raise ISO8601::Errors::TypeError when other object is not Numeric or ISO8601::Duration" do
         
     | 
| 
       81 
     | 
    
         
            -
                  expect { ISO8601::Duration.new('PT1H') + 'wololo' }.to raise_error(ISO8601::Errors::TypeError)
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
              describe '#-' do
         
     | 
| 
       86 
     | 
    
         
            -
                it "should return the result of the subtraction" do
         
     | 
| 
       87 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('P1Y1M1DT1H1M1S') - ISO8601::Duration.new('PT10S')).to be_an_instance_of(ISO8601::Duration)
         
     | 
| 
       88 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('PT10S')).to_s).to eq('P1Y1M1DT1H1M1S')
         
     | 
| 
       89 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P1Y1M1DT1H1M11S') - ISO8601::Duration.new('P1Y1M1DT1H1M11S')).to_s).to eq('PT0S')
         
     | 
| 
       90 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT12S')).to_s).to eq('PT0S')
         
     | 
| 
       91 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('PT12S') - ISO8601::Duration.new('PT1S')).to_s).to eq('PT11S')
         
     | 
| 
       92 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('PT12S')).to_s).to eq('-PT11S')
         
     | 
| 
       93 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('PT1S') - ISO8601::Duration.new('-PT12S')).to_s).to eq('PT13S')
         
     | 
| 
       94 
     | 
    
         
            -
                end
         
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
                it "should perform subtract operation with Numeric class" do
         
     | 
| 
       97 
     | 
    
         
            -
                  day = 60 * 60 * 24
         
     | 
| 
       98 
     | 
    
         
            -
                  minute = 60
         
     | 
| 
       99 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') - day).to_s).to eq('P11Y1MT1H1M1S')
         
     | 
| 
       100 
     | 
    
         
            -
                  expect((ISO8601::Duration.new('P11Y1M1DT1H1M1S') - (2 * minute).to_f).to_s).to eq('P11Y1M1DT59M1S')
         
     | 
| 
       101 
     | 
    
         
            -
                end
         
     | 
| 
       102 
     | 
    
         
            -
              end
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
              describe '#to_seconds' do
         
     | 
| 
       105 
     | 
    
         
            -
                context 'positive durations' do
         
     | 
| 
       106 
     | 
    
         
            -
                  it "should return the seconds of a P[n]Y duration in a common year" do
         
     | 
| 
       107 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2Y').to_seconds(common_year)).to eq(Time.utc(2012, 1) - Time.utc(2010, 1))
         
     | 
| 
       108 
     | 
    
         
            -
                  end
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
                  it "should return the seconds of a P[n]Y duration in a leap year" do
         
     | 
| 
       111 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2Y').to_seconds(leap_year)).to eq(Time.utc(2002, 1) - Time.utc(2000, 1))
         
     | 
| 
       112 
     | 
    
         
            -
                  end
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                  it "should return the seconds of a P[n]Y[n]M duration in a common year" do
         
     | 
| 
       115 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2Y3M').to_seconds(common_year)).to eq(Time.utc(2012, 4) - Time.utc(2010, 1))
         
     | 
| 
       116 
     | 
    
         
            -
                  end
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
                  it "should return the seconds of a P[n]Y[n]M duration in a leap year" do
         
     | 
| 
       119 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2Y3M').to_seconds(leap_year)).to eq(Time.utc(2002, 4) - Time.utc(2000, 1))
         
     | 
| 
       120 
     | 
    
         
            -
                  end
         
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
                  it "should return the seconds of a P[n]M duration in a common year" do
         
     | 
| 
       123 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1M').to_seconds(common_year)).to eq(2678400)
         
     | 
| 
       124 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P19M').to_seconds(ISO8601::DateTime.new('2012-05-01'))).to eq(Time.utc(2014, 12) - Time.utc(2012, 5))
         
     | 
| 
       125 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P14M').to_seconds(common_year)).to eq(Time.utc(2011, 3) - Time.utc(2010, 1))
         
     | 
| 
       126 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1M').to_seconds(common_november)).to eq(Time.utc(2010, 12) - Time.utc(2010, 11))
         
     | 
| 
       127 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1M').to_seconds(common_december)).to eq(Time.utc(2011, 1) - Time.utc(2010, 12))
         
     | 
| 
       128 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2M').to_seconds(common_november)).to eq(Time.utc(2011, 1) - Time.utc(2010, 11))
         
     | 
| 
       129 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P3M').to_seconds(common_november)).to eq(Time.utc(2011, 2) - Time.utc(2010, 11))
         
     | 
| 
       130 
     | 
    
         
            -
                  end
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
                  it "should return the seconds of a P[n]M duration in a leap year" do
         
     | 
| 
       133 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1M').to_seconds(leap_year)).to eq(Time.utc(2000, 2) - Time.utc(2000, 1))
         
     | 
| 
       134 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2M').to_seconds(leap_year)).to eq(Time.utc(2000, 3) - Time.utc(2000, 1))
         
     | 
| 
       135 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P14M').to_seconds(leap_year)).to eq(Time.utc(2001, 3) - Time.utc(2000, 1))
         
     | 
| 
       136 
     | 
    
         
            -
                  end
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
                  it "should return the seconds of a P[n]Y[n]M[n]D duration" do
         
     | 
| 
       139 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2Y11D').to_seconds(common_year)).to eq(Time.utc(2012, 1, 12) - Time.utc(2010, 1))
         
     | 
| 
       140 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1Y1M1D').to_seconds(ISO8601::DateTime.new('2010-05-01'))).to eq(Time.utc(2011, 6, 2) - Time.utc(2010, 5))
         
     | 
| 
       141 
     | 
    
         
            -
                  end
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                  it "should return the seconds of a P[n]D duration" do
         
     | 
| 
       144 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1D').to_seconds(common_year)).to eq(Time.utc(2010, 1, 2) - Time.utc(2010, 1, 1))
         
     | 
| 
       145 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P11D').to_seconds(common_year)).to eq(Time.utc(2010, 1, 12) - Time.utc(2010, 1, 1))
         
     | 
| 
       146 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P3M11D').to_seconds(common_year)).to eq(Time.utc(2010, 4, 12) - Time.utc(2010, 1))
         
     | 
| 
       147 
     | 
    
         
            -
                  end
         
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
                  it "should return the seconds of a P[n]W duration" do
         
     | 
| 
       150 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P2W').to_seconds).to eq(1209600)
         
     | 
| 
       151 
     | 
    
         
            -
                  end
         
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
                  it "should return the seconds of a PT[n]H duration" do
         
     | 
| 
       154 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('PT5H').to_seconds).to eq(18000)
         
     | 
| 
       155 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('P1YT5H').to_seconds(common_year)).to eq(Time.utc(2011, 1, 1, 5) - Time.utc(2010, 1))
         
     | 
| 
       156 
     | 
    
         
            -
                  end
         
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
                  it "should return the seconds of a PT[n]H[n]M duration" do
         
     | 
| 
       159 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('PT5M').to_seconds).to eq(60 * 5)
         
     | 
| 
       160 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('PT1H5M').to_seconds).to eq(3900)
         
     | 
| 
       161 
     | 
    
         
            -
                  end
         
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
                  it "should return the seconds of a PT[n]H[n]M duration" do
         
     | 
| 
       164 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('PT10S').to_seconds).to eq(10)
         
     | 
| 
       165 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('PT10.4S').to_seconds).to eq(10.4)
         
     | 
| 
       166 
     | 
    
         
            -
                  end
         
     | 
| 
       167 
     | 
    
         
            -
                end
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
                context 'negative durations' do
         
     | 
| 
       170 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]Y duration" do
         
     | 
| 
       171 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2Y').to_seconds(common_year)).to eq(Time.utc(2008, 1) - Time.utc(2010, 1))
         
     | 
| 
       172 
     | 
    
         
            -
                  end
         
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]Y duration in a leap year" do
         
     | 
| 
       175 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2Y').to_seconds(ISO8601::DateTime.new('2001-01-01'))).to eq(Time.utc(1999, 1) - Time.utc(2001, 1))
         
     | 
| 
       176 
     | 
    
         
            -
                  end
         
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]Y[n]M duration in a common year" do
         
     | 
| 
       179 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2Y3M').to_seconds(ISO8601::DateTime.new('2010-01-01'))).to eq(Time.utc(2007, 10) - Time.utc(2010, 1))
         
     | 
| 
       180 
     | 
    
         
            -
                  end
         
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]Y[n]M duration in a leap year" do
         
     | 
| 
       183 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2Y3M').to_seconds(ISO8601::DateTime.new('2001-01-01'))).to eq(Time.utc(1998, 10) - Time.utc(2001, 1))
         
     | 
| 
       184 
     | 
    
         
            -
                  end
         
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]M duration in a common year" do
         
     | 
| 
       187 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P1M').to_seconds(ISO8601::DateTime.new('2012-01-01'))).to eq(Time.utc(2011, 12) - Time.utc(2012, 1))
         
     | 
| 
       188 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P1M').to_seconds(ISO8601::DateTime.new('2012-02-01'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 2))
         
     | 
| 
       189 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2M').to_seconds(ISO8601::DateTime.new('2012-03-01'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 3))
         
     | 
| 
       190 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P36M').to_seconds(ISO8601::DateTime.new('2013-03-01'))).to eq(Time.utc(2010, 3) - Time.utc(2013, 3))
         
     | 
| 
       191 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P39M').to_seconds(ISO8601::DateTime.new('2013-03-01'))).to eq(Time.utc(2009, 12) - Time.utc(2013, 3))
         
     | 
| 
       192 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P156M').to_seconds(ISO8601::DateTime.new('2013-03-01'))).to eq(Time.utc(2000, 3) - Time.utc(2013, 3))
         
     | 
| 
       193 
     | 
    
         
            -
                  end
         
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]M duration in a leap year" do
         
     | 
| 
       196 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P1M').to_seconds(ISO8601::DateTime.new('2000-02-01'))).to eq(Time.utc(2000, 1) - Time.utc(2000, 2))
         
     | 
| 
       197 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2M').to_seconds(ISO8601::DateTime.new('2000-03-01'))).to eq(Time.utc(2000, 1) - Time.utc(2000, 3))
         
     | 
| 
       198 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P14M').to_seconds(ISO8601::DateTime.new('2001-03-01'))).to eq(Time.utc(2000, 1) - Time.utc(2001, 3))
         
     | 
| 
       199 
     | 
    
         
            -
                  end
         
     | 
| 
       200 
     | 
    
         
            -
             
     | 
| 
       201 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]Y[n]M[n]D duration" do
         
     | 
| 
       202 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2Y11D').to_seconds(ISO8601::DateTime.new('2014-01-12'))).to eq(Time.utc(2012, 1) - Time.utc(2014, 1, 12))
         
     | 
| 
       203 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P1Y1M1D').to_seconds(ISO8601::DateTime.new('2010-05-01'))).to eq(Time.utc(2009, 3, 31) - Time.utc(2010, 5))
         
     | 
| 
       204 
     | 
    
         
            -
                  end
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]D duration" do
         
     | 
| 
       207 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P1D').to_seconds(ISO8601::DateTime.new('2012-01-02'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 2))
         
     | 
| 
       208 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P11D').to_seconds(ISO8601::DateTime.new('2012-01-12'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 12))
         
     | 
| 
       209 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P3M11D').to_seconds(ISO8601::DateTime.new('2012-04-12'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 4, 12))
         
     | 
| 
       210 
     | 
    
         
            -
                  end
         
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
                  it "should return the seconds of a -P[n]W duration" do
         
     | 
| 
       213 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P2W').to_seconds).to eq(-1209600)
         
     | 
| 
       214 
     | 
    
         
            -
                  end
         
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
                  it "should return the seconds of a -PT[n]H duration" do
         
     | 
| 
       217 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT5H').to_seconds(ISO8601::DateTime.new('2012-01-01T05'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 5))
         
     | 
| 
       218 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-P1YT5H').to_seconds(ISO8601::DateTime.new('2013-01-01T05'))).to eq(Time.utc(2012, 1) - Time.utc(2013, 1, 1, 5))
         
     | 
| 
       219 
     | 
    
         
            -
                  end
         
     | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
                  it "should return the seconds of a -PT[n]H[n]M duration" do
         
     | 
| 
       222 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT5M').to_seconds(ISO8601::DateTime.new('2012-01-01T00:05'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 0, 5))
         
     | 
| 
       223 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT1H5M').to_seconds(ISO8601::DateTime.new('2012-01-01T01:05'))).to eq(Time.utc(2012, 1) - Time.utc(2012, 1, 1, 1, 5))
         
     | 
| 
       224 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT1H5M').to_seconds(common_year)).to eq(ISO8601::Duration.new('-PT65M').to_seconds(common_year))
         
     | 
| 
       225 
     | 
    
         
            -
                  end
         
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
                  it "should return the seconds of a -PT[n]H[n]M duration" do
         
     | 
| 
       228 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT10S').to_seconds(ISO8601::DateTime.new('2012-01-01T00:00:00'))).to eq(Time.utc(2011, 12, 31, 23, 59, 50) - Time.utc(2012, 1))
         
     | 
| 
       229 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT10.4S').to_seconds).to eq(-10.4)
         
     | 
| 
       230 
     | 
    
         
            -
                    expect(ISO8601::Duration.new('-PT10,4S').to_seconds).to eq(-10.4)
         
     | 
| 
       231 
     | 
    
         
            -
                  end
         
     | 
| 
       232 
     | 
    
         
            -
                end
         
     | 
| 
       233 
     | 
    
         
            -
              end
         
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
              describe '#abs' do
         
     | 
| 
       236 
     | 
    
         
            -
                let(:positive) { ISO8601::Duration.new('PT1H') }
         
     | 
| 
       237 
     | 
    
         
            -
                let(:negative) { ISO8601::Duration.new('-PT1H') }
         
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
                it "should return a kind of duration" do
         
     | 
| 
       240 
     | 
    
         
            -
                  expect(negative.abs).to be_instance_of(ISO8601::Duration)
         
     | 
| 
       241 
     | 
    
         
            -
                end
         
     | 
| 
       242 
     | 
    
         
            -
             
     | 
| 
       243 
     | 
    
         
            -
                it "should return the absolute value of the duration" do
         
     | 
| 
       244 
     | 
    
         
            -
                  expect(negative.abs).to eq(positive)
         
     | 
| 
       245 
     | 
    
         
            -
                end
         
     | 
| 
       246 
     | 
    
         
            -
              end
         
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
              describe '#==' do
         
     | 
| 
       249 
     | 
    
         
            -
                it "should equal by computed value" do
         
     | 
| 
       250 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H') == ISO8601::Duration.new('PT1H')).to be_truthy
         
     | 
| 
       251 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H') == ISO8601::Duration.new('PT60M')).to be_truthy
         
     | 
| 
       252 
     | 
    
         
            -
                end
         
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
                it "should equal by a Numeric value" do
         
     | 
| 
       255 
     | 
    
         
            -
                  hour = 60 * 60
         
     | 
| 
       256 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H') == hour).to be_truthy
         
     | 
| 
       257 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT2H') == hour).to be_falsy
         
     | 
| 
       258 
     | 
    
         
            -
                end
         
     | 
| 
       259 
     | 
    
         
            -
              end
         
     | 
| 
       260 
     | 
    
         
            -
             
     | 
| 
       261 
     | 
    
         
            -
              describe '#-@' do
         
     | 
| 
       262 
     | 
    
         
            -
                let(:positive) { ISO8601::Duration.new('PT1H') }
         
     | 
| 
       263 
     | 
    
         
            -
                let(:negative) { ISO8601::Duration.new('-PT1H') }
         
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
                it "should return a kind of duration" do
         
     | 
| 
       266 
     | 
    
         
            -
                  expect(-negative).to be_instance_of(ISO8601::Duration)
         
     | 
| 
       267 
     | 
    
         
            -
                end
         
     | 
| 
       268 
     | 
    
         
            -
             
     | 
| 
       269 
     | 
    
         
            -
                it "should return the negation of a positive duration" do
         
     | 
| 
       270 
     | 
    
         
            -
                  expect(-positive).to eq(negative)
         
     | 
| 
       271 
     | 
    
         
            -
                end
         
     | 
| 
       272 
     | 
    
         
            -
             
     | 
| 
       273 
     | 
    
         
            -
                it "should return the negation of a negative duration" do
         
     | 
| 
       274 
     | 
    
         
            -
                  expect(-negative).to eq(positive)
         
     | 
| 
       275 
     | 
    
         
            -
                end
         
     | 
| 
       276 
     | 
    
         
            -
              end
         
     | 
| 
       277 
     | 
    
         
            -
             
     | 
| 
       278 
     | 
    
         
            -
              describe '#eql?' do
         
     | 
| 
       279 
     | 
    
         
            -
                it "should respond to #eql?" do
         
     | 
| 
       280 
     | 
    
         
            -
                  subject = ISO8601::Duration.new('PT1H')
         
     | 
| 
       281 
     | 
    
         
            -
                  expect(subject).to respond_to(:eql?)
         
     | 
| 
       282 
     | 
    
         
            -
                end
         
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
       284 
     | 
    
         
            -
                it "should equal by hash identity" do
         
     | 
| 
       285 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H').eql?(ISO8601::Duration.new('PT1H'))).to be_truthy
         
     | 
| 
       286 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H').eql?(ISO8601::Duration.new('PT60M'))).to be_falsy
         
     | 
| 
       287 
     | 
    
         
            -
                end
         
     | 
| 
       288 
     | 
    
         
            -
              end
         
     | 
| 
       289 
     | 
    
         
            -
             
     | 
| 
       290 
     | 
    
         
            -
              describe '#hash' do
         
     | 
| 
       291 
     | 
    
         
            -
                it "should respond to #hash" do
         
     | 
| 
       292 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H')).to respond_to(:hash)
         
     | 
| 
       293 
     | 
    
         
            -
                end
         
     | 
| 
       294 
     | 
    
         
            -
             
     | 
| 
       295 
     | 
    
         
            -
                it "should build hash identity by value" do
         
     | 
| 
       296 
     | 
    
         
            -
                  expect(ISO8601::Duration.new('PT1H').hash).to eq(ISO8601::Duration.new('PT1H').hash)
         
     | 
| 
       297 
     | 
    
         
            -
                end
         
     | 
| 
       298 
     | 
    
         
            -
              end
         
     | 
| 
       299 
     | 
    
         
            -
            end
         
     |