iso8601 0.12.2 → 0.12.3

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.
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ describe ISO8601::Time do
4
+ it "should raise an error for any unknown pattern" do
5
+ expect { ISO8601::Time.new('') }.to raise_error(ISO8601::Errors::UnknownPattern)
6
+ expect { ISO8601::Time.new('T') }.to raise_error(ISO8601::Errors::UnknownPattern)
7
+ expect { ISO8601::Time.new('T10:3012+0400') }.to raise_error(ISO8601::Errors::UnknownPattern)
8
+ expect { ISO8601::Time.new('T10:30:12+0400') }.to raise_error(ISO8601::Errors::UnknownPattern)
9
+ expect { ISO8601::Time.new('T10:30:12+040') }.to raise_error(ISO8601::Errors::UnknownPattern)
10
+ end
11
+
12
+ it "should raise an error for a correct pattern but an invalid date" do
13
+ expect { ISO8601::Time.new('T25:00:00') }.to raise_error(ISO8601::Errors::RangeError)
14
+ expect { ISO8601::Time.new('T00:61:00') }.to raise_error(ISO8601::Errors::RangeError)
15
+ expect { ISO8601::Time.new('T00:00:61') }.to raise_error(ISO8601::Errors::RangeError)
16
+ end
17
+
18
+ it "should parse any allowed pattern" do
19
+ expect { ISO8601::Time.new('T10') }.to_not raise_error
20
+ expect { ISO8601::Time.new('T10-00:00') }.to_not raise_error
21
+ expect { ISO8601::Time.new('T10Z') }.to_not raise_error
22
+ expect { ISO8601::Time.new('T10:30') }.to_not raise_error
23
+ expect { ISO8601::Time.new('T10:30Z') }.to_not raise_error
24
+ expect { ISO8601::Time.new('T10:30:12') }.to_not raise_error
25
+ expect { ISO8601::Time.new('T10:30:12Z') }.to_not raise_error
26
+ expect { ISO8601::Time.new('T10:30:12+04') }.to_not raise_error
27
+ expect { ISO8601::Time.new('T10:30:12+04:00') }.to_not raise_error
28
+ expect { ISO8601::Time.new('T10:30:12-04:00') }.to_not raise_error
29
+ expect { ISO8601::Time.new('T103012+0400') }.to_not raise_error
30
+ expect { ISO8601::Time.new('T103012+04') }.to_not raise_error
31
+ expect { ISO8601::Time.new('T10:30:12-00:00') }.to_not raise_error
32
+ expect { ISO8601::Time.new('T16:26:10,5Z') }.to_not raise_error
33
+ expect { ISO8601::Time.new('T10+00:00') }.to_not raise_error
34
+ end
35
+
36
+ context 'reduced patterns' do
37
+ it "should parse correctly reduced times" do
38
+ reduced_time = ISO8601::Time.new('T101112Z')
39
+ expect(reduced_time.hour).to eq(10)
40
+ expect(reduced_time.minute).to eq(11)
41
+ expect(reduced_time.second).to eq(12)
42
+ end
43
+ end
44
+
45
+ it "should return each atomic value" do
46
+ t = ISO8601::Time.new('T12:02:01+04:00', ::Date.parse('2010-05-09'))
47
+ expect(t.hour).to eq(12)
48
+ expect(t.minute).to eq(2)
49
+ expect(t.second).to eq(1)
50
+ expect(t.zone).to eq('+04:00')
51
+ end
52
+
53
+ it "should keep the correct fraction when using commma separators" do
54
+ expect(ISO8601::Time.new('T16:26:10,5Z').second).to eq(10.5)
55
+ end
56
+
57
+ it "should respond to delegated casting methods" do
58
+ expect(ISO8601::Time.new('T10:09:08Z')).to respond_to(:to_s, :to_time, :to_date, :to_datetime)
59
+ end
60
+
61
+ describe '#+' do
62
+ it "should return the result of the addition of a number" do
63
+ expect((ISO8601::Time.new('T20:20:20Z') + 10).to_s).to eq('T20:20:30+00:00')
64
+ expect((ISO8601::Time.new('T20:20:20.5Z') + 10).to_s).to eq('T20:20:30.5+00:00')
65
+ expect((ISO8601::Time.new('T20:20:20+02:00') + 10.09).to_s).to eq('T20:20:30.1+02:00')
66
+ expect((ISO8601::Time.new('T20:20:20+02:00') + 10.1).to_s).to eq('T20:20:30.1+02:00')
67
+ expect((ISO8601::Time.new('T20:20:20+02:00') + 10).second).to eq(30)
68
+ expect((ISO8601::Time.new('T20:20:20.5Z') + 10).second).to eq(30.5)
69
+ expect((ISO8601::Time.new('T20:20:20+02:00') + 10.09).second).to eq(30.1)
70
+ end
71
+ end
72
+
73
+ describe '#-' do
74
+ it "should return the result of the subtraction of a number" do
75
+ expect((ISO8601::Time.new('T20:20:20+01:00') - 10).to_s).to eq('T20:20:10+01:00')
76
+ expect((ISO8601::Time.new('T20:20:20.11+02:00') - 10).to_s).to eq('T20:20:10.1+02:00')
77
+ end
78
+ end
79
+
80
+ describe '#to_a' do
81
+ it "should return an array of atoms" do
82
+ expect(ISO8601::Time.new('T19:29:39Z').to_a).to eq([19, 29, 39, '+00:00'])
83
+ end
84
+ end
85
+
86
+ describe '#atoms' do
87
+ it "should return an array of atoms" do
88
+ expect(ISO8601::Time.new('T19:29:39+04:00').atoms).to eq([19, 29, 39, '+04:00'])
89
+ expect(ISO8601::Time.new('T19:29:39Z').atoms).to eq([19, 29, 39, 'Z'])
90
+ expect(ISO8601::Time.new('T19:29:39').atoms).to eq([19, 29, 39])
91
+ expect(ISO8601::Time.new('T19:29').atoms).to eq([19, 29, 0.0])
92
+ expect(ISO8601::Time.new('T19:29Z').atoms).to eq([19, 29, 0.0, 'Z'])
93
+ expect(ISO8601::Time.new('T19Z').atoms).to eq([19, 0, 0.0, 'Z'])
94
+ end
95
+ end
96
+
97
+ describe '#hash' do
98
+ it "should return the time hash" do
99
+ subject = ISO8601::Time.new('T20:11:10Z')
100
+
101
+ expect(subject).to respond_to(:hash)
102
+ end
103
+ it "should return the same hash" do
104
+ subject = ISO8601::Time.new('T20:11:10Z')
105
+ contrast = ISO8601::Time.new('T20:11:10Z')
106
+
107
+ expect(subject.hash).to eq(contrast.hash)
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Weeks do
4
+ describe 'Atomic' do
5
+ let(:subject) { ISO8601::Weeks.new(1) }
6
+
7
+ it "should respond to the Atomic interface" do
8
+ %i[factor
9
+ to_seconds
10
+ symbol
11
+ to_i
12
+ to_f
13
+ to_s
14
+ value
15
+ <=>
16
+ eql?
17
+ hash
18
+ valid_atom?].each { |m| expect(subject).to respond_to(m) }
19
+ end
20
+ end
21
+
22
+ describe '#factor' do
23
+ it "should return the Week factor" do
24
+ expect(ISO8601::Weeks.new(2).factor).to eq(604800)
25
+ end
26
+ end
27
+
28
+ describe '#to_seconds' do
29
+ it "should return the amount of seconds" do
30
+ expect(ISO8601::Weeks.new(2).to_seconds).to eq(1209600)
31
+ expect(ISO8601::Weeks.new(-2).to_seconds).to eq(-1209600)
32
+ end
33
+ end
34
+
35
+ describe '#symbol' do
36
+ it "should return the ISO symbol" do
37
+ expect(ISO8601::Weeks.new(1).symbol).to eq(:W)
38
+ end
39
+ end
40
+
41
+ describe '#hash' do
42
+ it "should build hash identity by value" do
43
+ expect(ISO8601::Weeks.new(3).hash).to eq(ISO8601::Weeks.new(3).hash)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ISO8601::Years do
4
+ let(:common_year) { ISO8601::DateTime.new('2010-01-01') }
5
+ let(:leap_year) { ISO8601::DateTime.new('2000-01-01') }
6
+
7
+ describe 'Atomic' do
8
+ let(:subject) { ISO8601::Years.new(1) }
9
+
10
+ it "should respond to the Atomic interface" do
11
+ %i[factor
12
+ to_seconds
13
+ symbol
14
+ to_i
15
+ to_f
16
+ to_s
17
+ value
18
+ <=>
19
+ eql?
20
+ hash
21
+ valid_atom?].each { |m| expect(subject).to respond_to(m) }
22
+ end
23
+ end
24
+
25
+ describe '#factor' do
26
+ it "should return the Year factor" do
27
+ expect { ISO8601::Years.new(1).factor }.to_not raise_error
28
+ expect(ISO8601::Years.new(2).factor).to eq(31536000)
29
+ expect(ISO8601::Years.new(1).factor).to eq(31536000)
30
+ end
31
+
32
+ it "should return the Year factor for a common year" do
33
+ expect(ISO8601::Years.new(1).factor(common_year)).to eq(31536000)
34
+ expect(ISO8601::Years.new(0).factor(common_year)).to eq(31536000)
35
+ end
36
+
37
+ it "should return the Year factor for a leap year" do
38
+ expect(ISO8601::Years.new(1).factor(leap_year)).to eq(31622400)
39
+ end
40
+ end
41
+
42
+ describe '#to_seconds' do
43
+ it "should return the amount of seconds" do
44
+ expect(ISO8601::Years.new(2).to_seconds).to eq(63072000)
45
+ expect(ISO8601::Years.new(-2).to_seconds).to eq(-63072000)
46
+ end
47
+
48
+ it "should return the amount of seconds for a common year" do
49
+ expect(ISO8601::Years.new(2).to_seconds(common_year)).to eq(63072000)
50
+ expect(ISO8601::Years.new(12).to_seconds(common_year)).to eq(378691200)
51
+ end
52
+
53
+ it "should return the amount of seconds for a leap year" do
54
+ expect(ISO8601::Years.new(2).to_seconds(leap_year)).to eq(63158400)
55
+ expect(ISO8601::Years.new(15).to_seconds(leap_year)).to eq(473385600)
56
+ end
57
+ end
58
+
59
+ describe '#symbol' do
60
+ it "should return the ISO symbol" do
61
+ expect(ISO8601::Years.new(1).symbol).to eq(:Y)
62
+ end
63
+ end
64
+
65
+ describe '#hash' do
66
+ it "should build hash identity by value" do
67
+ expect(ISO8601::Years.new(3).hash).to eq(ISO8601::Years.new(3).hash)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ require 'iso8601'
3
+
4
+ RSpec.configure do |config|
5
+ config.run_all_when_everything_filtered = true
6
+ config.color = true
7
+ config.order = 'random'
8
+ config.formatter = :documentation
9
+ # config.fail_fast = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso8601
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnau Siches
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-19 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.85'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-packaging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: pry
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -75,11 +89,11 @@ executables: []
75
89
  extensions: []
