tempora 0.1.3 → 0.2.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/lib/month.rb +4 -12
- data/lib/quarter.rb +11 -15
- data/lib/tempora/has_months.rb +9 -0
- data/lib/tempora/has_weeks.rb +11 -0
- data/lib/{initialization.rb → tempora/initialization.rb} +1 -3
- data/lib/tempora/version.rb +1 -1
- data/lib/tempora.rb +0 -1
- data/lib/timeperiod.rb +9 -5
- data/lib/week.rb +2 -3
- data/lib/year.rb +6 -21
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829bad4acfece329fa910614c27da039a46933e2da7246d091df30fd1463cee5
|
4
|
+
data.tar.gz: 6d2d1e27e904b76d6f2661fb8328b8a3bceb83c142ffe376f76d261e66fdea07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff6c9aec13bd9eb4ce86085043887f750101a722d64a30d6b8af43e7e52962632e91b8dbb74561cf0df02d05acb7928234ab892eafbe3fe1930bbe6f05cf64cb
|
7
|
+
data.tar.gz: '08cc00d8bbac916783277803a0ef3279a7db353bd3a9e5743d2a0576824939e0b1b1039bea1143120068cf995060ac4bb0d827b553d73a2a368e902d69bbd40a'
|
data/lib/month.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative 'timeperiod'
|
2
|
-
require_relative 'initialization'
|
3
|
-
require_relative '
|
2
|
+
require_relative 'tempora/initialization'
|
3
|
+
require_relative 'tempora/has_weeks'
|
4
4
|
|
5
|
-
class Month
|
6
|
-
include TimePeriod
|
5
|
+
class Month < TimePeriod
|
7
6
|
extend Initialization
|
7
|
+
include HasWeeks
|
8
8
|
|
9
9
|
def initialize(year, month)
|
10
10
|
@year = Integer(year)
|
@@ -38,14 +38,6 @@ class Month
|
|
38
38
|
self.class.from(start_date.prev_month) # @start_date << 1
|
39
39
|
end
|
40
40
|
|
41
|
-
def weeks
|
42
|
-
Week.from(start_date)..Week.from(end_date)
|
43
|
-
end
|
44
|
-
|
45
|
-
def each_week(&block)
|
46
|
-
weeks.each(&block)
|
47
|
-
end
|
48
|
-
|
49
41
|
alias_method :month, :number
|
50
42
|
alias_method :succ, :next
|
51
43
|
alias_method :pred, :prev
|
data/lib/quarter.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require_relative 'timeperiod'
|
2
|
-
require_relative 'initialization'
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
2
|
+
require_relative 'tempora/initialization'
|
3
|
+
require_relative 'tempora/has_months'
|
4
|
+
require_relative 'tempora/has_weeks'
|
5
5
|
|
6
|
-
class Quarter
|
7
|
-
include TimePeriod
|
6
|
+
class Quarter < TimePeriod
|
8
7
|
extend Initialization
|
8
|
+
include HasMonths
|
9
|
+
include HasWeeks
|
9
10
|
|
10
11
|
def initialize(year, quarter)
|
11
12
|
@year = Integer(year)
|
@@ -34,19 +35,14 @@ class Quarter
|
|
34
35
|
|
35
36
|
alias_method :succ, :next
|
36
37
|
alias_method :pred, :prev
|
37
|
-
|
38
|
-
def months
|
39
|
-
Month.from(start_date)..Month.from(end_date)
|
40
|
-
end
|
41
|
-
|
42
|
-
def weeks
|
43
|
-
Week.from(start_date)..Week.from(end_date)
|
44
|
-
end
|
45
38
|
|
46
39
|
private
|
47
40
|
|
48
41
|
def self.initialization_parameter(date)
|
49
|
-
|
50
|
-
|
42
|
+
[date.year, quarter_from_date(date)]
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.quarter_from_date(date)
|
46
|
+
((date.month - 1) / 3) + 1
|
51
47
|
end
|
52
48
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
1
|
module Initialization
|
4
2
|
def now
|
5
3
|
from Time.now
|
@@ -8,7 +6,7 @@ module Initialization
|
|
8
6
|
alias_method :current, :now
|
9
7
|
|
10
8
|
def from(date)
|
11
|
-
new
|
9
|
+
new(*initialization_parameter(date.to_date))
|
12
10
|
end
|
13
11
|
|
14
12
|
private
|
data/lib/tempora/version.rb
CHANGED
data/lib/tempora.rb
CHANGED
data/lib/timeperiod.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
require 'date'
|
2
2
|
|
3
|
-
|
3
|
+
class TimePeriod
|
4
4
|
include Comparable
|
5
5
|
|
6
6
|
attr_reader :start_date, :end_date, :year, :number
|
7
|
+
|
8
|
+
def initialize(start_date, end_date)
|
9
|
+
@start_date = start_date
|
10
|
+
@end_date = end_date
|
11
|
+
end
|
7
12
|
|
8
13
|
def range
|
9
14
|
start_date..end_date
|
@@ -26,7 +31,7 @@ module TimePeriod
|
|
26
31
|
end
|
27
32
|
|
28
33
|
def overlaps?(other)
|
29
|
-
range.
|
34
|
+
range.overlap?(other.range)
|
30
35
|
end
|
31
36
|
|
32
37
|
def intersection(other)
|
@@ -35,7 +40,7 @@ module TimePeriod
|
|
35
40
|
new_start = [start_date, other.start_date].max
|
36
41
|
new_end = [end_date, other.end_date].min
|
37
42
|
|
38
|
-
|
43
|
+
TimePeriod.new(new_start, new_end)
|
39
44
|
end
|
40
45
|
|
41
46
|
def <=>(other)
|
@@ -45,5 +50,4 @@ module TimePeriod
|
|
45
50
|
alias_method :begin, :start_date
|
46
51
|
alias_method :end, :end_date
|
47
52
|
alias_method :length, :duration
|
48
|
-
end
|
49
|
-
|
53
|
+
end
|
data/lib/week.rb
CHANGED
data/lib/year.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require_relative 'timeperiod'
|
2
|
-
require_relative 'initialization'
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
2
|
+
require_relative 'tempora/initialization'
|
3
|
+
require_relative 'tempora/has_months'
|
4
|
+
require_relative 'tempora/has_weeks'
|
5
5
|
|
6
|
-
class Year
|
7
|
-
include TimePeriod
|
6
|
+
class Year < TimePeriod
|
8
7
|
extend Initialization
|
8
|
+
include HasWeeks
|
9
|
+
include HasMonths
|
9
10
|
|
10
11
|
def initialize(year)
|
11
12
|
@year = Integer(year)
|
@@ -29,22 +30,6 @@ class Year
|
|
29
30
|
def prev
|
30
31
|
self.class.new(year - 1)
|
31
32
|
end
|
32
|
-
|
33
|
-
def months
|
34
|
-
Month.new(year, 1)..Month.new(year, 12)
|
35
|
-
end
|
36
|
-
|
37
|
-
def weeks
|
38
|
-
Week.from(start_date)..Week.from(end_date)
|
39
|
-
end
|
40
|
-
|
41
|
-
def each_month(&block)
|
42
|
-
months.each(&block)
|
43
|
-
end
|
44
|
-
|
45
|
-
def each_week(&block)
|
46
|
-
weeks.each(&block)
|
47
|
-
end
|
48
33
|
|
49
34
|
alias_method :succ, :next
|
50
35
|
alias_method :pred, :prev
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tempora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Power
|
@@ -21,10 +21,12 @@ files:
|
|
21
21
|
- README.md
|
22
22
|
- Rakefile
|
23
23
|
- lib/_timespan.rb
|
24
|
-
- lib/initialization.rb
|
25
24
|
- lib/month.rb
|
26
25
|
- lib/quarter.rb
|
27
26
|
- lib/tempora.rb
|
27
|
+
- lib/tempora/has_months.rb
|
28
|
+
- lib/tempora/has_weeks.rb
|
29
|
+
- lib/tempora/initialization.rb
|
28
30
|
- lib/tempora/version.rb
|
29
31
|
- lib/timeperiod.rb
|
30
32
|
- lib/week.rb
|