fiscal_year 0.1.0 → 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/.rubocop.yml +7 -0
- data/CHANGELOG.md +5 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +30 -3
- data/lib/fiscal_year/config.rb +3 -1
- data/lib/fiscal_year/half.rb +26 -5
- data/lib/fiscal_year/quarter.rb +7 -2
- data/lib/fiscal_year/version.rb +1 -1
- data/lib/fiscal_year/year_to_date.rb +22 -10
- data/lib/fiscal_year.rb +16 -15
- 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: 284c5184ce2fd9503b81a6de26e657eacba6b917d8544e88ee37b771f9316b82
|
|
4
|
+
data.tar.gz: 072003b1e2b38f9c8e9e6ec6ce3fe549acd9fc06b9b403065e1605bf73bc0ba2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bae3fd2e63eb14fc7954e40e7e98e4861902b47b1f47a6f8038351373f899767aae0a70133a0d6fae274edefa9872596fa11ce23a81001e055b9b200ddb9245d
|
|
7
|
+
data.tar.gz: c3903b8302eb1f86ff53bc7ef74a2f43822e9a83eb2399491da321ab7c5af9a334bf0abd8fcb39db7fc828d451815d204d6baa6d43515768bcf1b8f222e48645
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
|
@@ -39,7 +39,7 @@ This Code of Conduct applies within all community spaces, and also applies when
|
|
|
39
39
|
|
|
40
40
|
## Enforcement
|
|
41
41
|
|
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at
|
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tk.music.jpn@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
|
43
43
|
|
|
44
44
|
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
|
45
45
|
|
data/README.md
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+