76
90
  extra_rdoc_files: []
77
91
  files:
78
- - CONTRIBUTING.md
79
- - Gemfile
80
92
  - LICENSE
81
93
  - README.md
82
- - iso8601.gemspec
94
+ - docs/date-time.md
95
+ - docs/duration.md
96
+ - docs/time-interval.md
83
97
  - lib/iso8601.rb
84
98
  - lib/iso8601/atomic.rb
85
99
  - lib/iso8601/date.rb
@@ -96,12 +110,25 @@ files:
96
110
  - lib/iso8601/version.rb
97
111
  - lib/iso8601/weeks.rb
98
112
  - lib/iso8601/years.rb
113
+ - spec/iso8601/date_spec.rb
114
+ - spec/iso8601/date_time_spec.rb
115
+ - spec/iso8601/days_spec.rb
116
+ - spec/iso8601/duration_spec.rb
117
+ - spec/iso8601/hours_spec.rb
118
+ - spec/iso8601/minutes_spec.rb
119
+ - spec/iso8601/months_spec.rb
120
+ - spec/iso8601/seconds_spec.rb
121
+ - spec/iso8601/time_interval_spec.rb
122
+ - spec/iso8601/time_spec.rb
123
+ - spec/iso8601/weeks_spec.rb
124
+ - spec/iso8601/years_spec.rb
125
+ - spec/spec_helper.rb
99
126
  homepage: https://github.com/arnau/ISO8601
