1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
require 'date'
require File.expand_path('../../../spec_helper', __FILE__)
describe "Date#new_start" do
it "converts a date object into another with a new calendar reform" do
Date.civil(1582, 10, 14, Date::ENGLAND).new_start.should == Date.civil(1582, 10, 24)
Date.civil(1582, 10, 4, Date::ENGLAND).new_start.should == Date.civil(1582, 10, 4)
Date.civil(1582, 10, 15).new_start(Date::ENGLAND).should == Date.civil(1582, 10, 5, Date::ENGLAND)
Date.civil(1752, 9, 14).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND)
Date.civil(1752, 9, 13).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 2, Date::ENGLAND)
end
end
describe "Date#italy" do
it "converts a date object into another with the Italian calendar reform" do
Date.civil(1582, 10, 14, Date::ENGLAND).italy.should == Date.civil(1582, 10, 24)
Date.civil(1582, 10, 4, Date::ENGLAND).italy.should == Date.civil(1582, 10, 4)
end
end
describe "Date#england" do
it "converts a date object into another with the English calendar reform" do
Date.civil(1582, 10, 15).england.should == Date.civil(1582, 10, 5, Date::ENGLAND)
Date.civil(1752, 9, 14).england.should == Date.civil(1752, 9, 14, Date::ENGLAND)
Date.civil(1752, 9, 13).england.should == Date.civil(1752, 9, 2, Date::ENGLAND)
end
end
describe "Date#julian" do
it "converts a date object into another with the Julian calendar" do
Date.civil(1582, 10, 15).julian.should == Date.civil(1582, 10, 5, Date::JULIAN)
Date.civil(1752, 9, 14).julian.should == Date.civil(1752, 9, 3, Date::JULIAN)
Date.civil(1752, 9, 13).julian.should == Date.civil(1752, 9, 2, Date::JULIAN)
end
end
describe "Date#gregorian" do
it "converts a date object into another with the Gregorian calendar" do
Date.civil(1582, 10, 4).gregorian.should == Date.civil(1582, 10, 14, Date::GREGORIAN)
Date.civil(1752, 9, 14).gregorian.should == Date.civil(1752, 9, 14, Date::GREGORIAN)
end
end
ruby_version_is "" ... "1.9" do
describe "Date#ordinal_to_jd" do
it "converts an ordinal date (year-day) to a Julian day number" do
Date.ordinal_to_jd(2007, 55).should == 2454156
end
end
describe "Date#jd_to_ordinal" do
it "converts a Julian day number into an ordinal date" do
Date.jd_to_ordinal(2454156).should == [2007, 55]
end
end
describe "Date#civil_to_jd" do
it "converts a civil date into a Julian day number" do
Date.civil_to_jd(2007, 2, 24).should == 2454156
end
end
describe "Date#jd_to_civil" do
it "converts a Julian day into a civil date" do
Date.jd_to_civil(2454156).should == [2007, 2, 24]
end
end
describe "Date#commercial_to_jd" do
it "converts a commercial date (year - week - day of week) into a Julian day number" do
Date.commercial_to_jd(2007, 45, 1).should == 2454410
end
end
describe "Date#jd_to_commercial" do
it "converts a Julian day number into a commercial date" do
Date.jd_to_commercial(2454410).should == [2007, 45, 1]
end
end
describe "Date#ajd_to_jd" do
it "converts a Astronomical Julian day number into a Julian day number" do
Date.ajd_to_jd(2454410).should == [2454410, Rational(1,2)]
Date.ajd_to_jd(2454410, 1.to_r / 2).should == [2454411, 0]
end
end
describe "Date#jd_to_ajd" do
it "converts a Julian day number into a Astronomical Julian day number" do
Date.jd_to_ajd(2454410, 0).should == 2454410 - Rational(1, 2)
Date.jd_to_ajd(2454410, 1.to_r / 2).should == 2454410
end
end
describe "Date#day_fraction_to_time" do
it "converts a day fraction into time" do
Date.day_fraction_to_time(2).should == [48, 0, 0, 0]
Date.day_fraction_to_time(1).should == [24, 0, 0, 0]
Date.day_fraction_to_time(1.to_r / 2).should == [12, 0, 0, 0]
Date.day_fraction_to_time(1.to_r / 7).should == [3, 25, 42, 1.to_r / 100800]
end
end
describe "Date#time_to_day_fraction" do
it "converts a time into a day fraction" do
Date.time_to_day_fraction(48, 0, 0).should == 2
Date.time_to_day_fraction(24, 0, 0).should == 1
Date.time_to_day_fraction(12, 0, 0).should == 1.to_r / 2
Date.time_to_day_fraction(10, 20, 10).should == 10.to_r / 24 + 20.to_r / (24 * 60) + 10.to_r / (24 * 60 * 60)
end
end
describe "Date#amjd_to_ajd" do
it "converts Astronomical Modified Julian day numbers into Astronomical Julian day numbers" do
Date.amjd_to_ajd(10).should == 10 + 2400000 + 1.to_r / 2
end
end
describe "Date#ajd_to_amjd" do
it "converts Astronomical Julian day numbers into Astronomical Modified Julian day numbers" do
Date.ajd_to_amjd(10000010).should == 10000010 - 2400000 - 1.to_r / 2
end
end
describe "Date#mjd_to_jd" do
it "converts Modified Julian day numbers into Julian day numbers" do
Date.mjd_to_jd(2000).should == 2000 + 2400001
end
end
describe "Date#jd_to_mjd" do
it "converts Julian day numbers into Modified Julian day numbers" do
Date.jd_to_mjd(2500000).should == 2500000 - 2400001
end
end
describe "Date#ld_to_jd" do
it "converts the number of days since the Gregorian calendar in Italy into Julian day numbers" do
Date.ld_to_jd(450000).should == 450000 + 2299160
end
end
describe "Date#jd_to_ld" do
it "converts Julian day numbers into the number of days since the Gregorian calendar in Italy" do
Date.jd_to_ld(2450000).should == 2450000 - 2299160
end
end
describe "Date#jd_to_wday" do
it "converts a Julian day number into a week day number" do
Date.jd_to_wday(2454482).should == 3
end
end
end
|