fiscal_year 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/fiscal_year/half.rb +4 -12
- data/lib/fiscal_year/quarter.rb +4 -4
- data/lib/fiscal_year/version.rb +1 -1
- data/lib/fiscal_year/year_to_date.rb +9 -2
- data/lib/fiscal_year.rb +16 -0
- data/sig/fiscal_year/half.rbs +1 -2
- data/sig/fiscal_year.rbs +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2a44c87e166920493e3723924cdf5c0a20cbdca0f148fb87e32a69aee645267
|
4
|
+
data.tar.gz: c6a17528d17f0cb3de8143a01227b06c7e8e527eee3a7ccc5677b637b7b3c41a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ade0c96554bc2670317108bb74851ccfd485cf4932709eafe479de937db7fab43c864a8372d895b99d774cebe6bb08520191e5015ca4ef38eb1a85a19f3d8f4
|
7
|
+
data.tar.gz: ca421f4b2fa6fd74c319bab2eb739203391f3c71d0fcd592e78018a62900e72edfcc838e7480e1d2a80af1256266c9863e014ec2873f6e8169e1a52dfbe8d1c8
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## [0.5.0] - 2024-03-18
|
2
|
+
- [BREAK] rename and move `FiscalYear::Half.normalize_year_by_month` to `FiscalYear.increase_year_by_month`
|
3
|
+
- add `FiscalYear.decrease_year_by_month` method
|
4
|
+
|
5
|
+
when year normalize, we may want to increase year or decrease year depending on the situation.
|
6
|
+
therefore, rename and add decrease method.
|
7
|
+
|
8
|
+
## [0.4.0] - 2023-06-15
|
9
|
+
- fix calculate logic of half year to date
|
10
|
+
|
1
11
|
## [0.3.0] - 2023-04-23
|
2
12
|
- add rbs
|
3
13
|
- fit to rbs
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
![build badge](https://github.com/TsubasaKawajiri/fiscal_year/actions/workflows/test.yml/badge.svg?branch=master)
|
2
|
-
|
2
|
+
|
3
3
|
[![Maintainability](https://api.codeclimate.com/v1/badges/39fdb48501c5f53235a9/maintainability)](https://codeclimate.com/github/TsubasaKawajiri/fiscal_year/maintainability)
|
4
4
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/39fdb48501c5f53235a9/test_coverage)](https://codeclimate.com/github/TsubasaKawajiri/fiscal_year/test_coverage)
|
5
5
|
|
data/lib/fiscal_year/half.rb
CHANGED
@@ -32,7 +32,7 @@ module FiscalYear
|
|
32
32
|
end_month = first.last
|
33
33
|
raise StandardError if end_month.nil?
|
34
34
|
|
35
|
-
end_year =
|
35
|
+
end_year = FiscalYear.increase_year_by_month(year, end_month)
|
36
36
|
|
37
37
|
Date.parse("#{year}/#{first.first}/01")..Date.parse("#{end_year}/#{end_month}/01").end_of_month
|
38
38
|
end
|
@@ -45,8 +45,8 @@ module FiscalYear
|
|
45
45
|
end_month = second.last
|
46
46
|
raise StandardError if first_month.nil? || end_month.nil?
|
47
47
|
|
48
|
-
start_year =
|
49
|
-
end_year =
|
48
|
+
start_year = FiscalYear.increase_year_by_month(year, first_month)
|
49
|
+
end_year = FiscalYear.increase_year_by_month(year, end_month)
|
50
50
|
|
51
51
|
Date.parse("#{start_year}/#{first_month}/01")..Date.parse("#{end_year}/#{end_month}/01").end_of_month
|
52
52
|
end
|
@@ -55,19 +55,11 @@ module FiscalYear
|
|
55
55
|
month = date.month
|
56
56
|
year = date.year
|
57
57
|
# if passed crossed year value, normalize to not crossed year value
|
58
|
-
year
|
58
|
+
year = FiscalYear.decrease_year_by_month(year, month)
|
59
59
|
|
60
60
|
first?(month) ? first_range_by(year) : second_range_by(year)
|
61
61
|
end
|
62
62
|
|
63
|
-
def normalize_year_by_month(year, month)
|
64
|
-
if FiscalYear.cross_year_month?(month)
|
65
|
-
year + 1
|
66
|
-
else
|
67
|
-
year
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
63
|
def cross_year_in_half?(half)
|
72
64
|
FiscalYear.cross_year? && half.any? { |month| month == 12 }
|
73
65
|
end
|
data/lib/fiscal_year/quarter.rb
CHANGED
@@ -34,13 +34,13 @@ module FiscalYear
|
|
34
34
|
|
35
35
|
def range_by(date)
|
36
36
|
year = date.year
|
37
|
-
|
38
|
-
last_year = cross_year_in_quarter?(
|
37
|
+
this_quarter = months(date.month)
|
38
|
+
last_year = cross_year_in_quarter?(this_quarter) ? year + 1 : year
|
39
39
|
|
40
|
-
Date.parse("#{year}/#{
|
40
|
+
Date.parse("#{year}/#{this_quarter.first}/01")..Date.parse("#{last_year}/#{this_quarter.last}/01").end_of_month
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def quarter_num(month)
|
44
44
|
rindex = FiscalYear.quarters.rindex(months(month))
|
45
45
|
|
46
46
|
rindex.nil? ? 0 : (rindex + 1)
|
data/lib/fiscal_year/version.rb
CHANGED
@@ -34,7 +34,7 @@ module FiscalYear
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# TODO: fit to Abc size
|
37
|
-
def half_range_by(date) # rubocop:disable Metrics/AbcSize
|
37
|
+
def half_range_by(date) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
38
38
|
year = date.year
|
39
39
|
month = date.month
|
40
40
|
|
@@ -45,7 +45,14 @@ module FiscalYear
|
|
45
45
|
end
|
46
46
|
|
47
47
|
Date.parse(
|
48
|
-
"#{
|
48
|
+
"#{
|
49
|
+
if FiscalYear::Half.cross_year_in_half?(Half.second) &&
|
50
|
+
FiscalYear.cross_year_month?(month)
|
51
|
+
year - 1
|
52
|
+
else
|
53
|
+
year
|
54
|
+
end
|
55
|
+
}/#{Half.second.first}"
|
49
56
|
)..date.end_of_month.to_date
|
50
57
|
end
|
51
58
|
|
data/lib/fiscal_year.rb
CHANGED
@@ -52,5 +52,21 @@ module FiscalYear
|
|
52
52
|
# @type self: singleton(FiscalYear)
|
53
53
|
months.in_groups(4)
|
54
54
|
end
|
55
|
+
|
56
|
+
def increase_year_by_month(year, month)
|
57
|
+
if FiscalYear.cross_year_month?(month)
|
58
|
+
year + 1
|
59
|
+
else
|
60
|
+
year
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def decrease_year_by_month(year, month)
|
65
|
+
if FiscalYear.cross_year_month?(month)
|
66
|
+
year - 1
|
67
|
+
else
|
68
|
+
year
|
69
|
+
end
|
70
|
+
end
|
55
71
|
end
|
56
72
|
end
|
data/sig/fiscal_year/half.rbs
CHANGED
@@ -7,7 +7,6 @@ module FiscalYear
|
|
7
7
|
def self.first_range_by: (Integer) -> Range[Date]
|
8
8
|
def self.second_range_by: (Integer) -> Range[Date]
|
9
9
|
def self.range_by: (Date) -> Range[Date]
|
10
|
-
def self.normalize_year_by_month: (Integer, Integer) -> Integer
|
11
10
|
def self.cross_year_in_half?: (Array[Integer]) -> bool
|
12
11
|
end
|
13
|
-
end
|
12
|
+
end
|
data/sig/fiscal_year.rbs
CHANGED
@@ -10,4 +10,6 @@ module FiscalYear
|
|
10
10
|
def self.cross_year_months: () -> Array[Integer]
|
11
11
|
def self.halfs: () -> [Array[Integer], Array[Integer]]
|
12
12
|
def self.quarters: () -> [Array[Integer], Array[Integer], Array[Integer], Array[Integer]]
|
13
|
+
def self.increase_year_by_month: (Integer, Integer) -> Integer
|
14
|
+
def self.decrease_year_by_month: (Integer, Integer) -> Integer
|
13
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiscal_year
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsubasa Kawajiri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|