iso8601 0.8.7 → 0.9.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/CHANGELOG.md +17 -0
- data/CONTRIBUTING.md +58 -0
- data/Gemfile +2 -2
- data/README.md +28 -102
- data/docs/date-time.md +86 -0
- data/docs/duration.md +77 -0
- data/docs/time-interval.md +120 -0
- data/iso8601.gemspec +43 -6
- data/lib/iso8601.rb +15 -7
- data/lib/iso8601/atomic.rb +78 -0
- data/lib/iso8601/date.rb +35 -10
- data/lib/iso8601/date_time.rb +14 -3
- data/lib/iso8601/days.rb +47 -0
- data/lib/iso8601/duration.rb +115 -99
- data/lib/iso8601/errors.rb +13 -1
- data/lib/iso8601/hours.rb +43 -0
- data/lib/iso8601/minutes.rb +43 -0
- data/lib/iso8601/months.rb +98 -0
- data/lib/iso8601/seconds.rb +47 -0
- data/lib/iso8601/time.rb +43 -15
- data/lib/iso8601/time_interval.rb +392 -0
- data/lib/iso8601/version.rb +1 -1
- data/lib/iso8601/weeks.rb +43 -0
- data/lib/iso8601/years.rb +80 -0
- data/spec/iso8601/date_spec.rb +0 -6
- data/spec/iso8601/date_time_spec.rb +0 -8
- data/spec/iso8601/days_spec.rb +44 -0
- data/spec/iso8601/duration_spec.rb +103 -99
- data/spec/iso8601/hours_spec.rb +44 -0
- data/spec/iso8601/minutes_spec.rb +44 -0
- data/spec/iso8601/months_spec.rb +86 -0
- data/spec/iso8601/seconds_spec.rb +44 -0
- data/spec/iso8601/time_interval_spec.rb +416 -0
- data/spec/iso8601/time_spec.rb +0 -6
- data/spec/iso8601/weeks_spec.rb +46 -0
- data/spec/iso8601/years_spec.rb +69 -0
- metadata +37 -19
- data/.dockerignore +0 -7
- data/.editorconfig +0 -9
- data/.gitignore +0 -19
- data/.rubocop.yml +0 -38
- data/.travis.yml +0 -19
- data/Dockerfile +0 -10
- data/Makefile +0 -19
- data/circle.yml +0 -13
- data/lib/iso8601/atoms.rb +0 -279
- data/spec/iso8601/atoms_spec.rb +0 -329
data/spec/iso8601/time_spec.rb
CHANGED
@@ -68,9 +68,6 @@ describe ISO8601::Time do
|
|
68
68
|
expect((ISO8601::Time.new('T20:20:20.5Z') + 10).second).to eq(30.5)
|
69
69
|
expect((ISO8601::Time.new('T20:20:20+02:00') + 10.09).second).to eq(30.1)
|
70
70
|
end
|
71
|
-
it "should return the result of the addition of a Duration" do
|
72
|
-
expect((ISO8601::Time.new('T20:20:20Z') + ISO8601::Duration.new("PT10S")).to_s).to eq('T20:20:30+00:00')
|
73
|
-
end
|
74
71
|
end
|
75
72
|
|
76
73
|
describe '#-' do
|
@@ -78,9 +75,6 @@ describe ISO8601::Time do
|
|
78
75
|
expect((ISO8601::Time.new('T20:20:20+01:00') - 10).to_s).to eq('T20:20:10+01:00')
|
79
76
|
expect((ISO8601::Time.new('T20:20:20.11+02:00') - 10).to_s).to eq('T20:20:10.1+02:00')
|
80
77
|
end
|
81
|
-
it "should return the result of the subtraction of a Duration" do
|
82
|
-
expect((ISO8601::Time.new('T20:20:20+01:00') - ISO8601::Duration.new("PT10S")).to_s).to eq('T20:20:10+01:00')
|
83
|
-
end
|
84
78
|
end
|
85
79
|
|
86
80
|
describe '#to_a' do
|
@@ -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
|
+
[: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,69 @@
|
|
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
|
+
[: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
|
+
end
|
35
|
+
|
36
|
+
it "should return the Year factor for a leap year" do
|
37
|
+
expect(ISO8601::Years.new(1).factor(leap_year)).to eq(31622400)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#to_seconds' do
|
42
|
+
it "should return the amount of seconds" do
|
43
|
+
expect(ISO8601::Years.new(2).to_seconds).to eq(63072000)
|
44
|
+
expect(ISO8601::Years.new(-2).to_seconds).to eq(-63072000)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return the amount of seconds for a common year" do
|
48
|
+
expect(ISO8601::Years.new(2).to_seconds(common_year)).to eq(63072000)
|
49
|
+
expect(ISO8601::Years.new(12).to_seconds(common_year)).to eq(378691200)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return the amount of seconds for a leap year" do
|
53
|
+
expect(ISO8601::Years.new(2).to_seconds(leap_year)).to eq(63158400)
|
54
|
+
expect(ISO8601::Years.new(15).to_seconds(leap_year)).to eq(473385600)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#symbol' do
|
59
|
+
it "should return the ISO symbol" do
|
60
|
+
expect(ISO8601::Years.new(1).symbol).to eq(:Y)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#hash' do
|
65
|
+
it "should build hash identity by value" do
|
66
|
+
expect(ISO8601::Years.new(3).hash).to eq(ISO8601::Years.new(3).hash)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
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.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnau Siches
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.4'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.35'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.35'
|
41
41
|
description: |2
|
42
42
|
ISO8601 is a simple implementation in Ruby of the ISO 8601 (Data elements and
|
43
43
|
interchange formats - Information interchange - Representation of dates
|
@@ -47,33 +47,44 @@ executables: []
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
-
- ".dockerignore"
|
51
|
-
- ".editorconfig"
|
52
|
-
- ".gitignore"
|
53
|
-
- ".rubocop.yml"
|
54
|
-
- ".travis.yml"
|
55
50
|
- CHANGELOG.md
|
56
|
-
-
|
51
|
+
- CONTRIBUTING.md
|
57
52
|
- Gemfile
|
58
53
|
- LICENSE
|
59
|
-
- Makefile
|
60
54
|
- README.md
|
61
55
|
- Rakefile
|
62
|
-
-
|
56
|
+
- docs/date-time.md
|
57
|
+
- docs/duration.md
|
58
|
+
- docs/time-interval.md
|
63
59
|
- iso8601.gemspec
|
64
60
|
- lib/iso8601.rb
|
65
|
-
- lib/iso8601/
|
61
|
+
- lib/iso8601/atomic.rb
|
66
62
|
- lib/iso8601/date.rb
|
67
63
|
- lib/iso8601/date_time.rb
|
64
|
+
- lib/iso8601/days.rb
|
68
65
|
- lib/iso8601/duration.rb
|
69
66
|
- lib/iso8601/errors.rb
|
67
|
+
- lib/iso8601/hours.rb
|
68
|
+
- lib/iso8601/minutes.rb
|
69
|
+
- lib/iso8601/months.rb
|
70
|
+
- lib/iso8601/seconds.rb
|
70
71
|
- lib/iso8601/time.rb
|
72
|
+
- lib/iso8601/time_interval.rb
|
71
73
|
- lib/iso8601/version.rb
|
72
|
-
-
|
74
|
+
- lib/iso8601/weeks.rb
|
75
|
+
- lib/iso8601/years.rb
|
73
76
|
- spec/iso8601/date_spec.rb
|
74
77
|
- spec/iso8601/date_time_spec.rb
|
78
|
+
- spec/iso8601/days_spec.rb
|
75
79
|
- spec/iso8601/duration_spec.rb
|
80
|
+
- spec/iso8601/hours_spec.rb
|
81
|
+
- spec/iso8601/minutes_spec.rb
|
82
|
+
- spec/iso8601/months_spec.rb
|
83
|
+
- spec/iso8601/seconds_spec.rb
|
84
|
+
- spec/iso8601/time_interval_spec.rb
|
76
85
|
- spec/iso8601/time_spec.rb
|
86
|
+
- spec/iso8601/weeks_spec.rb
|
87
|
+
- spec/iso8601/years_spec.rb
|
77
88
|
- spec/spec_helper.rb
|
78
89
|
homepage: https://github.com/arnau/ISO8601
|
79
90
|
licenses:
|
@@ -87,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
98
|
requirements:
|
88
99
|
- - ">="
|
89
100
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
101
|
+
version: 2.0.0
|
91
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
103
|
requirements:
|
93
104
|
- - ">="
|
@@ -95,15 +106,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
106
|
version: '0'
|
96
107
|
requirements: []
|
97
108
|
rubyforge_project: iso8601
|
98
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.5.0
|
99
110
|
signing_key:
|
100
111
|
specification_version: 4
|
101
112
|
summary: Ruby parser to work with ISO 8601 dateTimes and durations - http://en.wikipedia.org/wiki/ISO_8601
|
102
113
|
test_files:
|
103
|
-
- spec/iso8601/atoms_spec.rb
|
104
114
|
- spec/iso8601/date_spec.rb
|
105
115
|
- spec/iso8601/date_time_spec.rb
|
116
|
+
- spec/iso8601/days_spec.rb
|
106
117
|
- spec/iso8601/duration_spec.rb
|
118
|
+
- spec/iso8601/hours_spec.rb
|
119
|
+
- spec/iso8601/minutes_spec.rb
|
120
|
+
- spec/iso8601/months_spec.rb
|
121
|
+
- spec/iso8601/seconds_spec.rb
|
122
|
+
- spec/iso8601/time_interval_spec.rb
|
107
123
|
- spec/iso8601/time_spec.rb
|
124
|
+
- spec/iso8601/weeks_spec.rb
|
125
|
+
- spec/iso8601/years_spec.rb
|
108
126
|
- spec/spec_helper.rb
|
109
127
|
has_rdoc: yard
|
data/.dockerignore
DELETED
data/.editorconfig
DELETED
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
Documentation:
|
2
|
-
Enabled: false
|
3
|
-
|
4
|
-
Lint/UselessComparison:
|
5
|
-
Enabled: false
|
6
|
-
|
7
|
-
Metrics/ClassLength:
|
8
|
-
Max: 150
|
9
|
-
|
10
|
-
# Work in progress
|
11
|
-
Metrics/LineLength:
|
12
|
-
Max: 183
|
13
|
-
|
14
|
-
# Work in progress
|
15
|
-
Metrics/MethodLength:
|
16
|
-
Max: 24
|
17
|
-
|
18
|
-
# Work in progress
|
19
|
-
Metrics/PerceivedComplexity:
|
20
|
-
Max: 8
|
21
|
-
|
22
|
-
Style/Blocks:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Style/NumericLiterals:
|
26
|
-
MinDigits: 10
|
27
|
-
|
28
|
-
Style/RegexpLiteral:
|
29
|
-
MaxSlashes: 0
|
30
|
-
|
31
|
-
Style/StringLiterals:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Style/Encoding:
|
35
|
-
EnforcedStyle: when_needed
|
36
|
-
|
37
|
-
Style/BracesAroundHashParameters:
|
38
|
-
EnforcedStyle: braces
|
data/.travis.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 1.9.3
|
4
|
-
- 2.0.0
|
5
|
-
- 2.1.2
|
6
|
-
- 2.2.0
|
7
|
-
- ruby-head
|
8
|
-
- rbx-2
|
9
|
-
- jruby-head
|
10
|
-
script: bundle exec rspec spec
|
11
|
-
matrix:
|
12
|
-
include:
|
13
|
-
- rvm: jruby
|
14
|
-
env: JRUBY_OPTS='--2.0'
|
15
|
-
allow_failures:
|
16
|
-
- rvm: jruby-head
|
17
|
-
- rvm: ruby-head
|
18
|
-
- rvm: rbx-2
|
19
|
-
fast_finish: true
|
data/Dockerfile
DELETED
data/Makefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
TAG ?= latest
|
2
|
-
IMAGE_NAME ?= arnau/iso8601
|
3
|
-
IMAGE = $(IMAGE_NAME):$(TAG)
|
4
|
-
|
5
|
-
install: build
|
6
|
-
|
7
|
-
build:
|
8
|
-
docker build -t $(IMAGE) .
|
9
|
-
|
10
|
-
test:
|
11
|
-
docker run -t --rm -v $$(pwd):/usr/src/iso8601 $(IMAGE)
|
12
|
-
|
13
|
-
shell:
|
14
|
-
docker run -it --rm -v $$(pwd):/usr/src/iso8601 $(IMAGE) \
|
15
|
-
pry -r ./lib/iso8601
|
16
|
-
|
17
|
-
gem:
|
18
|
-
docker run -t --rm -v $$(pwd):/usr/src/iso8601 $(IMAGE) \
|
19
|
-
bundle exec rake build
|
data/circle.yml
DELETED
data/lib/iso8601/atoms.rb
DELETED
@@ -1,279 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module ISO8601
|
4
|
-
##
|
5
|
-
# A generic atom in a {ISO8601::Duration}
|
6
|
-
#
|
7
|
-
# @abstract
|
8
|
-
class Atom
|
9
|
-
include Comparable
|
10
|
-
##
|
11
|
-
# @param [Numeric] atom The atom value
|
12
|
-
# @param [ISO8601::DateTime, nil] base (nil) The base datetime to compute
|
13
|
-
# the atom factor.
|
14
|
-
def initialize(atom, base = nil)
|
15
|
-
fail TypeError, "The atom argument for #{inspect} should be a Numeric value." unless atom.is_a?(Numeric)
|
16
|
-
fail TypeError, "The base argument for #{inspect} should be a ISO8601::DateTime instance or nil." unless base.is_a?(ISO8601::DateTime) || base.nil?
|
17
|
-
@atom = atom
|
18
|
-
@base = base
|
19
|
-
end
|
20
|
-
attr_reader :atom
|
21
|
-
attr_reader :base
|
22
|
-
##
|
23
|
-
# The integer representation
|
24
|
-
#
|
25
|
-
# @return [Integer]
|
26
|
-
def to_i
|
27
|
-
atom.to_i
|
28
|
-
end
|
29
|
-
##
|
30
|
-
# The float representation
|
31
|
-
#
|
32
|
-
# @return [Float]
|
33
|
-
def to_f
|
34
|
-
atom.to_f
|
35
|
-
end
|
36
|
-
##
|
37
|
-
# Returns the ISO 8601 representation for the atom
|
38
|
-
#
|
39
|
-
# @return [String]
|
40
|
-
def to_s
|
41
|
-
(value.zero?) ? '' : "#{value}#{symbol}"
|
42
|
-
end
|
43
|
-
##
|
44
|
-
# The simplest numeric representation. If modulo equals 0 returns an
|
45
|
-
# integer else a float.
|
46
|
-
#
|
47
|
-
# @return [Numeric]
|
48
|
-
def value
|
49
|
-
(atom % 1).zero? ? atom.to_i : atom
|
50
|
-
end
|
51
|
-
##
|
52
|
-
# The amount of seconds
|
53
|
-
#
|
54
|
-
# @return [Numeric]
|
55
|
-
def to_seconds
|
56
|
-
atom * factor
|
57
|
-
end
|
58
|
-
##
|
59
|
-
# @param [Atom] other The contrast to compare against
|
60
|
-
#
|
61
|
-
# @return [-1, 0, 1]
|
62
|
-
def <=>(other)
|
63
|
-
return nil unless other.kind_of?(self.class)
|
64
|
-
|
65
|
-
to_f <=> other.to_f
|
66
|
-
end
|
67
|
-
##
|
68
|
-
# @param [#hash] other The contrast to compare against
|
69
|
-
#
|
70
|
-
# @return [Boolean]
|
71
|
-
def eql?(other)
|
72
|
-
(hash == other.hash)
|
73
|
-
end
|
74
|
-
##
|
75
|
-
# @return [Fixnum]
|
76
|
-
def hash
|
77
|
-
[atom, self.class].hash
|
78
|
-
end
|
79
|
-
##
|
80
|
-
# The atom factor to compute the amount of seconds for the atom
|
81
|
-
def factor
|
82
|
-
fail NotImplementedError,
|
83
|
-
"The #factor method should be implemented by each subclass"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
##
|
87
|
-
# A Years atom in a {ISO8601::Duration}
|
88
|
-
#
|
89
|
-
# A "calendar year" is the cyclic time interval in a calendar which is
|
90
|
-
# required for one revolution of the Earth around the Sun and approximated to
|
91
|
-
# an integral number of "calendar days".
|
92
|
-
#
|
93
|
-
# A "duration year" is the duration of 365 or 366 "calendar days" depending
|
94
|
-
# on the start and/or the end of the corresponding time interval within the
|
95
|
-
# specific "calendar year".
|
96
|
-
class Years < ISO8601::Atom
|
97
|
-
##
|
98
|
-
# The Year factor
|
99
|
-
#
|
100
|
-
# The "duration year" average is calculated through time intervals of 400
|
101
|
-
# "duration years". Each cycle of 400 "duration years" has 303 "common
|
102
|
-
# years" of 365 "calendar days" and 97 "leap years" of 366 "calendar days".
|
103
|
-
#
|
104
|
-
# @return [Integer]
|
105
|
-
def factor
|
106
|
-
if base.nil?
|
107
|
-
((365 * 303 + 366 * 97) / 400) * 86400
|
108
|
-
elsif atom.zero?
|
109
|
-
year = (base.year).to_i
|
110
|
-
(::Time.utc(year) - ::Time.utc(base.year))
|
111
|
-
else
|
112
|
-
year = (base.year + atom).to_i
|
113
|
-
(::Time.utc(year) - ::Time.utc(base.year)) / atom
|
114
|
-
end
|
115
|
-
end
|
116
|
-
##
|
117
|
-
# The atom symbol.
|
118
|
-
#
|
119
|
-
# @return [Symbol]
|
120
|
-
def symbol
|
121
|
-
:Y
|
122
|
-
end
|
123
|
-
end
|
124
|
-
##
|
125
|
-
# A Months atom in a {ISO8601::Duration}
|
126
|
-
#
|
127
|
-
# A "calendar month" is the time interval resulting from the division of a
|
128
|
-
# "calendar year" in 12 time intervals.
|
129
|
-
#
|
130
|
-
# A "duration month" is the duration of 28, 29, 30 or 31 "calendar days"
|
131
|
-
# depending on the start and/or the end of the corresponding time interval
|
132
|
-
# within the specific "calendar month".
|
133
|
-
class Months < ISO8601::Atom
|
134
|
-
##
|
135
|
-
# The Month factor
|
136
|
-
#
|
137
|
-
# The "duration month" average is calculated through time intervals of 400
|
138
|
-
# "duration years". Each cycle of 400 "duration years" has 303 "common
|
139
|
-
# years" of 365 "calendar days" and 97 "leap years" of 366 "calendar days".
|
140
|
-
def factor
|
141
|
-
if base.nil?
|
142
|
-
nobase_calculation
|
143
|
-
elsif atom.zero?
|
144
|
-
zero_calculation
|
145
|
-
else
|
146
|
-
calculation
|
147
|
-
end
|
148
|
-
end
|
149
|
-
##
|
150
|
-
# The atom symbol.
|
151
|
-
#
|
152
|
-
# @return [Symbol]
|
153
|
-
def symbol
|
154
|
-
:M
|
155
|
-
end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
def nobase_calculation
|
160
|
-
(((365 * 303 + 366 * 97) / 400) * 86400) / 12
|
161
|
-
end
|
162
|
-
|
163
|
-
def zero_calculation
|
164
|
-
month = (base.month <= 12) ? base.month : (base.month % 12)
|
165
|
-
year = base.year + ((base.month) / 12).to_i
|
166
|
-
|
167
|
-
(::Time.utc(year, month) - ::Time.utc(base.year, base.month))
|
168
|
-
end
|
169
|
-
|
170
|
-
def calculation
|
171
|
-
initial = base.month + atom
|
172
|
-
if initial <= 0
|
173
|
-
month = base.month + atom
|
174
|
-
|
175
|
-
if initial % 12 == 0
|
176
|
-
year = base.year + (initial / 12) - 1
|
177
|
-
month = 12
|
178
|
-
else
|
179
|
-
year = base.year + (initial / 12).floor
|
180
|
-
month = (12 + initial > 0) ? (12 + initial) : (12 + (initial % -12))
|
181
|
-
end
|
182
|
-
else
|
183
|
-
month = (initial <= 12) ? initial : (initial % 12)
|
184
|
-
month = 12 if month.zero?
|
185
|
-
year = base.year + ((base.month + atom) / 12).to_i
|
186
|
-
end
|
187
|
-
|
188
|
-
(::Time.utc(year, month) - ::Time.utc(base.year, base.month)) / atom
|
189
|
-
end
|
190
|
-
end
|
191
|
-
##
|
192
|
-
# A Weeks atom in a {ISO8601::Duration}
|
193
|
-
class Weeks < ISO8601::Atom
|
194
|
-
##
|
195
|
-
# The Week factor
|
196
|
-
def factor
|
197
|
-
604800
|
198
|
-
end
|
199
|
-
##
|
200
|
-
# The atom symbol.
|
201
|
-
#
|
202
|
-
# @return [Symbol]
|
203
|
-
def symbol
|
204
|
-
:W
|
205
|
-
end
|
206
|
-
end
|
207
|
-
##
|
208
|
-
# The Days atom in a {ISO8601::Duration}
|
209
|
-
#
|
210
|
-
# A "calendar day" is the time interval which starts at a certain time of day
|
211
|
-
# at a certain "calendar day" and ends at the same time of day at the next
|
212
|
-
# "calendar day".
|
213
|
-
class Days < ISO8601::Atom
|
214
|
-
##
|
215
|
-
# The Day factor
|
216
|
-
def factor
|
217
|
-
86400
|
218
|
-
end
|
219
|
-
##
|
220
|
-
# The atom symbol.
|
221
|
-
#
|
222
|
-
# @return [Symbol]
|
223
|
-
def symbol
|
224
|
-
:D
|
225
|
-
end
|
226
|
-
end
|
227
|
-
##
|
228
|
-
# The Hours atom in a {ISO8601::Duration}
|
229
|
-
class Hours < ISO8601::Atom
|
230
|
-
##
|
231
|
-
# The Hour factor
|
232
|
-
def factor
|
233
|
-
3600
|
234
|
-
end
|
235
|
-
##
|
236
|
-
# The atom symbol.
|
237
|
-
#
|
238
|
-
# @return [Symbol]
|
239
|
-
def symbol
|
240
|
-
:H
|
241
|
-
end
|
242
|
-
end
|
243
|
-
##
|
244
|
-
# The Minutes atom in a {ISO8601::Duration}
|
245
|
-
class Minutes < ISO8601::Atom
|
246
|
-
##
|
247
|
-
# The Minute factor
|
248
|
-
def factor
|
249
|
-
60
|
250
|
-
end
|
251
|
-
##
|
252
|
-
# The atom symbol.
|
253
|
-
#
|
254
|
-
# @return [Symbol]
|
255
|
-
def symbol
|
256
|
-
:M
|
257
|
-
end
|
258
|
-
end
|
259
|
-
##
|
260
|
-
# The Seconds atom in a {ISO8601::Duration}
|
261
|
-
#
|
262
|
-
# The second is the base unit of measurement of time in the International
|
263
|
-
# System of Units (SI) as defined by the International Committee of Weights
|
264
|
-
# and Measures.
|
265
|
-
class Seconds < ISO8601::Atom
|
266
|
-
##
|
267
|
-
# The Second factor
|
268
|
-
def factor
|
269
|
-
1
|
270
|
-
end
|
271
|
-
##
|
272
|
-
# The atom symbol.
|
273
|
-
#
|
274
|
-
# @return [Symbol]
|
275
|
-
def symbol
|
276
|
-
:S
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|