timely 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cebe03ec2467f4efe23f881f70be2c08fbb7e20
4
- data.tar.gz: 355bf2273646023df6e0f7e9218e7a91390dd25a
3
+ metadata.gz: 584fc428f9daeae0837d23072b66f7f9b243ff64
4
+ data.tar.gz: 5fb6844cfb6c8d57bd31993de1ad1d61c6bb3359
5
5
  SHA512:
6
- metadata.gz: bec47226548cc65af0aa7e0da099b5dc4f4b80056eb1f47e0f5de53959db654b18ed851245fbab86f9d45a0d80cb3fcc3a0bbcc9cc6188958d120402832b78f1
7
- data.tar.gz: c705e73fe8447761b8ea7a79984a77aeb13687bb81bc354e53f5f434d64f9d70f51325da10f81df7811e3c02a18621e02cc5b6dbcf7defcb33aa6f944ea066fe
6
+ metadata.gz: 09ba7d44b3b223dd336a0bfc80bf3ea265c9ae9f23d69184ce0844640cd1c26068846123908688e4f6dcd701b47437eb6e398d38d76bd41d940832a9d358e573
7
+ data.tar.gz: 5782e3428094d1272eb40a0923394a24c8196099601430374ccacf86fa59fa6b91606e4818938ba7f8f25bebf7a7ec45b8024938eedea19ea349cae0923cc95c
data/.travis.yml CHANGED
@@ -1,10 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
3
+ - 2.2.2
4
+ - 2.3.0
4
5
  script: bundle exec rake spec
5
6
  gemfile:
6
7
  - gemfiles/rails3.gemfile
7
8
  - gemfiles/rails4.gemfile
9
+ - gemfiles/rails5.gemfile
8
10
  notifications:
9
11
  email:
10
12
  - support@travellink.com.au
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ * Add time zone awareness for Time#on (e.g. Rails)
6
+ * Required Timely.load to load overrides
7
+
8
+ ## 0.2.0
9
+
10
+ * Rails 5 support
11
+
3
12
  ## 0.1.0
4
13
 
5
14
  * Initial release
@@ -2,7 +2,5 @@ source 'https://rubygems.org'
2
2
  gemspec :path => '../'
3
3
 
4
4
  group :development, :test do
5
- gem 'activesupport', '~> 3.2.0'
6
5
  gem 'activerecord', '~> 3.2.0'
7
- gem 'actionpack', '~> 3.2.0'
8
6
  end
@@ -2,8 +2,5 @@ source 'https://rubygems.org'
2
2
  gemspec :path => '../'
3
3
 
4
4
  group :development, :test do
5
- gem 'activesupport', '~> 4.0'
6
5
  gem 'activerecord', '~> 4.0'
7
- gem 'actionpack', '~> 4.0'
8
6
  end
9
-
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => '../'
3
+
4
+ group :development, :test do
5
+ gem 'activerecord', '~> 5.0'
6
+ end
data/lib/timely/date.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Timely
2
2
  module Date
3
3
  def at_time(hour = nil, minute = nil, second = nil)
4
- if hour.is_a?(Time)
4
+ if hour.is_a?(::Time)
5
5
  time = hour
6
6
  hour, minute, second = time.hour, time.min, time.sec
7
7
  end
@@ -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
@@ -9,3 +9,4 @@ require 'timely/rails/calendar_tag'
9
9
  require 'timely/rails/date_time'
10
10
  require 'timely/rails/date'
11
11
  require 'timely/rails/period'
12
+ require 'timely/rails/time'
data/lib/timely/time.rb CHANGED
@@ -14,8 +14,3 @@ module Timely
14
14
  alias_method :on, :on_date
15
15
  end
16
16
  end
17
-
18
- class Time
19
- include Timely::Time
20
- end
21
-
@@ -1,3 +1,3 @@
1
1
  module Timely
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/timely.rb CHANGED
@@ -18,4 +18,8 @@ module Timely
18
18
  require 'timely/trackable_date_set'
19
19
 
20
20
  require 'timely/railtie' if defined?(Rails::Railtie)
21
+
22
+ def self.load
23
+ ::Time.send :include, Timely::Time
24
+ end
21
25
  end
@@ -1,20 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DateTime do
4
- let(:date_time) { DateTime.parse("2010-01-01") }
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 DateTime.parse("2010-01-10 23:59:59")
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 DateTime.parse("2010-10-31 23:59:59")
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 DateTime.parse("2019-12-31 23:59:59")
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
@@ -10,7 +10,7 @@ require 'bundler/setup'
10
10
  require 'rspec/its'
11
11
  require 'active_record'
12
12
 
13
- require 'support/coverage'
13
+ require 'support/coverage_loader'
14
14
 
15
15
  I18n.enforce_available_locales = true if I18n.respond_to? :enforce_available_locales=
16
16
 
@@ -0,0 +1,4 @@
1
+ require 'simplecov-rcov'
2
+ require 'coveralls'
3
+ require 'coverage/kit'
4
+ Coverage::Kit.setup(minimum_coverage: 68.3)
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 = Time.parse("12:00")
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 = Time.parse("2010-01-01 09:30:00")
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 = Time.now - 12345
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 'simplecov'
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.1.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: 2016-06-15 00:00:00.000000000 Z
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: simplecov
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/coverage.rb
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.8
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/coverage.rb
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
@@ -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