home_run 0.9.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +19 -0
- data/README.rdoc +314 -0
- data/Rakefile +136 -0
- data/bench/cpu_bench.rb +279 -0
- data/bench/dt_garbage_bench.rb +11 -0
- data/bench/dt_mem_bench.rb +14 -0
- data/bench/garbage_bench.rb +11 -0
- data/bench/mem_bench.rb +14 -0
- data/bin/home_run +91 -0
- data/default.mspec +12 -0
- data/ext/1.8/date_ext.so +0 -0
- data/ext/1.9/date_ext.so +0 -0
- data/ext/date.rb +7 -0
- data/ext/date/format.rb +842 -0
- data/ext/date_ext.c +4548 -0
- data/ext/date_parser.c +367 -0
- data/ext/date_parser.rl +134 -0
- data/ext/datetime.c +2804 -0
- data/ext/extconf.rb +6 -0
- data/spec/date/accessor_spec.rb +176 -0
- data/spec/date/add_month_spec.rb +26 -0
- data/spec/date/add_spec.rb +23 -0
- data/spec/date/boat_spec.rb +38 -0
- data/spec/date/civil_spec.rb +147 -0
- data/spec/date/commercial_spec.rb +153 -0
- data/spec/date/constants_spec.rb +44 -0
- data/spec/date/conversions_spec.rb +246 -0
- data/spec/date/day_spec.rb +73 -0
- data/spec/date/downto_spec.rb +17 -0
- data/spec/date/eql_spec.rb +16 -0
- data/spec/date/format_spec.rb +52 -0
- data/spec/date/gregorian_spec.rb +52 -0
- data/spec/date/hash_spec.rb +11 -0
- data/spec/date/julian_spec.rb +129 -0
- data/spec/date/leap_spec.rb +19 -0
- data/spec/date/minus_month_spec.rb +25 -0
- data/spec/date/minus_spec.rb +51 -0
- data/spec/date/next_prev_spec.rb +108 -0
- data/spec/date/ordinal_spec.rb +83 -0
- data/spec/date/parse_spec.rb +442 -0
- data/spec/date/parsing_spec.rb +77 -0
- data/spec/date/relationship_spec.rb +28 -0
- data/spec/date/step_spec.rb +109 -0
- data/spec/date/strftime_spec.rb +223 -0
- data/spec/date/strptime_spec.rb +201 -0
- data/spec/date/succ_spec.rb +20 -0
- data/spec/date/today_spec.rb +15 -0
- data/spec/date/upto_spec.rb +17 -0
- data/spec/datetime/accessor_spec.rb +218 -0
- data/spec/datetime/add_month_spec.rb +26 -0
- data/spec/datetime/add_spec.rb +36 -0
- data/spec/datetime/boat_spec.rb +43 -0
- data/spec/datetime/constructor_spec.rb +142 -0
- data/spec/datetime/conversions_spec.rb +54 -0
- data/spec/datetime/day_spec.rb +73 -0
- data/spec/datetime/downto_spec.rb +39 -0
- data/spec/datetime/eql_spec.rb +17 -0
- data/spec/datetime/format_spec.rb +59 -0
- data/spec/datetime/hash_spec.rb +11 -0
- data/spec/datetime/leap_spec.rb +19 -0
- data/spec/datetime/minus_month_spec.rb +25 -0
- data/spec/datetime/minus_spec.rb +77 -0
- data/spec/datetime/next_prev_spec.rb +138 -0
- data/spec/datetime/now_spec.rb +18 -0
- data/spec/datetime/parse_spec.rb +390 -0
- data/spec/datetime/parsing_spec.rb +77 -0
- data/spec/datetime/relationship_spec.rb +28 -0
- data/spec/datetime/step_spec.rb +155 -0
- data/spec/datetime/strftime_spec.rb +118 -0
- data/spec/datetime/strptime_spec.rb +117 -0
- data/spec/datetime/succ_spec.rb +24 -0
- data/spec/datetime/upto_spec.rb +39 -0
- data/spec/spec_helper.rb +59 -0
- metadata +154 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime conversions" do
|
4
|
+
it "#new_offset should be a separate datetime with a modified offset" do
|
5
|
+
DateTime.new(2008, 1, 1).new_offset(0.5).to_s.should == DateTime.new(2008, 1, 1, 12, 0, 0, 0.5).to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
it "#new_offset result should be equal to the receiver" do
|
9
|
+
DateTime.new(2008, 1, 1).new_offset(0.5).should == DateTime.new(2008, 1, 1)
|
10
|
+
end
|
11
|
+
|
12
|
+
ruby_version_is "" ... "1.9" do
|
13
|
+
it "#newof should be a separate datetime with a modified offset" do
|
14
|
+
DateTime.new(2008, 1, 1).newof(0.5).to_s.should == DateTime.new(2008, 1, 1, 12, 0, 0, 0.5).to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "DateTime marshalling" do
|
20
|
+
it "should marshal and unmarshal correctly" do
|
21
|
+
Marshal.load(Marshal.dump(DateTime.jd)).should == DateTime.civil
|
22
|
+
d = DateTime.now
|
23
|
+
Marshal.load(Marshal.dump(d)).should == d
|
24
|
+
Marshal.load(Marshal.dump(DateTime.civil(2010, 2, 4, 1, 2, 4, 4/24.0))).should == DateTime.civil(2010, 2, 4, 1, 2, 4, 4/24.0)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ruby_version_is "1.9" do
|
29
|
+
describe "DateTime#to_datetime" do
|
30
|
+
it " should return the receiver" do
|
31
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).to_datetime.should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "DateTime#to_date" do
|
36
|
+
it " should return a Date with the same date as receiver" do
|
37
|
+
DateTime.new(2009, 1, 2, 12).to_date.should == Date.new(2009, 1, 2)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "DateTime#to_time" do
|
42
|
+
it " should return a Time in local time with the same year, month, day as the receiver" do
|
43
|
+
DateTime.new(2009, 1, 2, 3, 4, 5).to_time.should == Time.utc(2009, 1, 2, 3, 4, 5).getlocal
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "Time#to_datetime" do
|
48
|
+
it " should return a Date with the same year, month, and day as the receiver" do
|
49
|
+
Time.utc(2009, 1, 2, 3, 4, 5).to_datetime.should == DateTime.new(2009, 1, 2, 3, 4, 5)
|
50
|
+
Time.utc(2009, 1, 2, 3, 4, 5).getlocal.to_datetime.should == DateTime.new(2009, 1, 2, 3, 4, 5)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "DateTime#sunday?" do
|
5
|
+
it "should return true if the day is a Sunday" do
|
6
|
+
DateTime.civil(2009,1,4).sunday?.should == true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return false if the day is not a Sunday" do
|
10
|
+
DateTime.civil(2009,1,2).sunday?.should == false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "DateTime#monday?" do
|
15
|
+
it "should return true if the day is a Monday" do
|
16
|
+
DateTime.civil(2009,1,5).monday?.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return false if the day is not a Monday" do
|
20
|
+
DateTime.civil(2009,1,2).monday?.should == false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "DateTime#tuesday?" do
|
25
|
+
it "should return true if the day is a Tuesday" do
|
26
|
+
DateTime.civil(2009,1,6).tuesday?.should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return false if the day is not a Tuesday" do
|
30
|
+
DateTime.civil(2009,1,2).tuesday?.should == false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "DateTime#wednesday?" do
|
35
|
+
it "should return true if the day is a Wednesday" do
|
36
|
+
DateTime.civil(2009,1,7).wednesday?.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return false if the day is not a Tuesday" do
|
40
|
+
DateTime.civil(2009,1,2).wednesday?.should == false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "DateTime#thursday?" do
|
45
|
+
it "should return true if the day is a Thursday" do
|
46
|
+
DateTime.civil(2009,1,1).thursday?.should == true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return false if the day is not a Thursday" do
|
50
|
+
DateTime.civil(2009,1,2).thursday?.should == false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "DateTime#friday?" do
|
55
|
+
it "should return true if the day is a Friday" do
|
56
|
+
DateTime.civil(2009,1,2).friday?.should == true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return false if the day is not a Friday" do
|
60
|
+
DateTime.civil(2009,1,1).friday?.should == false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "DateTime#saturday?" do
|
65
|
+
it "should return true if the day is a Saturday" do
|
66
|
+
DateTime.civil(2009,1,3).saturday?.should == true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return false if the day is not a Saturday" do
|
70
|
+
DateTime.civil(2009,1,2).saturday?.should == false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#downto" do
|
4
|
+
|
5
|
+
it "should be able to step backward in time" do
|
6
|
+
ds = DateTime.civil(2000, 4, 14)
|
7
|
+
de = DateTime.civil(2000, 3, 29)
|
8
|
+
count = 0
|
9
|
+
ds.downto(de) do |d|
|
10
|
+
d.should <= ds
|
11
|
+
d.should >= de
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
count.should == 17
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should respect fractional days" do
|
18
|
+
ds = DateTime.civil(2000, 4, 14, 0)
|
19
|
+
de = DateTime.civil(2000, 3, 29, 12)
|
20
|
+
count = 0
|
21
|
+
ds.downto(de) do |d|
|
22
|
+
d.should <= ds
|
23
|
+
d.should >= de
|
24
|
+
count += 1
|
25
|
+
end
|
26
|
+
count.should == 16
|
27
|
+
|
28
|
+
ds = DateTime.civil(2000, 4, 14, 12)
|
29
|
+
de = DateTime.civil(2000, 3, 29, 0)
|
30
|
+
count = 0
|
31
|
+
ds.downto(de) do |d|
|
32
|
+
d.should <= ds
|
33
|
+
d.should >= de
|
34
|
+
count += 1
|
35
|
+
end
|
36
|
+
count.should == 17
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#eql?" do
|
4
|
+
it "should be able determine equality between date objects" do
|
5
|
+
DateTime.civil(2007, 10, 11).should eql(DateTime.civil(2007, 10, 11))
|
6
|
+
DateTime.civil(2007, 10, 11, 10, 11, 12, 0.5).should eql(DateTime.civil(2007, 10, 11, 10, 11, 12, 0.5))
|
7
|
+
DateTime.civil(2007, 10, 11, 10, 11, 12, 0.5).should eql(DateTime.civil(2007, 10, 12, 10, 11, 12, 0.5) - 1)
|
8
|
+
DateTime.civil(2007, 10, 11, 10, 11, 12, 0.5).should_not eql(DateTime.civil(2007, 10, 11, 10, 11, 12, 0.4))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able determine equality between a date and a datetime objects" do
|
12
|
+
DateTime.civil(2007, 10, 11).should eql(Date.civil(2007, 10, 11))
|
13
|
+
DateTime.civil(2007, 10, 11).should eql(Date.civil(2007, 10, 12) - 1)
|
14
|
+
DateTime.civil(2007, 10, 11).should_not eql(Date.civil(2007, 10, 12))
|
15
|
+
DateTime.civil(2007, 10, 11, 1).should_not eql(Date.civil(2007, 10, 11))
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime formatting methods" do
|
4
|
+
it "#asctime and #ctime should use a format similar to Time" do
|
5
|
+
DateTime.new(2008, 1, 2, 10, 20, 30).asctime.should == 'Wed Jan 2 10:20:30 2008'
|
6
|
+
DateTime.new(2008, 1, 2, 10, 20, 30).ctime.should == 'Wed Jan 2 10:20:30 2008'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#to_s should use an ISO8601 format" do
|
10
|
+
DateTime.new(2008, 1, 2, 10, 20, 30, 8/24.0).to_s.should == '2008-01-02T10:20:30+08:00'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#inspect should use an ISO8601 format" do
|
14
|
+
DateTime.new(2008, 1, 2, 10, 20, 30, 8/24.0).inspect.should == '#<DateTime 2008-01-02T10:20:30+08:00>'
|
15
|
+
end
|
16
|
+
|
17
|
+
ruby_version_is "1.9" do
|
18
|
+
it "#httpdate should use an HTTP format" do
|
19
|
+
DateTime.new(2009, 1, 2, 3, 4, 5).httpdate.should == "Fri, 02 Jan 2009 03:04:05 GMT"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "#iso8601 should use an ISO8601 format" do
|
23
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).iso8601.should == "2009-01-02T03:04:05+12:00"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "#jisx03010 should use an JIS X 0301 format" do
|
27
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "H21.01.02T03:04:05+12:00"
|
28
|
+
DateTime.new(1988, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "S63.01.02T03:04:05+12:00"
|
29
|
+
DateTime.new(1925, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "T14.01.02T03:04:05+12:00"
|
30
|
+
DateTime.new(1911, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "M44.01.02T03:04:05+12:00"
|
31
|
+
DateTime.new(1873, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "M06.01.02T03:04:05+12:00"
|
32
|
+
DateTime.new(1872, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "1872-01-02T03:04:05+12:00"
|
33
|
+
DateTime.new(1867, 1, 2, 3, 4, 5, 0.5).jisx0301.should == "1867-01-02T03:04:05+12:00"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#rfc2822 should use an RFC2822 format" do
|
37
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).rfc2822.should == "Fri, 2 Jan 2009 03:04:05 +1200"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#rfc822 should use an RFC822 format" do
|
41
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).rfc822.should == "Fri, 2 Jan 2009 03:04:05 +1200"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#rfc3339 should use an RFC3339 format" do
|
45
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).rfc3339.should == "2009-01-02T03:04:05+12:00"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#xmlschema should use an ISO8601 format" do
|
49
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).xmlschema.should == "2009-01-02T03:04:05+12:00"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should handle fractional seconds if given an argument for iso8601, jisx0301, rfc3339, and xmlschema" do
|
53
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).iso8601(4).should == "2009-01-02T03:04:05.0000+12:00"
|
54
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).jisx0301(4).should == "H21.01.02T03:04:05.0000+12:00"
|
55
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).rfc3339(4).should == "2009-01-02T03:04:05.0000+12:00"
|
56
|
+
DateTime.new(2009, 1, 2, 3, 4, 5, 0.5).xmlschema(4).should == "2009-01-02T03:04:05.0000+12:00"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#hash" do
|
4
|
+
it "should use the same hash value for equal datetimes" do
|
5
|
+
DateTime.civil(2004, 7, 12, 13, 14, 15).hash.should == DateTime.civil(2004, 7, 12, 13, 14, 15).hash
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should use a different hash value for different dates" do
|
9
|
+
DateTime.civil(2004, 7, 12, 13, 14, 15).hash.should_not == DateTime.civil(2004, 7, 12, 13, 14, 16).hash
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#leap?" do
|
4
|
+
it "should be true if the current date is a leap year and no argument is given" do
|
5
|
+
DateTime.civil(2000, 10, 11).leap?.should == true
|
6
|
+
DateTime.civil(2004, 10, 11).leap?.should == true
|
7
|
+
DateTime.civil(2008, 10, 11).leap?.should == true
|
8
|
+
DateTime.civil(1996, 10, 11).leap?.should == true
|
9
|
+
DateTime.civil(1600, 10, 11).leap?.should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be false if the current date is not a leap year and no argument is given" do
|
13
|
+
DateTime.civil(1700, 10, 11).leap?.should == false
|
14
|
+
DateTime.civil(1800, 10, 11).leap?.should == false
|
15
|
+
DateTime.civil(1900, 10, 11).leap?.should == false
|
16
|
+
DateTime.civil(1999, 10, 11).leap?.should == false
|
17
|
+
DateTime.civil(2001, 10, 11).leap?.should == false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#<<" do
|
4
|
+
|
5
|
+
it "should substract a number of months from a date" do
|
6
|
+
(DateTime.civil(2007, 12, 27) << 10).should == DateTime.civil(2007,2,27)
|
7
|
+
(DateTime.commercial(2007, 45, 5) << 10).should == DateTime.commercial(2007,2,2)
|
8
|
+
(DateTime.jd(2455086) << 10).should == DateTime.jd(2454782)
|
9
|
+
(DateTime.ordinal(2008, 315) << 10).should == DateTime.ordinal(2008, 10)
|
10
|
+
(DateTime.civil(2007, 12, 27) << 12).should == DateTime.civil(2006,12,27)
|
11
|
+
(DateTime.civil(2007, 12, 27) << -12).should == DateTime.civil(2008,12,27)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should result in the last day of a month if the day doesn't exist" do
|
15
|
+
d = DateTime.civil(2008,3,31) << 1
|
16
|
+
d.should == DateTime.civil(2008, 2, 29)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an error on non numeric parameters" do
|
20
|
+
lambda { DateTime.civil(2007,2,27) << "hello" }.should raise_error(TypeError)
|
21
|
+
lambda { DateTime.civil(2007,2,27) << DateTime.new }.should raise_error(TypeError)
|
22
|
+
lambda { DateTime.civil(2007,2,27) << Object.new }.should raise_error(TypeError)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#-" do
|
4
|
+
|
5
|
+
it "should substract a number of days from a DateTime" do
|
6
|
+
(DateTime.civil(2008, 1, 8) - 315).should == DateTime.civil(2007,2,27)
|
7
|
+
(DateTime.commercial(2007, 47, 2) - 315).should == DateTime.commercial(2007,2,2)
|
8
|
+
(DateTime.jd(2455097) - 315).should == DateTime.jd(2454782)
|
9
|
+
(DateTime.ordinal(2008, 325) - 315).should == DateTime.ordinal(2008, 10)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should subtract a fractional number of days to a Date" do
|
13
|
+
(DateTime.civil(2008, 1, 8, 12) - 315.5).should == DateTime.civil(2007,2,27)
|
14
|
+
(DateTime.commercial(2007, 47, 2, 18) - 315.75).should == DateTime.commercial(2007,2,2)
|
15
|
+
(DateTime.jd(2455097, 6) - 315.25).should == DateTime.jd(2454782)
|
16
|
+
(DateTime.ordinal(2008, 325, 6) - 315.25).should == DateTime.ordinal(2008, 10)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should substract a negative number of days from a DateTime" do
|
20
|
+
d = DateTime.civil(2007, 4, 19).-(-13)
|
21
|
+
d.should == DateTime.civil(2007, 5 ,2)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should subtract a fractional negative number of days to a Date" do
|
25
|
+
d = DateTime.civil(2007, 2, 16, 12).-(-10.5)
|
26
|
+
d.should == DateTime.civil(2007,2,27)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to compute the different between two DateTimes" do
|
30
|
+
(DateTime.civil(2007,2,27) - DateTime.civil(2007,2,27)).should be_close(0.0, 0.00000001)
|
31
|
+
(DateTime.civil(2007,2,27) - DateTime.civil(2007,2,26)).should be_close(1.0, 0.00000001)
|
32
|
+
(DateTime.civil(2006,2,27) - DateTime.civil(2007,2,27)).should be_close(-365.0, 0.00000001)
|
33
|
+
(DateTime.civil(2008,2,27) - DateTime.civil(2007,2,27)).should be_close(365.0, 0.00000001)
|
34
|
+
(DateTime.civil(2009,2,27) - DateTime.civil(2008,2,27)).should be_close(366.0, 0.00000001)
|
35
|
+
|
36
|
+
(DateTime.civil(2009,2,27) - DateTime.commercial(2008,2,1)).should be_close(417.0, 0.00000001)
|
37
|
+
(DateTime.civil(2009,2,27) - DateTime.jd(2454782)).should be_close(108.0, 0.00000001)
|
38
|
+
(DateTime.civil(2009,2,27) - DateTime.ordinal(2008, 10)).should be_close(414.0, 0.00000001)
|
39
|
+
|
40
|
+
(DateTime.commercial(2008,2,1) - DateTime.civil(2008,2,27)).should be_close(-51.0, 0.00000001)
|
41
|
+
(DateTime.commercial(2008,2,1) - DateTime.jd(2454782)).should be_close(-309.0, 0.00000001)
|
42
|
+
(DateTime.commercial(2008,2,1) - DateTime.ordinal(2008, 10)).should be_close(-3.0, 0.00000001)
|
43
|
+
|
44
|
+
(DateTime.jd(2454782) - DateTime.commercial(2008,2,1)).should be_close(309.0, 0.00000001)
|
45
|
+
(DateTime.jd(2454782) - DateTime.civil(2009,2,27)).should be_close(-108.0, 0.00000001)
|
46
|
+
(DateTime.jd(2454782) - DateTime.ordinal(2008, 10)).should be_close(306.0, 0.00000001)
|
47
|
+
|
48
|
+
(DateTime.ordinal(2008, 10) - DateTime.commercial(2008,2,1)).should be_close(3.0, 0.00000001)
|
49
|
+
(DateTime.ordinal(2008, 10) - DateTime.jd(2454782)).should be_close(-306.0, 0.00000001)
|
50
|
+
(DateTime.ordinal(2008, 10) - DateTime.civil(2009,2,27)).should be_close(-414.0, 0.00000001)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should consider the offset when computing the different between two DateTimes" do
|
54
|
+
(DateTime.civil(2007,2,27, 0, 0, 0, 0.5) - DateTime.civil(2007,2,27,0,0,0)).should be_close(-0.5, 0.00000001)
|
55
|
+
(DateTime.civil(2007,2,27, 0, 0, 0, -0.5) - DateTime.civil(2007,2,27,12,0,0)).should be_close(0.0, 0.00000001)
|
56
|
+
(DateTime.civil(2007,2,27,0,0,0,-0.5) - DateTime.civil(2007,2,27,0,0,0,0.5)).should be_close(1.0, 0.00000001)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be able to subtract a Date from a DateTime" do
|
60
|
+
(DateTime.ordinal(2008, 10) - Date.commercial(2008,2,1)).should be_close(3.0, 0.00000001)
|
61
|
+
(DateTime.ordinal(2008, 10) - Date.jd(2454782)).should be_close(-306.0, 0.00000001)
|
62
|
+
(DateTime.ordinal(2008, 10) - Date.civil(2009,2,27)).should be_close(-414.0, 0.00000001)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should assume a Date is in the same offset as the receiver" do
|
66
|
+
(DateTime.ordinal(2008, 10, 0, 0, 0, 0.5) - Date.commercial(2008,2,1)).should be_close(3.0, 0.00000001)
|
67
|
+
(DateTime.ordinal(2008, 10, 0, 0, 0, 0.1) - Date.jd(2454782)).should be_close(-306.0, 0.00000001)
|
68
|
+
(DateTime.ordinal(2008, 10, 0, 0, 0, -0.5) - Date.civil(2009,2,27)).should be_close(-414.0, 0.00000001)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should raise an error on non numeric parameters" do
|
72
|
+
lambda { DateTime.civil(2007,2,27) - :hello }.should raise_error(TypeError)
|
73
|
+
lambda { DateTime.civil(2007,2,27) - "hello" }.should raise_error(TypeError)
|
74
|
+
lambda { DateTime.civil(2007,2,27) - Object.new }.should raise_error(TypeError)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "DateTime#next_day" do
|
5
|
+
it "should add a single day to a DateTime if no arguments" do
|
6
|
+
(DateTime.civil(2007,2,27).next_day).should == DateTime.civil(2007, 2, 28)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add the given number of days to a DateTime if an argument" do
|
10
|
+
(DateTime.civil(2007,2,27).next_day(2)).should == DateTime.civil(2007, 3, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle a negative argument by subtracting days" do
|
14
|
+
(DateTime.civil(2007,2,27).next_day(-2)).should == DateTime.civil(2007, 2, 25)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should keep the same fractional part and offset" do
|
18
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_day).day_fraction.should == 0.5
|
19
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_day).offset.should == 0.5
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "DateTime#prev_day" do
|
24
|
+
it "should subtract a single day to a DateTime if no arguments" do
|
25
|
+
(DateTime.civil(2007,2,27).prev_day).should == DateTime.civil(2007, 2, 26)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should subtract the given number of days to a DateTime if an argument" do
|
29
|
+
(DateTime.civil(2007,2,27).prev_day(2)).should == DateTime.civil(2007, 2, 25)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should handle a negative argument by adding days" do
|
33
|
+
(DateTime.civil(2007,2,27).prev_day(-2)).should == DateTime.civil(2007, 3, 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should keep the same fractional part and offset" do
|
37
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_day).day_fraction.should == 0.5
|
38
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_day).offset.should == 0.5
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "DateTime#next_month" do
|
43
|
+
it "should add a single month to a DateTime if no arguments" do
|
44
|
+
(DateTime.civil(2007,2,27).next_month).should == DateTime.civil(2007, 3, 27)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should add the given number of months to a DateTime if an argument" do
|
48
|
+
(DateTime.civil(2007,2,27).next_month(2)).should == DateTime.civil(2007, 4, 27)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should handle a negative argument by subtracting months" do
|
52
|
+
(DateTime.civil(2007,2,27).next_month(-2)).should == DateTime.civil(2006, 12, 27)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should handle adding a month where the new date is not a valid date" do
|
56
|
+
(DateTime.civil(2007,1,31).next_month).should == DateTime.civil(2007, 2, 28)
|
57
|
+
(DateTime.civil(2008,1,31).next_month).should == DateTime.civil(2008, 2, 29)
|
58
|
+
(DateTime.civil(2007,1,31).next_month(3)).should == DateTime.civil(2007, 4, 30)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should keep the same fractional part and offset" do
|
62
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_month).day_fraction.should == 0.5
|
63
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_month).offset.should == 0.5
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "DateTime#prev_month" do
|
68
|
+
it "should subtract a single month to a DateTime if no arguments" do
|
69
|
+
(DateTime.civil(2007,2,27).prev_month).should == DateTime.civil(2007, 1, 27)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should subtract the given number of months to a DateTime if an argument" do
|
73
|
+
(DateTime.civil(2007,2,27).prev_month(2)).should == DateTime.civil(2006, 12, 27)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should handle a negative argument by adding months" do
|
77
|
+
(DateTime.civil(2007,2,27).prev_month(-2)).should == DateTime.civil(2007, 4, 27)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should handle subtracting a month where the new date is not a valid date" do
|
81
|
+
(DateTime.civil(2007,3,31).prev_month).should == DateTime.civil(2007, 2, 28)
|
82
|
+
(DateTime.civil(2008,3,31).prev_month).should == DateTime.civil(2008, 2, 29)
|
83
|
+
(DateTime.civil(2007,3,31).prev_month(4)).should == DateTime.civil(2006, 11, 30)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should keep the same fractional part and offset" do
|
87
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_month).day_fraction.should == 0.5
|
88
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_month).offset.should == 0.5
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "DateTime#next_year" do
|
93
|
+
it "should add a single year to a DateTime if no arguments" do
|
94
|
+
(DateTime.civil(2007,2,27).next_year).should == DateTime.civil(2008, 2, 27)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should add the given number of years to a DateTime if an argument" do
|
98
|
+
(DateTime.civil(2007,2,27).next_year(2)).should == DateTime.civil(2009, 2, 27)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should handle a negative argument by subtracting years" do
|
102
|
+
(DateTime.civil(2007,2,27).next_year(-2)).should == DateTime.civil(2005, 2, 27)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should handle adding a year where the new date is not a valid date" do
|
106
|
+
(DateTime.civil(2008,2,29).next_year).should == DateTime.civil(2009, 2, 28)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should keep the same fractional part and offset" do
|
110
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_year).day_fraction.should == 0.5
|
111
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_year).offset.should == 0.5
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "DateTime#prev_year" do
|
116
|
+
it "should add a single year to a DateTime if no arguments" do
|
117
|
+
(DateTime.civil(2007,2,27).prev_year).should == DateTime.civil(2006, 2, 27)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should add the given number of years to a DateTime if an argument" do
|
121
|
+
(DateTime.civil(2007,2,27).prev_year(2)).should == DateTime.civil(2005, 2, 27)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should handle a negative argument by subtracting years" do
|
125
|
+
(DateTime.civil(2007,2,27).prev_year(-2)).should == DateTime.civil(2009, 2, 27)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should handle adding a year where the new date is not a valid date" do
|
129
|
+
(DateTime.civil(2008,2,29).prev_year).should == DateTime.civil(2007, 2, 28)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should keep the same fractional part and offset" do
|
133
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_year).day_fraction.should == 0.5
|
134
|
+
(DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_year).offset.should == 0.5
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|