home_run 0.9.0
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 +140 -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 +87 -0
- data/default.mspec +12 -0
- data/ext/date/format.rb +842 -0
- data/ext/date.rb +7 -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 +138 -0
@@ -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
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime.now" do
|
4
|
+
it "should be right now as a DateTime" do
|
5
|
+
t = Time.now
|
6
|
+
d = DateTime.now
|
7
|
+
d.year.should == t.year
|
8
|
+
d.mon.should == t.mon
|
9
|
+
d.day.should == t.day
|
10
|
+
d.hour.should == t.hour
|
11
|
+
d.min.should == t.min
|
12
|
+
d.sec.should == t.sec
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should accept an optional sg value" do
|
16
|
+
DateTime.now(1).to_s.should == DateTime.now.to_s
|
17
|
+
end
|
18
|
+
end
|