Changeset 311 for ruby/branches


Ignore:
Timestamp:
Sep 29, 2009, 11:12:37 AM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

DvDate completed

Location:
ruby/branches/0.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/rm/data_types/quantity/date_time.rb

    r309 r311  
    6060                day = future.day - past.day
    6161              else
    62                 month -= 1
     62                month = -1
    6363                previous_month = future.month - 1
    64                 if previous_month <= 0
     64                if previous_month == 0
    6565                  previous_month = 12
    6666                end
     
    7676                year -= 1
    7777                month += future.month + 12 - past.month
     78              end
     79              if month < 0
     80                year -= 1
     81                month += 12
    7882              end
    7983              year += future.year - past.year
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_types/quantity/date_time/dv_date_spec.rb

    r310 r311  
    3131  end
    3232
    33   it 'diff should P0Y0M1W10D' do
     33  it 'diff should P0Y0M1W11D' do
    3434    diff_date = DvDate.new(:value => '2009-10-09')
    3535    @dv_date.diff(diff_date).value.should == 'P0Y0M1W11D'
    3636  end
     37
     38  it 'should process leap year' do
     39    @dv_date.value = '2004-02-28'
     40    diff_date = DvDate.new(:value => '2004-03-01')
     41    @dv_date.diff(diff_date).value.should == 'P0Y0M0W2D'
     42  end
     43
     44  it 'should process year'do
     45    diff_date = DvDate.new(:value => '2007-12-31')
     46    @dv_date.diff(diff_date).value.should == 'P1Y8M4W28D'
     47  end
     48
     49  it 'should be P0Y11M4W31D' do
     50    diff_date = DvDate.new(:value => '2008-09-30')
     51    @dv_date.diff(diff_date).value.should == 'P0Y11M4W29D'
     52  end
     53
     54  it 'should be P1Y0M0W1D' do
     55    diff_date = DvDate.new(:value => '2010-09-29')
     56    @dv_date.diff(diff_date).value.should == 'P1Y0M0W1D'
     57  end
     58
     59  it 'should be P0Y0M0W1D' do
     60    past_date = DvDate.new(:value => '2009-12-31')
     61    future_date=DvDate.new(:value => '2010-01-01')
     62    past_date.diff(future_date).value.should == 'P0Y0M0W1D'
     63  end
    3764end
Note: See TracChangeset for help on using the changeset viewer.