fiscaly 1.1.0 → 1.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/CHANGELOG.md +6 -0
- data/lib/fiscaly.rb +34 -12
- data/lib/fiscaly/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '01081761f20ba665100b05af9b8a78a25fa55842814165402befca7888733083'
|
4
|
+
data.tar.gz: d7d519ce2ba94716502aead282c31c8985c66ab5d9a3a2e0279d74ecc3d35b53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 283253dbc0100b0dfccba65926ca3c4b6aba61694cadfd640229f27175fb10d7bafc90c19d490b31f866b7ad2e4f8879f987acf486e4acb4becfa5a1a144e4ee
|
7
|
+
data.tar.gz: feaa6a08ab79459935d005031cea5f9f52a7a0073fd0948c5c97ba21770e2976305d22b2e2580c3de495c34cb2856b23c21ee93acbaec68202172ae920178b7b
|
data/CHANGELOG.md
CHANGED
data/lib/fiscaly.rb
CHANGED
@@ -5,12 +5,6 @@ require 'fiscaly/version'
|
|
5
5
|
class Fiscaly
|
6
6
|
KEY = :fiscaly_options
|
7
7
|
|
8
|
-
cattr_accessor :options
|
9
|
-
@@options = {
|
10
|
-
start_month: 4,
|
11
|
-
forward_fyear: false
|
12
|
-
}
|
13
|
-
|
14
8
|
attr_reader :date
|
15
9
|
attr_reader :options
|
16
10
|
|
@@ -31,13 +25,17 @@ class Fiscaly
|
|
31
25
|
@options[:start_month]
|
32
26
|
end
|
33
27
|
|
28
|
+
def start_day
|
29
|
+
@options[:start_day]
|
30
|
+
end
|
31
|
+
|
34
32
|
def forward_fyear?
|
35
33
|
@options[:forward_fyear]
|
36
34
|
end
|
37
35
|
|
38
36
|
def fyear
|
39
37
|
fy = @date.year
|
40
|
-
fy -= 1 if @date.month < start_month
|
38
|
+
fy -= 1 if @date.month < start_month || (@date.month == start_month && @date.day < start_day)
|
41
39
|
fy += 1 if forward_fyear?
|
42
40
|
fy
|
43
41
|
end
|
@@ -48,11 +46,11 @@ class Fiscaly
|
|
48
46
|
|
49
47
|
def beginning_of_fyear
|
50
48
|
year = forward_fyear? ? fyear - 1 : fyear
|
51
|
-
Date.new(year, start_month)
|
49
|
+
Date.new(year, start_month, start_day)
|
52
50
|
end
|
53
51
|
|
54
52
|
def end_of_fyear
|
55
|
-
|
53
|
+
beginning_of_fyear + 12.months - 1.days
|
56
54
|
end
|
57
55
|
|
58
56
|
def range_of_fyear
|
@@ -70,7 +68,7 @@ class Fiscaly
|
|
70
68
|
end
|
71
69
|
|
72
70
|
def end_of_fhalf(index = nil)
|
73
|
-
|
71
|
+
beginning_of_fhalf(index) + 6.months - 1.days
|
74
72
|
end
|
75
73
|
|
76
74
|
def range_of_fhalf(index = nil)
|
@@ -88,13 +86,25 @@ class Fiscaly
|
|
88
86
|
end
|
89
87
|
|
90
88
|
def end_of_fquarter(index = nil)
|
91
|
-
|
89
|
+
beginning_of_fquarter(index) + 3.months - 1.days
|
92
90
|
end
|
93
91
|
|
94
92
|
def range_of_fquarter(index = nil)
|
95
93
|
beginning_of_fquarter(index)..end_of_fquarter(index)
|
96
94
|
end
|
97
95
|
|
96
|
+
def beginning_of_fmonth
|
97
|
+
Date.new(year, month, start_day)
|
98
|
+
end
|
99
|
+
|
100
|
+
def end_of_fmonth
|
101
|
+
beginning_of_fmonth + 1.month - 1.days
|
102
|
+
end
|
103
|
+
|
104
|
+
def range_of_fmonth
|
105
|
+
beginning_of_fmonth..end_of_fmonth
|
106
|
+
end
|
107
|
+
|
98
108
|
def range_of_month
|
99
109
|
@date.beginning_of_month..@date.end_of_month
|
100
110
|
end
|
@@ -102,6 +112,14 @@ class Fiscaly
|
|
102
112
|
private
|
103
113
|
|
104
114
|
class << self
|
115
|
+
attr_accessor :options
|
116
|
+
|
117
|
+
@@options = {
|
118
|
+
start_month: 4,
|
119
|
+
start_day: 1,
|
120
|
+
forward_fyear: false
|
121
|
+
}
|
122
|
+
|
105
123
|
def today(options = {})
|
106
124
|
date(Date.today, options)
|
107
125
|
end
|
@@ -148,6 +166,10 @@ class Fiscaly
|
|
148
166
|
@@options[:start_month] = val
|
149
167
|
end
|
150
168
|
|
169
|
+
def start_day=(val)
|
170
|
+
@@options[:start_day] = val
|
171
|
+
end
|
172
|
+
|
151
173
|
def forward_fyear=(val)
|
152
174
|
@@options[:forward_fyear] = val
|
153
175
|
end
|
@@ -157,7 +179,7 @@ class Fiscaly
|
|
157
179
|
def normalize(fyear, month, day, options = {})
|
158
180
|
options = global_options.merge(options)
|
159
181
|
year = fyear
|
160
|
-
year += 1 if month < options[:start_month]
|
182
|
+
year += 1 if month < options[:start_month] || (month == options[:start_month] && day < options[:start_day])
|
161
183
|
year -= 1 if options[:forward_fyear]
|
162
184
|
Date.new(year, month, day)
|
163
185
|
end
|
data/lib/fiscaly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiscaly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshikazu Kaneta
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.0.
|
111
|
+
rubygems_version: 3.0.3
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Financial date class for ruby
|