time_ext 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,285 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TimeExt" do
4
+
5
+ before(:each) do
6
+ @time = Time.local(2010, 8, 28, 15, 57, 17, 78430)
7
+ end
8
+
9
+ it "should have extra Time calculation methods" do
10
+ @time.prev_second.should == @time - 1.second
11
+ @time.prev_sec.should == @time - 1.second
12
+ @time.next_second.should == @time + 1.second
13
+ @time.next_sec.should == @time + 1.second
14
+
15
+ @time.prev_minute.should == @time - 1.minute
16
+ @time.prev_min.should == @time - 1.minute
17
+ @time.next_minute.should == @time + 1.minute
18
+ @time.next_min.should == @time + 1.minute
19
+
20
+ @time.prev_hour.should == @time - 1.hour
21
+ @time.next_hour.should == @time + 1.hour
22
+
23
+ @time.prev_day.should == @time - 1.day
24
+ @time.next_day.should == @time + 1.day
25
+ @time.days_ago(1).should == @time - 1.day
26
+ @time.days_since(1).should == @time + 1.day
27
+
28
+ @time.prev_week.day.should == 16
29
+
30
+ @time.prev_quarter.day.should == 1
31
+ @time.prev_quarter.month.should == 4
32
+ @time.next_quarter.day.should == 1
33
+ @time.next_quarter.month.should == 10
34
+
35
+ @time.respond_to?(:floor).should be_true
36
+ @time.respond_to?(:beginning_of).should be_true
37
+ @time.respond_to?(:ceil).should be_true
38
+ @time.respond_to?(:beginning_of_next).should be_true
39
+ @time.respond_to?(:round).should be_true
40
+ @time.respond_to?(:beginning_of_closest).should be_true
41
+ end
42
+
43
+ it "should floor and ceil to seconds" do
44
+ floor = @time.floor(:sec)
45
+ floor.usec.should == 0
46
+ floor.sec.should == @time.sec
47
+ floor.min.should == @time.min
48
+ floor.hour.should == @time.hour
49
+ floor.day.should == @time.day
50
+ floor.month.should == @time.month
51
+ floor.year.should == @time.year
52
+
53
+ ceil = @time.ceil(:sec)
54
+ ceil.usec.should == 0
55
+ ceil.sec.should == @time.sec + 1
56
+ ceil.min.should == @time.min
57
+ ceil.hour.should == @time.hour
58
+ ceil.day.should == @time.day
59
+ ceil.month.should == @time.month
60
+ ceil.year.should == @time.year
61
+ end
62
+
63
+ it "should floor and ceil to minutes" do
64
+ floor = @time.floor(:min)
65
+ floor.usec.should == 0
66
+ floor.sec.should == 0
67
+ floor.min.should == @time.min
68
+ floor.hour.should == @time.hour
69
+ floor.day.should == @time.day
70
+ floor.month.should == @time.month
71
+ floor.year.should == @time.year
72
+
73
+ ceil = @time.ceil(:min)
74
+ ceil.usec.should == 0
75
+ ceil.sec.should == 0
76
+ ceil.min.should == @time.min + 1
77
+ ceil.hour.should == @time.hour
78
+ ceil.day.should == @time.day
79
+ ceil.month.should == @time.month
80
+ ceil.year.should == @time.year
81
+ end
82
+
83
+ it "should floor and ceil to hours" do
84
+ floor = @time.floor(:hour)
85
+ floor.usec.should == 0
86
+ floor.sec.should == 0
87
+ floor.min.should == 0
88
+ floor.hour.should == @time.hour
89
+ floor.day.should == @time.day
90
+ floor.month.should == @time.month
91
+ floor.year.should == @time.year
92
+
93
+ ceil = @time.ceil(:hour)
94
+ ceil.usec.should == 0
95
+ ceil.sec.should == 0
96
+ ceil.min.should == 0
97
+ ceil.hour.should == @time.hour + 1
98
+ ceil.day.should == @time.day
99
+ ceil.month.should == @time.month
100
+ ceil.year.should == @time.year
101
+ end
102
+
103
+ it "should floor and ceil to days" do
104
+ floor = @time.floor(:day)
105
+ floor.usec.should == 0
106
+ floor.sec.should == 0
107
+ floor.min.should == 0
108
+ floor.hour.should == 0
109
+ floor.day.should == @time.day
110
+ floor.month.should == @time.month
111
+ floor.year.should == @time.year
112
+
113
+ ceil = @time.ceil(:day)
114
+ ceil.usec.should == 0
115
+ ceil.sec.should == 0
116
+ ceil.min.should == 0
117
+ ceil.hour.should == 0
118
+ ceil.day.should == @time.day + 1
119
+ ceil.month.should == @time.month
120
+ ceil.year.should == @time.year
121
+ end
122
+
123
+ it "should floor and ceil to weeks" do
124
+ floor = @time.floor(:week)
125
+ floor.usec.should == 0
126
+ floor.sec.should == 0
127
+ floor.min.should == 0
128
+ floor.hour.should == 0
129
+ floor.day.should == 23
130
+ floor.month.should == @time.month
131
+ floor.year.should == @time.year
132
+
133
+ ceil = @time.ceil(:week)
134
+ ceil.usec.should == 0
135
+ ceil.sec.should == 0
136
+ ceil.min.should == 0
137
+ ceil.hour.should == 0
138
+ ceil.day.should == 30
139
+ ceil.month.should == @time.month
140
+ ceil.year.should == @time.year
141
+ end
142
+
143
+ it "should floor and ceil to months" do
144
+ floor = @time.floor(:month)
145
+ floor.usec.should == 0
146
+ floor.sec.should == 0
147
+ floor.min.should == 0
148
+ floor.hour.should == 0
149
+ floor.day.should == 1
150
+ floor.month.should == @time.month
151
+ floor.year.should == @time.year
152
+
153
+ ceil = @time.ceil(:month)
154
+ ceil.usec.should == 0
155
+ ceil.sec.should == 0
156
+ ceil.min.should == 0
157
+ ceil.hour.should == 0
158
+ ceil.day.should == 1
159
+ ceil.month.should == @time.month + 1
160
+ ceil.year.should == @time.year
161
+ end
162
+
163
+ it "should floor and ceil to quarters" do
164
+ floor = @time.floor(:quarter)
165
+ floor.usec.should == 0
166
+ floor.sec.should == 0
167
+ floor.min.should == 0
168
+ floor.hour.should == 0
169
+ floor.day.should == 1
170
+ floor.month.should == 7
171
+ floor.year.should == @time.year
172
+
173
+ ceil = @time.ceil(:quarter)
174
+ ceil.usec.should == 0
175
+ ceil.sec.should == 0
176
+ ceil.min.should == 0
177
+ ceil.hour.should == 0
178
+ ceil.day.should == 1
179
+ ceil.month.should == 10
180
+ ceil.year.should == @time.year
181
+ end
182
+
183
+ it "should floor and ceil to years" do
184
+ floor = @time.floor(:year)
185
+ floor.usec.should == 0
186
+ floor.sec.should == 0
187
+ floor.min.should == 0
188
+ floor.hour.should == 0
189
+ floor.day.should == 1
190
+ floor.month.should == 1
191
+ floor.year.should == @time.year
192
+
193
+ ceil = @time.ceil(:year)
194
+ ceil.usec.should == 0
195
+ ceil.sec.should == 0
196
+ ceil.min.should == 0
197
+ ceil.hour.should == 0
198
+ ceil.day.should == 1
199
+ ceil.month.should == 1
200
+ ceil.year.should == @time.year + 1
201
+ end
202
+
203
+ it "should round to seconds" do
204
+ round = Time.local(2010, 8, 28, 15, 57, 17, 999999.999).round(:sec)
205
+ round.usec.should == 0
206
+ round.sec.should == 18
207
+
208
+ round = Time.local(2010, 8, 28, 15, 57, 17, 111111.111).round(:sec)
209
+ round.usec.should == 0
210
+ round.sec.should == 17
211
+ end
212
+
213
+ it "should round to minutes" do
214
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:min)
215
+ round.sec.should == 0
216
+ round.min.should == 58
217
+
218
+ round = Time.local(2010, 8, 28, 15, 57, 17, 999999.999).round(:min)
219
+ round.sec.should == 0
220
+ round.min.should == 57
221
+ end
222
+
223
+ it "should round to hours" do
224
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:hour)
225
+ round.min.should == 0
226
+ round.hour.should == 16
227
+
228
+ round = Time.local(2010, 8, 28, 15, 17, 47, 999999.999).round(:hour)
229
+ round.min.should == 0
230
+ round.hour.should == 15
231
+ end
232
+
233
+ it "should round to days" do
234
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:day)
235
+ round.hour.should == 0
236
+ round.day.should == 29
237
+
238
+ round = Time.local(2010, 8, 28, 11, 57, 47, 999999.999).round(:day)
239
+ round.hour.should == 0
240
+ round.day.should == 28
241
+ end
242
+
243
+ it "should round to weeks" do
244
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:week)
245
+ round.hour.should == 0
246
+ round.day.should == 30
247
+
248
+ round = Time.local(2010, 8, 25, 15, 57, 47, 999999.999).round(:week)
249
+ round.hour.should == 0
250
+ round.day.should == 23
251
+ end
252
+
253
+ it "should round to months" do
254
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:month)
255
+ round.day.should == 1
256
+ round.month.should == 9
257
+
258
+ round = Time.local(2010, 8, 8, 15, 57, 47, 999999.999).round(:month)
259
+ round.day.should == 1
260
+ round.month.should == 8
261
+ end
262
+
263
+ it "should round to quarters" do
264
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:quarter)
265
+ round.hour.should == 0
266
+ round.day.should == 1
267
+ round.month.should == 10
268
+
269
+ round = Time.local(2010, 8, 8, 15, 57, 47, 999999.999).round(:quarter)
270
+ round.hour.should == 0
271
+ round.day.should == 1
272
+ round.month.should == 7
273
+ end
274
+
275
+ it "should round to years" do
276
+ round = Time.local(2010, 8, 28, 15, 57, 47, 999999.999).round(:year)
277
+ round.month.should == 1
278
+ round.year.should == 2011
279
+
280
+ round = Time.local(2010, 4, 28, 15, 57, 47, 999999.999).round(:year)
281
+ round.month.should == 1
282
+ round.year.should == 2010
283
+ end
284
+
285
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: time_ext
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Jim Myhrberg
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-27 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 0
34
+ version: 2.3.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 9
50
+ version: 1.2.9
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: yard
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: Extends the abilities of Ruby's built-in Time class by building on top of ActiveSupport.
68
+ email: contact@jimeh.me
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.md
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - VERSION
83
+ - doc/Time.html
84
+ - doc/_index.html
85
+ - doc/class_list.html
86
+ - doc/css/common.css
87
+ - doc/css/full_list.css
88
+ - doc/css/style.css
89
+ - doc/file.README.html
90
+ - doc/file_list.html
91
+ - doc/frames.html
92
+ - doc/index.html
93
+ - doc/js/app.js
94
+ - doc/js/full_list.js
95
+ - doc/js/jquery.js
96
+ - doc/method_list.html
97
+ - doc/top-level-namespace.html
98
+ - lib/time/ext.rb
99
+ - lib/time_ext.rb
100
+ - lib/time_ext/time.rb
101
+ - spec/spec.opts
102
+ - spec/spec_helper.rb
103
+ - spec/time_ext_spec.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/jimeh/time_ext
106
+ licenses: []
107
+
108
+ post_install_message:
109
+ rdoc_options:
110
+ - --charset=UTF-8
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.3.7
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Extends the abilities of Ruby's built-in Time class by building on top of ActiveSupport.
138
+ test_files:
139
+ - spec/spec_helper.rb
140
+ - spec/time_ext_spec.rb