|
|
2
|
+
[](https://codeclimate.com/github/TsubasaKawajiri/fiscal_year/maintainability)
|
|
3
|
+
[](https://codeclimate.com/github/TsubasaKawajiri/fiscal_year/test_coverage)
|
|
4
|
+
|
|
1
5
|
# FiscalYear
|
|
2
6
|
|
|
7
|
+
Calculate fiscal year half, quarter, and year to date.
|
|
3
8
|
|
|
4
9
|
## Installation
|
|
5
10
|
|
|
6
|
-
|
|
11
|
+
```
|
|
12
|
+
gem 'fiscal_year'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
then,
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
bundle install
|
|
19
|
+
```
|
|
7
20
|
|
|
8
21
|
## Usage
|
|
9
22
|
|
|
@@ -12,6 +25,20 @@ require 'fiscal_year'
|
|
|
12
25
|
|
|
13
26
|
FiscalYear.quarters
|
|
14
27
|
=> [[4, 5, 6], [7, 8, 9], [10, 11, 12], [1, 2, 3]]
|
|
28
|
+
|
|
29
|
+
date = Date.parse('2023/08/01')
|
|
30
|
+
|
|
31
|
+
# get current Half range
|
|
32
|
+
FiscalYear::Half.range_by(date)
|
|
33
|
+
=> Sat, 01 Apr 2023..Sat, 30 Sep 2023
|
|
34
|
+
|
|
35
|
+
# get current quarter range
|
|
36
|
+
FiscalYear::Quarter.range_by(date)
|
|
37
|
+
=> Sat, 01 Jul 2023..Sat, 30 Sep 2023
|
|
38
|
+
|
|
39
|
+
# get year to date
|
|
40
|
+
FiscalYear::YearToDate.range_by(date)
|
|
41
|
+
=> Sat, 01 Apr 2023..Thu, 31 Aug 2023
|
|
15
42
|
```
|
|
16
43
|
|
|
17
44
|
configure start month
|
|
@@ -31,7 +58,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
31
58
|
|
|
32
59
|
## Contributing
|
|
33
60
|
|
|
34
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/TsubasaKawajiri/fiscal_year. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/TsubasaKawajiri/fiscal_year/blob/master/CODE_OF_CONDUCT.md).
|
|
35
62
|
|
|
36
63
|
## License
|
|
37
64
|
|
|
@@ -39,4 +66,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
39
66
|
|
|
40
67
|
## Code of Conduct
|
|
41
68
|
|
|
42
|
-
Everyone interacting in the FiscalYear project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
|
69
|
+
Everyone interacting in the FiscalYear project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/TsubasaKawajiri/fiscal_year/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/fiscal_year/config.rb
CHANGED
data/lib/fiscal_year/half.rb
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
module FiscalYear
|
|
4
4
|
class Half
|
|
5
5
|
class << self
|
|
6
|
-
|
|
7
6
|
def first
|
|
8
7
|
FiscalYear.halfs.first
|
|
9
8
|
end
|
|
@@ -21,22 +20,44 @@ module FiscalYear
|
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
def first_range_by(year)
|
|
24
|
-
Date
|
|
23
|
+
# care Date#parse 2 digit year auto complete.
|
|
24
|
+
# 99 + 1 = 100, but expect 2000 this context.
|
|
25
|
+
year = 1999 if year == 99
|
|
26
|
+
end_year = normalize_year_by_month(year, first.last)
|
|
27
|
+
|
|
28
|
+
Date.parse("#{year}/#{first.first}/01")..Date.parse("#{end_year}/#{first.last}/01").end_of_month
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
def second_range_by(year)
|
|
28
|
-
Date
|
|
32
|
+
# care Date#parse 2 digit year auto complete.
|
|
33
|
+
# 99 + 1 = 100, but expect 2000 this context.
|
|
34
|
+
year = 1999 if year == 99
|
|
35
|
+
start_year = normalize_year_by_month(year, second.first)
|
|
36
|
+
end_year = normalize_year_by_month(year, second.last)
|
|
37
|
+
|
|
38
|
+
Date.parse("#{start_year}/#{second.first}/01")..Date.parse("#{end_year}/#{second.last}/01").end_of_month
|
|
29
39
|
end
|
|
30
40
|
|
|
31
41
|
def range_by(date)
|
|
32
42
|
month = date.month
|
|
33
43
|
year = date.year
|
|
44
|
+
# if passed crossed year value, normalize to not crossed year value
|
|
45
|
+
year -= 1 if FiscalYear.cross_year_month?(month)
|
|
46
|
+
|
|
47
|
+
first?(month) ? first_range_by(year) : second_range_by(year)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def normalize_year_by_month(year, month)
|
|
34
51
|
if FiscalYear.cross_year_month?(month)
|
|
35
|
-
|
|
52
|
+
year + 1
|
|
36
53
|
else
|
|
37
|
-
|
|
54
|
+
year
|
|
38
55
|
end
|
|
39
56
|
end
|
|
57
|
+
|
|
58
|
+
def cross_year_in_half?(half)
|
|
59
|
+
FiscalYear.cross_year? && half.any? { |month| month == 12 }
|
|
60
|
+
end
|
|
40
61
|
end
|
|
41
62
|
end
|
|
42
63
|
end
|
data/lib/fiscal_year/quarter.rb
CHANGED
|
@@ -31,14 +31,19 @@ module FiscalYear
|
|
|
31
31
|
|
|
32
32
|
def range_by(date)
|
|
33
33
|
year = date.year
|
|
34
|
-
|
|
34
|
+
this_quater = months(date.month)
|
|
35
|
+
last_year = cross_year_in_quarter?(this_quater) ? year + 1 : year
|
|
35
36
|
|
|
36
|
-
Date.parse("#{year}/#{
|
|
37
|
+
Date.parse("#{year}/#{this_quater.first}/01")..Date.parse("#{last_year}/#{this_quater.last}/01").end_of_month
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def quater_num(month)
|
|
40
41
|
(FiscalYear.quarters.rindex(months(month)) + 1)
|
|
41
42
|
end
|
|
43
|
+
|
|
44
|
+
def cross_year_in_quarter?(quarter)
|
|
45
|
+
FiscalYear.cross_year? && quarter.any? { |month| month == 12 }
|
|
46
|
+
end
|
|
42
47
|
end
|
|
43
48
|
end
|
|
44
49
|
end
|
data/lib/fiscal_year/version.rb
CHANGED
|
@@ -8,9 +8,9 @@ module FiscalYear
|
|
|
8
8
|
month = date.month
|
|
9
9
|
|
|
10
10
|
if FiscalYear.cross_year_month?(month)
|
|
11
|
-
Date.parse("#{year - 1}/#{FiscalYear.config.start_month}")..date.end_of_month.to_date
|
|
11
|
+
Date.parse("#{year - 1}/#{FiscalYear.config.start_month}/01")..date.end_of_month.to_date
|
|
12
12
|
else
|
|
13
|
-
Date.parse("#{year}/#{FiscalYear.config.start_month}")..date.end_of_month.to_date
|
|
13
|
+
Date.parse("#{year}/#{FiscalYear.config.start_month}/01")..date.end_of_month.to_date
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
@@ -29,24 +29,36 @@ module FiscalYear
|
|
|
29
29
|
pair
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
# TODO: fit to Abc size
|
|
33
|
+
def half_range_by(date) # rubocop:disable Metrics/AbcSize
|
|
33
34
|
year = date.year
|
|
34
35
|
month = date.month
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
if Half.first?(month)
|
|
38
|
+
return (Date.parse("#{FiscalYear.cross_year_month?(month) ? year - 1 : year}/#{Half.first.first}/01")..
|
|
39
|
+
date.end_of_month.to_date
|
|
40
|
+
)
|
|
41
|
+
end
|
|
37
42
|
|
|
38
|
-
Date.parse(
|
|
43
|
+
Date.parse(
|
|
44
|
+
"#{FiscalYear::Half.cross_year_in_half?(Half.second) ? year - 1 : year}/#{Half.second.first}"
|
|
45
|
+
)..date.end_of_month.to_date
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
def quarter_range_by(date)
|
|
42
49
|
year = date.year
|
|
43
50
|
month = date.month
|
|
44
51
|
|
|
45
|
-
%i[first? second? third? fourth?]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
quarter_method = %i[first? second? third? fourth?]
|
|
53
|
+
.filter { |method_name| FiscalYear::Quarter.public_send(method_name, month) }
|
|
54
|
+
.first.to_s.gsub("?", "").to_sym
|
|
55
|
+
|
|
56
|
+
quarter = Quarter.public_send(quarter_method)
|
|
57
|
+
|
|
58
|
+
(
|
|
59
|
+
Date.parse("#{FiscalYear.cross_year_month?(month) ? year - 1 : year}/#{quarter.first}/01")..
|
|
60
|
+
date.end_of_month.to_date
|
|
61
|
+
)
|
|
50
62
|
end
|
|
51
63
|
end
|
|
52
64
|
end
|
data/lib/fiscal_year.rb
CHANGED
|
@@ -2,38 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "fiscal_year/version"
|
|
4
4
|
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
5
|
+
require "fiscal_year/half"
|
|
6
|
+
require "fiscal_year/quarter"
|
|
7
|
+
require "fiscal_year/year_to_date"
|
|
8
|
+
require "fiscal_year/config"
|
|
9
9
|
|
|
10
|
-
require
|
|
11
|
-
require
|
|
10
|
+
require "active_support"
|
|
11
|
+
require "active_support/core_ext"
|
|
12
12
|
|
|
13
13
|
module FiscalYear
|
|
14
|
-
|
|
14
|
+
@config ||= FiscalYear::Config.new
|
|
15
|
+
|
|
15
16
|
class << self
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def configure(&block)
|
|
21
|
-
yield(@@config) if block_given?
|
|
17
|
+
attr_reader :config
|
|
18
|
+
|
|
19
|
+
def configure
|
|
20
|
+
yield(@config) if block_given?
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
def cross_year_month?(month)
|
|
25
24
|
cross_year_months.include?(month)
|
|
26
25
|
end
|
|
27
|
-
|
|
26
|
+
|
|
28
27
|
def cross_year?
|
|
29
28
|
months.rindex(1) != 0
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
def months
|
|
33
|
-
(1..12).to_a.tap { |arr| arr.concat(arr.shift(
|
|
32
|
+
(1..12).to_a.tap { |arr| arr.concat(arr.shift(@config.start_month - 1)) }
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
def cross_year_months
|
|
36
|
+
return [] if @config.start_month == 1
|
|
37
|
+
|
|
37
38
|
months.slice(months.rindex(1), months.length)
|
|
38
39
|
end
|
|
39
40
|
|
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.2.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: 2023-03-
|
|
11
|
+
date: 2023-03-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|