timely 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/CHANGELOG.md +9 -0
- data/gemfiles/rails3.gemfile +0 -2
- data/gemfiles/rails4.gemfile +0 -3
- data/gemfiles/rails5.gemfile +6 -0
- data/lib/timely/date.rb +1 -1
- data/lib/timely/rails/time.rb +18 -0
- data/lib/timely/rails.rb +1 -0
- data/lib/timely/time.rb +0 -5
- data/lib/timely/version.rb +1 -1
- data/lib/timely.rb +4 -0
- data/spec/rails/date_time_spec.rb +10 -4
- data/spec/rails/time_spec.rb +71 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/coverage_loader.rb +4 -0
- data/spec/time_spec.rb +7 -3
- data/timely.gemspec +1 -1
- metadata +10 -6
- data/spec/support/coverage.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 584fc428f9daeae0837d23072b66f7f9b243ff64
|
4
|
+
data.tar.gz: 5fb6844cfb6c8d57bd31993de1ad1d61c6bb3359
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09ba7d44b3b223dd336a0bfc80bf3ea265c9ae9f23d69184ce0844640cd1c26068846123908688e4f6dcd701b47437eb6e398d38d76bd41d940832a9d358e573
|
7
|
+
data.tar.gz: 5782e3428094d1272eb40a0923394a24c8196099601430374ccacf86fa59fa6b91606e4818938ba7f8f25bebf7a7ec45b8024938eedea19ea349cae0923cc95c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/gemfiles/rails3.gemfile
CHANGED
data/gemfiles/rails4.gemfile
CHANGED
data/lib/timely/date.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Timely
|
2
|
+
module Rails
|
3
|
+
module Time
|
4
|
+
def on_date(year, month = nil, day = nil)
|
5
|
+
if year.is_a?(Date)
|
6
|
+
date = year
|
7
|
+
year, month, day = date.year, date.month, date.day
|
8
|
+
end
|
9
|
+
|
10
|
+
raise ArgumentError, "Year, month, and day needed" unless [year, month, day].all?
|
11
|
+
|
12
|
+
::Time.zone.local(year, month, day, hour, min, sec)
|
13
|
+
end
|
14
|
+
|
15
|
+
alias_method :on, :on_date
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/timely/rails.rb
CHANGED
data/lib/timely/time.rb
CHANGED
data/lib/timely/version.rb
CHANGED
data/lib/timely.rb
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DateTime do
|
4
|
-
let(:date_time) {
|
4
|
+
let(:date_time) { parse_time("2010-01-01 00:00:00") }
|
5
5
|
|
6
6
|
it "should allow advancing by calendar days" do
|
7
7
|
expect(date_time.advance_considering_calendar(:calendar_days, 10))
|
8
|
-
.to eq
|
8
|
+
.to eq parse_time("2010-01-10 23:59:59")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should allow advancing by calendar months" do
|
12
12
|
expect(date_time.advance_considering_calendar(:calendar_months, 10))
|
13
|
-
.to eq
|
13
|
+
.to eq parse_time("2010-10-31 23:59:59")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should allow advancing by calendar years" do
|
17
17
|
expect(date_time.advance_considering_calendar(:calendar_years, 10))
|
18
|
-
.to eq
|
18
|
+
.to eq parse_time("2019-12-31 23:59:59")
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_time(time)
|
22
|
+
# ActiveSupport 5.1+ returns end of day differently
|
23
|
+
# Returns with usec at 999999 vs 0
|
24
|
+
DateTime.parse(time).end_of_day
|
19
25
|
end
|
20
26
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
TestRailsTime = Class.new(Time) do
|
4
|
+
include ::Timely::Rails::Time
|
5
|
+
end
|
6
|
+
|
7
|
+
describe TestRailsTime do
|
8
|
+
before { TestRailsTime.zone = 'Australia/Sydney' }
|
9
|
+
|
10
|
+
it 'should be able to set date on a time' do
|
11
|
+
xmas = Date.new(2012, 12, 25)
|
12
|
+
lunch_time = TestRailsTime.parse("12:00")
|
13
|
+
xmas_lunch = lunch_time.on_date(xmas)
|
14
|
+
expect(xmas_lunch.year).to eq 2012
|
15
|
+
expect(xmas_lunch.month).to eq 12
|
16
|
+
expect(xmas_lunch.day).to eq 25
|
17
|
+
expect(xmas_lunch.hour).to eq 12
|
18
|
+
expect(xmas_lunch.min).to eq 0
|
19
|
+
expect(xmas_lunch.sec).to eq 0
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow setting the date part given a date" do
|
23
|
+
time = TestRailsTime.parse("2010-01-01 09:30:00")
|
24
|
+
expect(time.on_date(Date.parse("2012-12-31"))).to eq TestRailsTime.zone.parse("2012-12-31 09:30:00")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Time do
|
29
|
+
before :each do
|
30
|
+
TestRailsTime.zone = 'Australia/Sydney'
|
31
|
+
@time = TestRailsTime.now
|
32
|
+
|
33
|
+
@year = 2005
|
34
|
+
@month = 3
|
35
|
+
@day = 15
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should give that time on a date' do
|
39
|
+
expect(@time).to respond_to(:on_date)
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'giving that time on a date' do
|
43
|
+
it 'should accept year, month and day' do
|
44
|
+
expect { @time.on_date(@year, @month, @day) }.to_not raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should require year, month, and day' do
|
48
|
+
expect { @time.on_date(@year, @month) }.to raise_error(ArgumentError)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return the same time on the specified year, month, and day' do
|
52
|
+
expected = TestRailsTime.zone.local(@year, @month, @day, @time.hour, @time.min, @time.sec)
|
53
|
+
expect(@time.on_date(@year, @month, @day)).to eq expected
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should accept a date' do
|
57
|
+
expect { @time.on_date(Date.today) }.to_not raise_error
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return the same time on the specified date' do
|
61
|
+
@date = Date.today - 2345
|
62
|
+
expected = Time.zone.local(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec)
|
63
|
+
expect(@time.on_date(@date)).to eq expected
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should provide 'on' as an alias" do
|
68
|
+
expected = TestRailsTime.zone.local(@year, @month, @day, @time.hour, @time.min, @time.sec)
|
69
|
+
expect(@time.on(@year, @month, @day)).to eq expected
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/time_spec.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
TestTime = Class.new(Time) do
|
4
|
+
include ::Timely::Time
|
5
|
+
end
|
6
|
+
|
3
7
|
describe Time do
|
4
8
|
it 'should be able to set date on a time' do
|
5
9
|
xmas = Date.new(2012, 12, 25)
|
6
|
-
lunch_time =
|
10
|
+
lunch_time = TestTime.parse("12:00")
|
7
11
|
xmas_lunch = lunch_time.on_date(xmas)
|
8
12
|
expect(xmas_lunch.year).to eq 2012
|
9
13
|
expect(xmas_lunch.month).to eq 12
|
@@ -14,14 +18,14 @@ describe Time do
|
|
14
18
|
end
|
15
19
|
|
16
20
|
it "should allow setting the date part given a date" do
|
17
|
-
time =
|
21
|
+
time = TestTime.parse("2010-01-01 09:30:00")
|
18
22
|
expect(time.on_date(Date.parse("2012-12-31"))).to eq Time.parse("2012-12-31 09:30:00")
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
22
26
|
describe Time do
|
23
27
|
before :each do
|
24
|
-
@time =
|
28
|
+
@time = TestTime.now
|
25
29
|
|
26
30
|
@year = 2005
|
27
31
|
@month = 3
|
data/timely.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency 'rspec'
|
25
25
|
spec.add_development_dependency 'rspec-its'
|
26
|
-
spec.add_development_dependency '
|
26
|
+
spec.add_development_dependency 'coverage-kit'
|
27
27
|
spec.add_development_dependency 'simplecov-rcov'
|
28
28
|
spec.add_development_dependency 'coveralls'
|
29
29
|
spec.add_development_dependency 'sqlite3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: coverage-kit
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -210,6 +210,7 @@ files:
|
|
210
210
|
- Rakefile
|
211
211
|
- gemfiles/rails3.gemfile
|
212
212
|
- gemfiles/rails4.gemfile
|
213
|
+
- gemfiles/rails5.gemfile
|
213
214
|
- lib/timely.rb
|
214
215
|
- lib/timely/date.rb
|
215
216
|
- lib/timely/date_chooser.rb
|
@@ -224,6 +225,7 @@ files:
|
|
224
225
|
- lib/timely/rails/extensions.rb
|
225
226
|
- lib/timely/rails/period.rb
|
226
227
|
- lib/timely/rails/season.rb
|
228
|
+
- lib/timely/rails/time.rb
|
227
229
|
- lib/timely/railtie.rb
|
228
230
|
- lib/timely/range.rb
|
229
231
|
- lib/timely/string.rb
|
@@ -246,11 +248,12 @@ files:
|
|
246
248
|
- spec/rails/date_spec.rb
|
247
249
|
- spec/rails/date_time_spec.rb
|
248
250
|
- spec/rails/period_spec.rb
|
251
|
+
- spec/rails/time_spec.rb
|
249
252
|
- spec/schema.rb
|
250
253
|
- spec/season_spec.rb
|
251
254
|
- spec/spec_helper.rb
|
252
255
|
- spec/string_spec.rb
|
253
|
-
- spec/support/
|
256
|
+
- spec/support/coverage_loader.rb
|
254
257
|
- spec/temporal_patterns_spec.rb
|
255
258
|
- spec/time_since_spec.rb
|
256
259
|
- spec/time_spec.rb
|
@@ -277,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
277
280
|
version: '0'
|
278
281
|
requirements: []
|
279
282
|
rubyforge_project:
|
280
|
-
rubygems_version: 2.4.
|
283
|
+
rubygems_version: 2.4.5.1
|
281
284
|
signing_key:
|
282
285
|
specification_version: 4
|
283
286
|
summary: Set of time, date, weekday related methods.
|
@@ -291,11 +294,12 @@ test_files:
|
|
291
294
|
- spec/rails/date_spec.rb
|
292
295
|
- spec/rails/date_time_spec.rb
|
293
296
|
- spec/rails/period_spec.rb
|
297
|
+
- spec/rails/time_spec.rb
|
294
298
|
- spec/schema.rb
|
295
299
|
- spec/season_spec.rb
|
296
300
|
- spec/spec_helper.rb
|
297
301
|
- spec/string_spec.rb
|
298
|
-
- spec/support/
|
302
|
+
- spec/support/coverage_loader.rb
|
299
303
|
- spec/temporal_patterns_spec.rb
|
300
304
|
- spec/time_since_spec.rb
|
301
305
|
- spec/time_spec.rb
|
data/spec/support/coverage.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
MINIMUM_COVERAGE = 68
|
2
|
-
|
3
|
-
unless ENV['COVERAGE'] == 'off'
|
4
|
-
require 'simplecov'
|
5
|
-
require 'simplecov-rcov'
|
6
|
-
require 'coveralls'
|
7
|
-
Coveralls.wear!
|
8
|
-
|
9
|
-
SimpleCov.formatters = [
|
10
|
-
SimpleCov::Formatter::RcovFormatter,
|
11
|
-
Coveralls::SimpleCov::Formatter
|
12
|
-
]
|
13
|
-
SimpleCov.start do
|
14
|
-
add_filter '/vendor/'
|
15
|
-
add_filter '/spec/'
|
16
|
-
add_group 'lib', 'lib'
|
17
|
-
end
|
18
|
-
SimpleCov.at_exit do
|
19
|
-
SimpleCov.result.format!
|
20
|
-
percent = SimpleCov.result.covered_percent
|
21
|
-
unless percent >= MINIMUM_COVERAGE
|
22
|
-
puts "Coverage must be above #{MINIMUM_COVERAGE}%. It is #{"%.2f" % percent}%"
|
23
|
-
Kernel.exit(1)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|