fiscal_year 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +11 -0
- data/lib/fiscal_year/half.rb +4 -12
- data/lib/fiscal_year/version.rb +1 -1
- data/lib/fiscal_year/year_to_date.rb +6 -9
- data/lib/fiscal_year.rb +24 -0
- data/sig/fiscal_year/config.rbs +1 -0
- data/sig/fiscal_year/half.rbs +1 -2
- data/sig/fiscal_year.rbs +3 -0
- 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: '0917960fc403b45d283863bad77ac8e35fc8b5a3c216a13f1ca2cdb68c95410a'
|
4
|
+
data.tar.gz: 68506d80a59973356f41d5bd1c55af3164542378ec8d9bea7d31be14bd90e302
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74e0c8c7ddff795d9c64754dde60b462073f45afd04892dcad3e1595970d1bc2a7ac4ebf3bc464ccc112f10bfe33393023bf008cf08b349c27839994a00c4199
|
7
|
+
data.tar.gz: 50c1f1e00478c28ee72bc301ab8ab5fe42c1d142e822cc2d8747ff25f631ff62aff2e3e457e8bb852cde09676b38c0826057f8dedd503e5ad8ad2c3ad37a7e90
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## [0.6.0] - 2024-05-15
|
2
|
+
- [BREAK] Ruby 3.0.x, 2.7.x and 2.6.x has no longer support.
|
3
|
+
- add `FiscalYear.range_by` method
|
4
|
+
|
5
|
+
## [0.5.0] - 2024-03-18
|
6
|
+
- [BREAK] rename and move `FiscalYear::Half.normalize_year_by_month` to `FiscalYear.increase_year_by_month`
|
7
|
+
- add `FiscalYear.decrease_year_by_month` method
|
8
|
+
|
9
|
+
when year normalize, we may want to increase year or decrease year depending on the situation.
|
10
|
+
therefore, rename and add decrease method.
|
11
|
+
|
1
12
|
## [0.4.0] - 2023-06-15
|
2
13
|
- fix calculate logic of half year to date
|
3
14
|
|
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/version.rb
CHANGED
@@ -21,16 +21,13 @@ module FiscalYear
|
|
21
21
|
months = FiscalYear.months[(0..month_index)]
|
22
22
|
raise StandardError if months.nil?
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
24
|
+
[date.year].product(months).map do |e|
|
25
|
+
if FiscalYear.cross_year_month?(month)
|
26
|
+
(FiscalYear.cross_year_month?(e.second) ? e : [e.first - 1, e.second])
|
27
|
+
else
|
28
|
+
e
|
29
|
+
end
|
31
30
|
end
|
32
|
-
|
33
|
-
pair
|
34
31
|
end
|
35
32
|
|
36
33
|
# TODO: fit to Abc size
|
data/lib/fiscal_year.rb
CHANGED
@@ -52,5 +52,29 @@ 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
|
71
|
+
|
72
|
+
def range_by(date)
|
73
|
+
year = date.year
|
74
|
+
month = date.month
|
75
|
+
normalized_year = decrease_year_by_month(year, month)
|
76
|
+
|
77
|
+
FiscalYear::Half.first_range_by(normalized_year).first..FiscalYear::Half.second_range_by(normalized_year).last
|
78
|
+
end
|
55
79
|
end
|
56
80
|
end
|
data/sig/fiscal_year/config.rbs
CHANGED
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,7 @@ 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
|
15
|
+
def self.range_by: (Date) -> Range
|
13
16
|
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.6.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-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
73
|
+
version: 3.1.0
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|