home_run 0.9.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/CHANGELOG +3 -0
  2. data/LICENSE +19 -0
  3. data/README.rdoc +314 -0
  4. data/Rakefile +136 -0
  5. data/bench/cpu_bench.rb +279 -0
  6. data/bench/dt_garbage_bench.rb +11 -0
  7. data/bench/dt_mem_bench.rb +14 -0
  8. data/bench/garbage_bench.rb +11 -0
  9. data/bench/mem_bench.rb +14 -0
  10. data/bin/home_run +91 -0
  11. data/default.mspec +12 -0
  12. data/ext/1.8/date_ext.so +0 -0
  13. data/ext/1.9/date_ext.so +0 -0
  14. data/ext/date.rb +7 -0
  15. data/ext/date/format.rb +842 -0
  16. data/ext/date_ext.c +4548 -0
  17. data/ext/date_parser.c +367 -0
  18. data/ext/date_parser.rl +134 -0
  19. data/ext/datetime.c +2804 -0
  20. data/ext/extconf.rb +6 -0
  21. data/spec/date/accessor_spec.rb +176 -0
  22. data/spec/date/add_month_spec.rb +26 -0
  23. data/spec/date/add_spec.rb +23 -0
  24. data/spec/date/boat_spec.rb +38 -0
  25. data/spec/date/civil_spec.rb +147 -0
  26. data/spec/date/commercial_spec.rb +153 -0
  27. data/spec/date/constants_spec.rb +44 -0
  28. data/spec/date/conversions_spec.rb +246 -0
  29. data/spec/date/day_spec.rb +73 -0
  30. data/spec/date/downto_spec.rb +17 -0
  31. data/spec/date/eql_spec.rb +16 -0
  32. data/spec/date/format_spec.rb +52 -0
  33. data/spec/date/gregorian_spec.rb +52 -0
  34. data/spec/date/hash_spec.rb +11 -0
  35. data/spec/date/julian_spec.rb +129 -0
  36. data/spec/date/leap_spec.rb +19 -0
  37. data/spec/date/minus_month_spec.rb +25 -0
  38. data/spec/date/minus_spec.rb +51 -0
  39. data/spec/date/next_prev_spec.rb +108 -0
  40. data/spec/date/ordinal_spec.rb +83 -0
  41. data/spec/date/parse_spec.rb +442 -0
  42. data/spec/date/parsing_spec.rb +77 -0
  43. data/spec/date/relationship_spec.rb +28 -0
  44. data/spec/date/step_spec.rb +109 -0
  45. data/spec/date/strftime_spec.rb +223 -0
  46. data/spec/date/strptime_spec.rb +201 -0
  47. data/spec/date/succ_spec.rb +20 -0
  48. data/spec/date/today_spec.rb +15 -0
  49. data/spec/date/upto_spec.rb +17 -0
  50. data/spec/datetime/accessor_spec.rb +218 -0
  51. data/spec/datetime/add_month_spec.rb +26 -0
  52. data/spec/datetime/add_spec.rb +36 -0
  53. data/spec/datetime/boat_spec.rb +43 -0
  54. data/spec/datetime/constructor_spec.rb +142 -0
  55. data/spec/datetime/conversions_spec.rb +54 -0
  56. data/spec/datetime/day_spec.rb +73 -0
  57. data/spec/datetime/downto_spec.rb +39 -0
  58. data/spec/datetime/eql_spec.rb +17 -0
  59. data/spec/datetime/format_spec.rb +59 -0
  60. data/spec/datetime/hash_spec.rb +11 -0
  61. data/spec/datetime/leap_spec.rb +19 -0
  62. data/spec/datetime/minus_month_spec.rb +25 -0
  63. data/spec/datetime/minus_spec.rb +77 -0
  64. data/spec/datetime/next_prev_spec.rb +138 -0
  65. data/spec/datetime/now_spec.rb +18 -0
  66. data/spec/datetime/parse_spec.rb +390 -0
  67. data/spec/datetime/parsing_spec.rb +77 -0
  68. data/spec/datetime/relationship_spec.rb +28 -0
  69. data/spec/datetime/step_spec.rb +155 -0
  70. data/spec/datetime/strftime_spec.rb +118 -0
  71. data/spec/datetime/strptime_spec.rb +117 -0
  72. data/spec/datetime/succ_spec.rb +24 -0
  73. data/spec/datetime/upto_spec.rb +39 -0
  74. data/spec/spec_helper.rb +59 -0
  75. metadata +154 -0
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "DateTime#===" do
4
+
5
+ it "should be true for the two same dates" do
6
+ (DateTime.civil(2000, 04, 06) === DateTime.civil(2000, 04, 06)).should == true
7
+ end
8
+
9
+ it "should be true if comparison is a Date on the same date" do
10
+ (DateTime.civil(2000, 04, 06, 10) === Date.civil(2000, 04, 06)).should == true
11
+ end
12
+
13
+ it "should be true if comparison is a Numeric with the same integer value as JD" do
14
+ (DateTime.civil(2000, 04, 06) === DateTime.civil(2000, 04, 06).jd).should == true
15
+ end
16
+
17
+ it "should be false for different dates" do
18
+ (DateTime.civil(2000, 04, 05) === DateTime.civil(2000, 04, 06)).should == false
19
+ end
20
+
21
+ it "should be false if comparison is a Date with a different date" do
22
+ (DateTime.civil(2000, 04, 06, 10) === Date.civil(2000, 04, 07)).should == false
23
+ end
24
+
25
+ it "should be false if comparison is a Numeric with the different integer value as JD" do
26
+ (DateTime.civil(2000, 04, 06) === DateTime.civil(2000, 04, 07).jd).should == false
27
+ end
28
+ end
@@ -0,0 +1,155 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "DateTime#step" do
4
+
5
+ it "should be able to step forward in time" do
6
+ ds = DateTime.civil(2008, 10, 11)
7
+ de = DateTime.civil(2008, 9, 29)
8
+ count = 0
9
+ de.step(ds) do |d|
10
+ d.should <= ds
11
+ d.should >= de
12
+ count += 1
13
+ end.should == de
14
+ count.should == 13
15
+
16
+ count = 0
17
+ de.step(ds, 5) do |d|
18
+ d.should <= ds
19
+ d.should >= de
20
+ count += 1
21
+ end.should == de
22
+ count.should == 3
23
+
24
+ count = 0
25
+ de.step(ds, 0.25) do |d|
26
+ d.should <= ds
27
+ d.should >= de
28
+ count += 1
29
+ end.should == de
30
+ count.should == 49
31
+
32
+ count = 0
33
+ ds.step(de) do |d|; count += 1; end.should == ds
34
+ count.should == 0
35
+
36
+ end
37
+
38
+ it "should be able to step backward in time" do
39
+ ds = DateTime.civil(2000, 4, 14)
40
+ de = DateTime.civil(2000, 3, 29)
41
+ count = 0
42
+ ds.step(de, -1) do |d|
43
+ d.should <= ds
44
+ d.should >= de
45
+ count += 1
46
+ end.should == ds
47
+ count.should == 17
48
+
49
+ count = 0
50
+ ds.step(de, -5) do |d|
51
+ d.should <= ds
52
+ d.should >= de
53
+ count += 1
54
+ end.should == ds
55
+ count.should == 4
56
+
57
+ count = 0
58
+ ds.step(de, -0.25) do |d|
59
+ d.should <= ds
60
+ d.should >= de
61
+ count += 1
62
+ end.should == ds
63
+ count.should == 65
64
+
65
+ count = 0
66
+ de.step(ds, -1) do |d|; count += 1; end.should == de
67
+ count.should == 0
68
+
69
+ end
70
+
71
+ it "should yield once if the dates are the same, regardless of step" do
72
+ ds = DateTime.civil(2008, 10, 11)
73
+ count = 0
74
+ ds.step(ds, 1) do |d|
75
+ d.should == ds
76
+ count += 1
77
+ end.should == ds
78
+ count.should == 1
79
+
80
+ count = 0
81
+ ds.step(ds, 0) do |d|
82
+ d.should == ds
83
+ count += 1
84
+ end.should == ds
85
+ count.should == 1
86
+
87
+ count = 0
88
+ ds.step(ds, -1) do |d|
89
+ d.should == ds
90
+ count += 1
91
+ end.should == ds
92
+ count.should == 1
93
+ end
94
+
95
+ it "should not yield if the target date is greater than the receiver, and step is not positive" do
96
+ ds = DateTime.civil(2008, 10, 11)
97
+ count = 0
98
+ ds.step(ds.next, 0) do |d|
99
+ count += 1
100
+ end.should == ds
101
+ count.should == 0
102
+
103
+ count = 0
104
+ ds.step(ds.next, -1) do |d|
105
+ count += 1
106
+ end.should == ds
107
+ count.should == 0
108
+ end
109
+
110
+ it "should not yield if the target date is less than the receiver, and step is not negative" do
111
+ ds = DateTime.civil(2008, 10, 11)
112
+ count = 0
113
+ ds.next.step(ds, 0) do |d|
114
+ count += 1
115
+ end.should == ds.next
116
+ count.should == 0
117
+
118
+ count = 0
119
+ ds.next.step(ds, 1) do |d|
120
+ count += 1
121
+ end.should == ds.next
122
+ count.should == 0
123
+ end
124
+
125
+ it "should correctly handle offsets" do
126
+ ds = DateTime.civil(2008, 10, 11)
127
+ de = DateTime.civil(2008, 10, 11, 0, 0, 0, 0.5)
128
+
129
+ count = 0
130
+ ds.step(de, 0.25) do |d|
131
+ count += 1
132
+ end.should == ds
133
+ count.should == 0
134
+
135
+ count = 0
136
+ ds.step(de, -0.25) do |d|
137
+ count += 1
138
+ end.should == ds
139
+ count.should == 3
140
+
141
+ count = 0
142
+ de.step(ds, -0.25) do |d|
143
+ count += 1
144
+ end.should == de
145
+ count.should == 0
146
+
147
+ count = 0
148
+ de.step(ds, 0.25) do |d|
149
+ count += 1
150
+ end.should == de
151
+ count.should == 3
152
+
153
+ end
154
+
155
+ end
@@ -0,0 +1,118 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "DateTime#strftime" do
4
+
5
+ it "should be able to print the date time" do
6
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime.should == "2000-04-06T10:11:12+00:00"
7
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime.should == DateTime.civil(2000, 4, 6, 10, 11, 12).to_s
8
+ end
9
+
10
+ it "should be able to print the hour in a 24 hour clock with leading zero" do
11
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%H').should == "10"
12
+ DateTime.civil(2000, 4, 6, 13, 11, 12).strftime('%H').should == "13"
13
+ end
14
+
15
+ it "should be able to print the hour in a 12 hour clock with leading zero" do
16
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%I').should == "10"
17
+ DateTime.civil(2000, 4, 6, 13, 11, 12).strftime('%I').should == "01"
18
+ end
19
+
20
+ it "should be able to print the hour in a 24 hour clock with leading space" do
21
+ DateTime.civil(2000, 4, 6, 9, 11, 12).strftime('%k').should == " 9"
22
+ DateTime.civil(2000, 4, 6, 13, 11, 12).strftime('%k').should == "13"
23
+ end
24
+
25
+ it "should be able to print the hour in a 12 hour clock with leading space" do
26
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%l').should == "10"
27
+ DateTime.civil(2000, 4, 6, 13, 11, 12).strftime('%l').should == " 1"
28
+ end
29
+
30
+ it "should be able to print the number of milliseconds of the second" do
31
+ DateTime.civil(2008, 11, 12, 14, 3, 30, -8/24.0).strftime('%L').should == "000"
32
+ (DateTime.civil(2008, 11, 12, 14, 3, 31, 8/24.0) + (0.5/86400)).strftime('%L').should == "500"
33
+ end
34
+
35
+ it "should be able to print the minute with leading zero" do
36
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%M').should == "11"
37
+ DateTime.civil(2000, 4, 6, 10, 14, 12).strftime('%M').should == "14"
38
+ end
39
+
40
+ it "should be able to print the number of nanoseconds of the second" do
41
+ DateTime.civil(2008, 11, 12, 14, 3, 30, -8/24.0).strftime('%N').should == "000000000"
42
+ (DateTime.civil(2008, 11, 12, 14, 3, 31, 8/24.0) + (0.5/86400)).strftime('%N').should == "500000000"
43
+ end
44
+
45
+ it "should be able to print the meridian indicator in lower case" do
46
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%P').should == "am"
47
+ DateTime.civil(2000, 4, 6, 13, 11, 12).strftime('%P').should == "pm"
48
+ end
49
+
50
+ it "should be able to print the meridian indicator in upper case" do
51
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%p').should == "AM"
52
+ DateTime.civil(2000, 4, 6, 13, 11, 12).strftime('%p').should == "PM"
53
+ end
54
+
55
+ it "should be able to print the number of milliseconds since the unix epoch" do
56
+ DateTime.civil(2008, 11, 12, 14, 3, 30, -8/24.0).strftime('%Q').should == "1226527410000"
57
+ (DateTime.civil(2008, 11, 12, 14, 3, 31, 8/24.0) + (0.5/86400)).strftime('%Q').should == "1226469811500"
58
+ end
59
+
60
+ it "should be able to print the second with leading zero" do
61
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%S').should == "12"
62
+ DateTime.civil(2000, 4, 6, 10, 11, 13).strftime('%S').should == "13"
63
+ end
64
+
65
+ it "should be able to print the number of seconds since the unix epoch" do
66
+ DateTime.civil(2008, 11, 12, 14, 3, 30, -8/24.0).strftime('%s').should == "1226527410"
67
+ DateTime.civil(2008, 11, 12, 14, 3, 31, 8/24.0).strftime('%s').should == "1226469811"
68
+ end
69
+
70
+ it "should be able to print the time zone offset as a string of hours and minutes" do
71
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%z').should == "+0000"
72
+ DateTime.civil(2000, 4, 6, 10, 11, 12, -0.5).strftime('%z').should == "-1200"
73
+ DateTime.civil(2000, 4, 6, 10, 11, 12, 0.5).strftime('%z').should == "+1200"
74
+ DateTime.civil(2000, 4, 6, 10, 11, 12, -1/24.0).strftime('%z').should == "-0100"
75
+ DateTime.civil(2000, 4, 6, 10, 11, 12, 1/24.0).strftime('%z').should == "+0100"
76
+
77
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%Z').should == "+00:00"
78
+ DateTime.civil(2000, 4, 6, 10, 11, 12, -0.5).strftime('%Z').should == "-12:00"
79
+ DateTime.civil(2000, 4, 6, 10, 11, 12, 0.5).strftime('%Z').should == "+12:00"
80
+ DateTime.civil(2000, 4, 6, 10, 11, 12, -1/24.0).strftime('%Z').should == "-01:00"
81
+ DateTime.civil(2000, 4, 6, 10, 11, 12, 1/24.0).strftime('%Z').should == "+01:00"
82
+ end
83
+
84
+ ############################
85
+ # Specs that combine stuff #
86
+ ############################
87
+
88
+ it "should be able to print the common date" do
89
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime("%c").should == "Thu Apr 6 10:11:12 2000"
90
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime("%c").should == DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%a %b %e %H:%M:%S %Y')
91
+ end
92
+
93
+ it "should be able to print the hour and minute" do
94
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime("%R").should == "10:11"
95
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime("%R").should == DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%H:%M')
96
+ end
97
+
98
+ it "should be able to show the hour, minute, second, and am/pm flag" do
99
+ DateTime.civil(2000, 4, 9, 10, 11, 12).strftime("%r").should == "10:11:12 AM"
100
+ DateTime.civil(2000, 4, 9, 13, 11, 12).strftime("%r").should == " 1:11:12 PM"
101
+ DateTime.civil(2000, 4, 9, 10, 11, 12).strftime("%r").should == DateTime.civil(2000, 4, 9, 10, 11, 12).strftime('%I:%M:%S %p')
102
+ end
103
+
104
+ it "should be able to show the hour, minute, and second" do
105
+ DateTime.civil(2000, 4, 9, 10, 11, 12).strftime("%T").should == "10:11:12"
106
+ DateTime.civil(2000, 4, 9, 13, 11, 12).strftime("%T").should == "13:11:12"
107
+ DateTime.civil(2000, 4, 9, 10, 11, 12).strftime("%T").should == DateTime.civil(2000, 4, 9, 10, 11, 12).strftime('%H:%M:%S')
108
+ DateTime.civil(2000, 4, 9, 10, 11, 12).strftime("%X").should == "10:11:12"
109
+ DateTime.civil(2000, 4, 9, 13, 11, 12).strftime("%X").should == "13:11:12"
110
+ DateTime.civil(2000, 4, 9, 10, 11, 12).strftime("%X").should == DateTime.civil(2000, 4, 9, 10, 11, 12).strftime('%H:%M:%S')
111
+ end
112
+
113
+ it "should be able to print the common date and timezone" do
114
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime("%+").should == "Thu Apr 6 10:11:12 +00:00 2000"
115
+ DateTime.civil(2000, 4, 6, 10, 11, 12, 0.5).strftime("%+").should == "Thu Apr 6 10:11:12 +12:00 2000"
116
+ DateTime.civil(2000, 4, 6, 10, 11, 12).strftime("%+").should == DateTime.civil(2000, 4, 6, 10, 11, 12).strftime('%a %b %e %H:%M:%S %Z %Y')
117
+ end
118
+ end
@@ -0,0 +1,117 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "DateTime.strptime" do
4
+ before do
5
+ @t = Time.now
6
+ end
7
+
8
+ it "._strptime should be a hash of values" do
9
+ DateTime._strptime('2008-10-11T01:00:02+0000').should == {:offset=>0, :zone=>"+0000", :sec=>2, :year=>2008, :hour=>1, :mday=>11, :min=>0, :mon=>10}
10
+ DateTime._strptime('2008-10-11', '%Y-%m-%d').should == {:year=>2008, :mon=>10, :mday=>11}
11
+ end
12
+
13
+ it "should have defaults and an optional sg value" do
14
+ DateTime.strptime('2008-10-11T00:00:00+00:00').should == DateTime.civil(2008, 10, 11)
15
+ DateTime.strptime('2008-10-11', '%Y-%m-%d').should == DateTime.civil(2008, 10, 11)
16
+ DateTime.strptime('2008-10-11', '%Y-%m-%d', 1).should == DateTime.civil(2008, 10, 11)
17
+ DateTime.strptime.should == DateTime.jd
18
+ end
19
+
20
+ it "should be able to parse the date time" do
21
+ DateTime.strptime("2000-04-06T10:11:12+00:00").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
22
+ end
23
+
24
+ it "should be able to parse the hour in a 24 hour clock with leading zero" do
25
+ DateTime.strptime("10", '%H').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
26
+ DateTime.strptime("09", '%H').should == DateTime.civil(@t.year, @t.mon, @t.day, 9, 0, 0)
27
+ DateTime.strptime("2000 16", '%Y %H').should == DateTime.civil(2000, 1, 1, 16, 0, 0)
28
+ end
29
+
30
+ it "should be able to parse the hour in a 12 hour clock with leading zero with meridian indicator" do
31
+ DateTime.strptime("10 AM", '%I %p').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
32
+ DateTime.strptime("03 04 04 PM", '%m %d %I %p').should == DateTime.civil(@t.year, 3, 4, 16, 0, 0)
33
+ end
34
+
35
+ it "should be able to parse the hour in a 24 hour clock with leading space" do
36
+ DateTime.strptime("10", '%k').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
37
+ DateTime.strptime(" 9", '%k').should == DateTime.civil(@t.year, @t.mon, @t.day, 9, 0, 0)
38
+ DateTime.strptime("10 16", '%d %k').should == DateTime.civil(@t.year, @t.mon, 10, 16, 0, 0)
39
+ end
40
+
41
+ it "should be able to parse the hour in a 12 hour clock with leading space with meridian indicator" do
42
+ DateTime.strptime("10 am", '%l %P').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
43
+ DateTime.strptime(" 4 pm", '%l %P').should == DateTime.civil(@t.year, @t.mon, @t.day, 16, 0, 0)
44
+ end
45
+
46
+ it "should be able to parse the number of milliseconds of the second" do
47
+ DateTime.strptime("10 000", '%M %L').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 10, 0)
48
+ DateTime.strptime("10 500", '%M %L').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 10, 0) + (0.5/86400)
49
+ end
50
+
51
+ it "should be able to parse the minute with leading zero" do
52
+ DateTime.strptime("10", '%M').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 10, 0)
53
+ DateTime.strptime("09", '%M').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 9, 0)
54
+ end
55
+
56
+ it "should be able to parse the number of nanoseconds of the second" do
57
+ DateTime.strptime("10 000000000", '%M %N').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 10, 0)
58
+ DateTime.strptime("10 500000000", '%M %N').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 10, 0) + (0.5/86400)
59
+ end
60
+
61
+ it "should be able to parse the number of seconds since the unix epoch" do
62
+ Date.strptime("954979200", "%s").should == Date.civil(2000, 4, 6)
63
+ end
64
+
65
+ it "should be able to parse the number of milliseconds since the unix epoch" do
66
+ DateTime.strptime("1226527410000", '%Q').should == DateTime.civil(2008, 11, 12, 22, 3, 30, 0)
67
+ DateTime.strptime("1226527411000", '%Q').should == DateTime.civil(2008, 11, 12, 22, 3, 31, 0)
68
+ DateTime.strptime("32511888001500", "%Q").should == DateTime.civil(3000, 4, 6, 0, 0, 1) + (0.5/86400)
69
+ end
70
+
71
+ it "should be able to parse the second with leading zero" do
72
+ DateTime.strptime("10", '%S').should == DateTime.civil(@t.year, @t.mon, @t.day, 0, 0, 10)
73
+ DateTime.strptime("10 09", '%H %S').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 9)
74
+ end
75
+
76
+ it "should be able to parse the number of seconds since the unix epoch" do
77
+ DateTime.strptime("1226527410", '%s').should == DateTime.civil(2008, 11, 12, 22, 3, 30, 0)
78
+ DateTime.strptime("1226527411", '%s').should == DateTime.civil(2008, 11, 12, 22, 3, 31, 0)
79
+ DateTime.strptime("32511888001", "%s").should == DateTime.civil(3000, 4, 6, 0, 0, 1)
80
+ end
81
+
82
+ it "should be able to parse the time zone offset as a string of hours and minutes" do
83
+ DateTime.strptime("2000 +0000", '%Y %z').offset.should == 0
84
+ DateTime.strptime("2000 Z", '%Y %z').offset.should == 0
85
+ DateTime.strptime("2000 -1200", '%Y %z').offset.should == -0.5
86
+ DateTime.strptime("2000 +1200", '%Y %z').offset.should == 0.5
87
+ DateTime.strptime("2000 -01:00", '%Y %z').offset.should == -1/24.0
88
+ DateTime.strptime("2000 +01:00", '%Y %z').offset.should == 1/24.0
89
+ end
90
+
91
+ ############################
92
+ # Specs that combine stuff #
93
+ ############################
94
+
95
+ it "should be able to parse the common date" do
96
+ DateTime.strptime("Thu Apr 6 10:11:12 2000", "%c").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
97
+ end
98
+
99
+ it "should be able to parse the hour and minute" do
100
+ DateTime.strptime("10:11", "%R").should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 11, 0)
101
+ end
102
+
103
+ it "should be able to parse the hour, minute, second, and am/pm flag" do
104
+ DateTime.strptime("10:11:12 AM", "%r").should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 11, 12)
105
+ DateTime.strptime("01:11:12 PM", "%r").should == DateTime.civil(@t.year, @t.mon, @t.day, 13, 11, 12)
106
+ end
107
+
108
+ it "should be able to parse the hour, minute, and second" do
109
+ DateTime.strptime("10:11:12", "%T").should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 11, 12)
110
+ DateTime.strptime("01:11:12", "%X").should == DateTime.civil(@t.year, @t.mon, @t.day, 1, 11, 12)
111
+ end
112
+
113
+ it "should be able to parse the common date and timezone" do
114
+ DateTime.strptime("Thu Apr 6 10:11:12 +0000 2000", "%+").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
115
+ DateTime.strptime("Thu Apr 6 10:11:12 +1200 2000", "%+").should == DateTime.civil(2000, 4, 6, 10, 11, 12, 0.5)
116
+ end
117
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "DateTime#succ" do
4
+ it "should be the next day" do
5
+ ds = DateTime.civil(2008, 10, 11)
6
+ ds.succ.should == DateTime.civil(2008, 10, 12)
7
+ ds = DateTime.civil(2008, 10, 31)
8
+ ds.succ.should == DateTime.civil(2008, 11, 1)
9
+ ds = DateTime.commercial(2008, 2, 7)
10
+ ds.succ.should == DateTime.commercial(2008, 3, 1)
11
+ ds = DateTime.jd(2008)
12
+ ds.succ.should == DateTime.jd(2009)
13
+ ds = DateTime.ordinal(2008, 366)
14
+ ds.succ.should == DateTime.ordinal(2009, 1)
15
+ end
16
+
17
+ it "should be aliased as next" do
18
+ DateTime.civil(2008, 10, 11).next.should == DateTime.civil(2008, 10, 12)
19
+ end
20
+
21
+ it "should keep the same fractional component" do
22
+ DateTime.civil(2008, 10, 11, 12, 13, 14).succ.should == DateTime.civil(2008, 10, 12, 12, 13, 14)
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "DateTime#upto" do
4
+
5
+ it "should be able to step forward in time" do
6
+ ds = DateTime.civil(2008, 10, 11)
7
+ de = DateTime.civil(2008, 9, 29)
8
+ count = 0
9
+ de.upto(ds) do |d|
10
+ d.should <= ds
11
+ d.should >= de
12
+ count += 1
13
+ end
14
+ count.should == 13
15
+ end
16
+
17
+ it "should respect fractional days" do
18
+ ds = DateTime.civil(2008, 10, 11, 0)
19
+ de = DateTime.civil(2008, 9, 29, 12)
20
+ count = 0
21
+ de.upto(ds) do |d|
22
+ d.should <= ds
23
+ d.should >= de
24
+ count += 1
25
+ end
26
+ count.should == 12
27
+
28
+ ds = DateTime.civil(2008, 10, 11, 12)
29
+ de = DateTime.civil(2008, 9, 29, 0)
30
+ count = 0
31
+ de.upto(ds) do |d|
32
+ d.should <= ds
33
+ d.should >= de
34
+ count += 1
35
+ end
36
+ count.should == 13
37
+ end
38
+
39
+ end