100
127
  licenses:
101
128
  - MIT
102
129
  metadata:
103
130
  yard.run: yri
104
- post_install_message:
131
+ post_install_message:
105
132
  rdoc_options: []
106
133
  require_paths:
107
134
  - lib
@@ -117,9 +144,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
144
  version: '0'
118
145
  requirements: []
119
146
  rubygems_version: 3.1.2
120
- signing_key:
147
+ signing_key:
121
148
  specification_version: 4
122
149
  summary: Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601
123
150
  test_files:
124
- - iso8601.gemspec
125
- - Gemfile
151
+ - spec/spec_helper.rb
152
+ - spec/iso8601/minutes_spec.rb
153
+ - spec/iso8601/time_spec.rb
154
+ - spec/iso8601/seconds_spec.rb
155
+ - spec/iso8601/date_spec.rb
156
+ - spec/iso8601/years_spec.rb
157
+ - spec/iso8601/days_spec.rb
158
+ - spec/iso8601/weeks_spec.rb
159
+ - spec/iso8601/date_time_spec.rb
160
+ - spec/iso8601/hours_spec.rb
161
+ - spec/iso8601/time_interval_spec.rb
162
+ - spec/iso8601/duration_spec.rb
163
+ - spec/iso8601/months_spec.rb
@@ -1,57 +0,0 @@
1
- # Contributing
2
-
3
- Thanks for taking the time to submit a pull request! These are the few
4
- guidelines to keep things coherent.
5
-
6
- [Fork the project](http://github.com/arnau/ISO8601/fork) and clone.
7
-
8
- Create your _feature_ branch:
9
-
10
- ```sh
11
- git checkout -b features/xyz
12
- ```
13
-
14
- Set up your machine. I recommend using [Docker](https://docker.com):
15
-
16
- ```sh
17
- make install
18
- ```
19
-
20
- But of course you can go raw style
21
-
22
- ```sh
23
- bundle install
24
- ```
25
-
26
- Add your code and tests and check it passes:
27
-
28
- ```sh
29
- make test # mri, jruby
30
- # or
31
- make mri-test
32
- make jruby-test
33
- ```
34
-
35
- Or raw style
36
-
37
- ```sh
38
- bundle exec rspec
39
- ```
40
-
41
- Although not required, try to adhere to Rubocop's checks:
42
-
43
- ```sh
44
- make check
45
- ```
46
-
47
- Or raw style
48
-
49
- ```sh
50
- bundle exec rubocop
51
- ```
52
-
53
- Push your branch and submit a [Pull Request](https://github.com/arnau/iso8601/compare/).
54
-
55
- Add a description of your proposed changes and why they are needed.
56
-
57
- I'll review it as soon as I can.
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec
@@ -1,29 +0,0 @@
1
- $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
- require 'iso8601/version'
3
-
4
- # rubocop:disable Metrics/BlockLength
5
- Gem::Specification.new do |s|
6
- s.name = 'iso8601'
7
- s.version = ISO8601::VERSION
8
- s.date = Time.now.strftime('%Y-%m-%d')
9
- s.authors = ['Arnau Siches']
10
- s.email = 'arnau.siches@gmail.com'
11
- s.homepage = 'https://github.com/arnau/ISO8601'
12
- s.summary = "Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601"
13
- s.description = <<-DESC
14
- ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data elements and
15
- interchange formats - Information interchange - Representation of dates
16
- and times) standard.
17
- DESC
18
- s.license = 'MIT'
19
- s.files = %w{LICENSE README.md CONTRIBUTING.md} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:lib/)}i }
20
- s.test_files = %w{iso8601.gemspec Gemfile} + `git ls-files`.split("\n").select { |f| f =~ %r{^(?:specs/)}i }
21
- s.require_paths = ['lib']
22
-
23
- s.metadata["yard.run"] = "yri"
24
- s.required_ruby_version = '>= 2.0.0'
25
- s.add_development_dependency 'rspec', '~> 3.9'
26
- s.add_development_dependency 'rubocop', '~> 0.85'
27
- s.add_development_dependency 'pry', '~> 0.13.1'
28
- s.add_development_dependency 'pry-doc', '~> 1.1.0'
29
- end