fiscal_year 0.2.0 → 0.3.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 +4 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +6 -5
- data/README.md +7 -3
- data/Steepfile +6 -0
- data/lib/fiscal_year/half.rb +20 -7
- data/lib/fiscal_year/quarter.rb +7 -2
- data/lib/fiscal_year/version.rb +1 -1
- data/lib/fiscal_year/year_to_date.rb +6 -2
- data/lib/fiscal_year.rb +9 -2
- data/rbs_collection.lock.yaml +89 -0
- data/rbs_collection.yaml +15 -0
- data/sig/fiscal_year/config.rbs +5 -0
- data/sig/fiscal_year/half.rbs +13 -0
- data/sig/fiscal_year/quarter.rbs +16 -0
- data/sig/fiscal_year/year_to_date.rbs +8 -0
- data/sig/fiscal_year.rbs +10 -1
- metadata +10 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cf15774708a32e8499e3228288a15749adf62d98a7dc72ccc31e9cfc0b5b842
|
4
|
+
data.tar.gz: 44dc1c5dc58d257bee352257abae21f5e02412d39d5aef76910ef34036a596bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e38a3d7c476be3d0e2889f608e73b52f04234553f2119fa665dc19143fb0fafadd6ef832dc4c42527096e7a402136992a4e2a4e5222109364522c32fca1de1a
|
7
|
+
data.tar.gz: 591f594009aa1cfb7595a3c18720c8d7f88974a7510252f870f981d5518ef296ebdd2fb8b5eb8397bc040c263fc33d4ae0acd09cc76993c4f52731eac15dce36
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -5,8 +5,9 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in fiscal_year.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
gem "rspec"
|
11
|
-
|
12
|
-
gem "
|
8
|
+
group :development do
|
9
|
+
gem "rake"
|
10
|
+
gem "rspec"
|
11
|
+
gem "rubocop"
|
12
|
+
gem "simplecov"
|
13
|
+
end
|
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-

|
2
|
+
[](https://badge.fury.io/rb/fiscal_year)
|
2
3
|
[](https://codeclimate.com/github/TsubasaKawajiri/fiscal_year/maintainability)
|
3
4
|
[](https://codeclimate.com/github/TsubasaKawajiri/fiscal_year/test_coverage)
|
4
5
|
|
5
6
|
# FiscalYear
|
6
7
|
|
7
|
-
|
8
|
+
FiscalYear is calculates half-year, quarter-year, and YTD figures.
|
9
|
+
It can take in a year's numerical value or a year and month and return the results as a Range.
|
10
|
+
|
11
|
+
Additionally, it allows for the customization of the starting month of the fiscal period.
|
8
12
|
|
9
13
|
## Installation
|
10
14
|
|
@@ -54,7 +58,7 @@ configure start month
|
|
54
58
|
|
55
59
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
60
|
|
57
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
58
62
|
|
59
63
|
## Contributing
|
60
64
|
|
data/Steepfile
ADDED
data/lib/fiscal_year/half.rb
CHANGED
@@ -4,11 +4,17 @@ module FiscalYear
|
|
4
4
|
class Half
|
5
5
|
class << self
|
6
6
|
def first
|
7
|
-
FiscalYear.halfs.first
|
7
|
+
first = FiscalYear.halfs.first
|
8
|
+
return first if first.is_a? Array
|
9
|
+
|
10
|
+
[]
|
8
11
|
end
|
9
12
|
|
10
13
|
def second
|
11
|
-
FiscalYear.halfs.second
|
14
|
+
second = FiscalYear.halfs.second
|
15
|
+
return second if second.is_a? Array
|
16
|
+
|
17
|
+
[]
|
12
18
|
end
|
13
19
|
|
14
20
|
def first?(month)
|
@@ -23,19 +29,26 @@ module FiscalYear
|
|
23
29
|
# care Date#parse 2 digit year auto complete.
|
24
30
|
# 99 + 1 = 100, but expect 2000 this context.
|
25
31
|
year = 1999 if year == 99
|
26
|
-
|
32
|
+
end_month = first.last
|
33
|
+
raise StandardError if end_month.nil?
|
27
34
|
|
28
|
-
|
35
|
+
end_year = normalize_year_by_month(year, end_month)
|
36
|
+
|
37
|
+
Date.parse("#{year}/#{first.first}/01")..Date.parse("#{end_year}/#{end_month}/01").end_of_month
|
29
38
|
end
|
30
39
|
|
31
40
|
def second_range_by(year)
|
32
41
|
# care Date#parse 2 digit year auto complete.
|
33
42
|
# 99 + 1 = 100, but expect 2000 this context.
|
34
43
|
year = 1999 if year == 99
|
35
|
-
|
36
|
-
|
44
|
+
first_month = second.first
|
45
|
+
end_month = second.last
|
46
|
+
raise StandardError if first_month.nil? || end_month.nil?
|
47
|
+
|
48
|
+
start_year = normalize_year_by_month(year, first_month)
|
49
|
+
end_year = normalize_year_by_month(year, end_month)
|
37
50
|
|
38
|
-
Date.parse("#{start_year}/#{
|
51
|
+
Date.parse("#{start_year}/#{first_month}/01")..Date.parse("#{end_year}/#{end_month}/01").end_of_month
|
39
52
|
end
|
40
53
|
|
41
54
|
def range_by(date)
|
data/lib/fiscal_year/quarter.rb
CHANGED
@@ -26,7 +26,10 @@ module FiscalYear
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def months(month)
|
29
|
-
FiscalYear.quarters.find { |a| a.include?(month) }
|
29
|
+
months = FiscalYear.quarters.find { |a| a.include?(month) }
|
30
|
+
raise ::StandardError if months.nil?
|
31
|
+
|
32
|
+
months
|
30
33
|
end
|
31
34
|
|
32
35
|
def range_by(date)
|
@@ -38,7 +41,9 @@ module FiscalYear
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def quater_num(month)
|
41
|
-
|
44
|
+
rindex = FiscalYear.quarters.rindex(months(month))
|
45
|
+
|
46
|
+
rindex.nil? ? 0 : (rindex + 1)
|
42
47
|
end
|
43
48
|
|
44
49
|
def cross_year_in_quarter?(quarter)
|
data/lib/fiscal_year/version.rb
CHANGED
@@ -14,11 +14,15 @@ module FiscalYear
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
# TODO: fit to Abc size
|
18
|
+
def year_month_pairs(date) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
18
19
|
month = date.month
|
20
|
+
month_index = FiscalYear.months.index(month)
|
21
|
+
months = FiscalYear.months[(0..month_index)]
|
22
|
+
raise StandardError if months.nil?
|
19
23
|
|
20
24
|
pair = []
|
21
|
-
[date.year].product(
|
25
|
+
[date.year].product(months).each do |e|
|
22
26
|
pair << if FiscalYear.cross_year_month?(month)
|
23
27
|
(FiscalYear.cross_year_month?(e.second) ? e : [e.first - 1, e.second])
|
24
28
|
else
|
data/lib/fiscal_year.rb
CHANGED
@@ -11,8 +11,8 @@ require "active_support"
|
|
11
11
|
require "active_support/core_ext"
|
12
12
|
|
13
13
|
module FiscalYear
|
14
|
+
# @type ivar @config: FiscalYear::Config
|
14
15
|
@config ||= FiscalYear::Config.new
|
15
|
-
|
16
16
|
class << self
|
17
17
|
attr_reader :config
|
18
18
|
|
@@ -35,14 +35,21 @@ module FiscalYear
|
|
35
35
|
def cross_year_months
|
36
36
|
return [] if @config.start_month == 1
|
37
37
|
|
38
|
-
months.
|
38
|
+
rindex = months.rindex(1).to_i
|
39
|
+
|
40
|
+
m = months.slice(rindex, months.length)
|
41
|
+
raise StandardError if m.nil?
|
42
|
+
|
43
|
+
m
|
39
44
|
end
|
40
45
|
|
41
46
|
def halfs
|
47
|
+
# @type self: singleton(FiscalYear)
|
42
48
|
months.in_groups(2)
|
43
49
|
end
|
44
50
|
|
45
51
|
def quarters
|
52
|
+
# @type self: singleton(FiscalYear)
|
46
53
|
months.in_groups(4)
|
47
54
|
end
|
48
55
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
---
|
2
|
+
sources:
|
3
|
+
- name: ruby/gem_rbs_collection
|
4
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
5
|
+
revision: main
|
6
|
+
repo_dir: gems
|
7
|
+
path: ".gem_rbs_collection"
|
8
|
+
gems:
|
9
|
+
- name: activesupport
|
10
|
+
version: '7.0'
|
11
|
+
source:
|
12
|
+
type: git
|
13
|
+
name: ruby/gem_rbs_collection
|
14
|
+
revision: 641dae8a456dc964cf7e447b7d994c709c7e5f96
|
15
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
16
|
+
repo_dir: gems
|
17
|
+
- name: ast
|
18
|
+
version: '2.4'
|
19
|
+
source:
|
20
|
+
type: git
|
21
|
+
name: ruby/gem_rbs_collection
|
22
|
+
revision: 641dae8a456dc964cf7e447b7d994c709c7e5f96
|
23
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
24
|
+
repo_dir: gems
|
25
|
+
- name: concurrent-ruby
|
26
|
+
version: '1.1'
|
27
|
+
source:
|
28
|
+
type: git
|
29
|
+
name: ruby/gem_rbs_collection
|
30
|
+
revision: 641dae8a456dc964cf7e447b7d994c709c7e5f96
|
31
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
32
|
+
repo_dir: gems
|
33
|
+
- name: i18n
|
34
|
+
version: '1.10'
|
35
|
+
source:
|
36
|
+
type: git
|
37
|
+
name: ruby/gem_rbs_collection
|
38
|
+
revision: 641dae8a456dc964cf7e447b7d994c709c7e5f96
|
39
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
40
|
+
repo_dir: gems
|
41
|
+
- name: json
|
42
|
+
version: '0'
|
43
|
+
source:
|
44
|
+
type: stdlib
|
45
|
+
- name: minitest
|
46
|
+
version: '0'
|
47
|
+
source:
|
48
|
+
type: stdlib
|
49
|
+
- name: parallel
|
50
|
+
version: '1.20'
|
51
|
+
source:
|
52
|
+
type: git
|
53
|
+
name: ruby/gem_rbs_collection
|
54
|
+
revision: 641dae8a456dc964cf7e447b7d994c709c7e5f96
|
55
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
56
|
+
repo_dir: gems
|
57
|
+
- name: rainbow
|
58
|
+
version: '3.0'
|
59
|
+
source:
|
60
|
+
type: git
|
61
|
+
name: ruby/gem_rbs_collection
|
62
|
+
revision: 641dae8a456dc964cf7e447b7d994c709c7e5f96
|
63
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
64
|
+
repo_dir: gems
|
65
|
+
- name: date
|
66
|
+
version: '0'
|
67
|
+
source:
|
68
|
+
type: stdlib
|
69
|
+
- name: logger
|
70
|
+
version: '0'
|
71
|
+
source:
|
72
|
+
type: stdlib
|
73
|
+
- name: monitor
|
74
|
+
version: '0'
|
75
|
+
source:
|
76
|
+
type: stdlib
|
77
|
+
- name: mutex_m
|
78
|
+
version: '0'
|
79
|
+
source:
|
80
|
+
type: stdlib
|
81
|
+
- name: singleton
|
82
|
+
version: '0'
|
83
|
+
source:
|
84
|
+
type: stdlib
|
85
|
+
- name: time
|
86
|
+
version: '0'
|
87
|
+
source:
|
88
|
+
type: stdlib
|
89
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- name: ruby/gem_rbs_collection
|
4
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
5
|
+
revision: main
|
6
|
+
repo_dir: gems
|
7
|
+
|
8
|
+
# A directory to install the downloaded RBSs
|
9
|
+
path: .gem_rbs_collection
|
10
|
+
|
11
|
+
gems:
|
12
|
+
# Skip loading rbs gem's RBS.
|
13
|
+
# It's unnecessary if you don't use rbs as a library.
|
14
|
+
- name: rbs
|
15
|
+
ignore: true
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FiscalYear
|
2
|
+
class Half
|
3
|
+
def self.first: () -> Array[Integer] | -> Array[untyped]
|
4
|
+
def self.second: () -> Array[Integer] | -> Array[untyped]
|
5
|
+
def self.first?: (Integer) -> bool
|
6
|
+
def self.second?: (Integer) -> bool
|
7
|
+
def self.first_range_by: (Integer) -> Range[Date]
|
8
|
+
def self.second_range_by: (Integer) -> Range[Date]
|
9
|
+
def self.range_by: (Date) -> Range[Date]
|
10
|
+
def self.normalize_year_by_month: (Integer, Integer) -> Integer
|
11
|
+
def self.cross_year_in_half?: (Array[Integer]) -> bool
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module FiscalYear
|
2
|
+
class Quarter
|
3
|
+
def self.first: () -> Array[Integer]
|
4
|
+
def self.second: () -> Array[Integer]
|
5
|
+
def self.third: () -> Array[Integer]
|
6
|
+
def self.fourth: () -> Array[Integer]
|
7
|
+
def self.first?: (Integer) -> bool
|
8
|
+
def self.second?: (Integer) -> bool
|
9
|
+
def self.third?: (Integer) -> bool
|
10
|
+
def self.fourth?: (Integer) -> bool
|
11
|
+
def self.months: (Integer) -> Array[Integer]
|
12
|
+
def self.range_by: (Date) -> Range[Date]
|
13
|
+
def self.quarter_num: (Integer) -> Integer
|
14
|
+
def self. cross_year_in_quarter?: (Array[Integer]) -> bool
|
15
|
+
end
|
16
|
+
end
|
data/sig/fiscal_year.rbs
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
module FiscalYear
|
2
2
|
VERSION: String
|
3
|
-
|
3
|
+
@config: FiscalYear::Config
|
4
|
+
|
5
|
+
attr_reader self.config: FiscalYear::Config
|
6
|
+
def self.configure: () { (FiscalYear::Config) -> void } -> void | -> void
|
7
|
+
def self.cross_year_month?: (Integer) -> bool
|
8
|
+
def self.cross_year?: () -> bool
|
9
|
+
def self.months: -> Array[Integer]
|
10
|
+
def self.cross_year_months: () -> Array[Integer]
|
11
|
+
def self.halfs: () -> [Array[Integer], Array[Integer]]
|
12
|
+
def self.quarters: () -> [Array[Integer], Array[Integer], Array[Integer], Array[Integer]]
|
4
13
|
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.3.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-
|
11
|
+
date: 2023-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,34 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
27
|
description: fiscal year, quarter, year to date calculate
|
56
28
|
email:
|
57
29
|
- tk.music.jpn@gmail.com
|
@@ -67,13 +39,20 @@ files:
|
|
67
39
|
- LICENSE.txt
|
68
40
|
- README.md
|
69
41
|
- Rakefile
|
42
|
+
- Steepfile
|
70
43
|
- lib/fiscal_year.rb
|
71
44
|
- lib/fiscal_year/config.rb
|
72
45
|
- lib/fiscal_year/half.rb
|
73
46
|
- lib/fiscal_year/quarter.rb
|
74
47
|
- lib/fiscal_year/version.rb
|
75
48
|
- lib/fiscal_year/year_to_date.rb
|
49
|
+
- rbs_collection.lock.yaml
|
50
|
+
- rbs_collection.yaml
|
76
51
|
- sig/fiscal_year.rbs
|
52
|
+
- sig/fiscal_year/config.rbs
|
53
|
+
- sig/fiscal_year/half.rbs
|
54
|
+
- sig/fiscal_year/quarter.rbs
|
55
|
+
- sig/fiscal_year/year_to_date.rbs
|
77
56
|
homepage: https://github.com/TsubasaKawajiri/fiscal_year
|
78
57
|
licenses:
|
79
58
|
- MIT
|
@@ -82,6 +61,7 @@ metadata:
|
|
82
61
|
homepage_uri: https://github.com/TsubasaKawajiri/fiscal_year
|
83
62
|
source_code_uri: https://github.com/TsubasaKawajiri/fiscal_year
|
84
63
|
changelog_uri: https://github.com/TsubasaKawajiri/fiscal_year/CHANGEROG.md
|
64
|
+
rubygems_mfa_required: 'true'
|
85
65
|
post_install_message:
|
86
66
|
rdoc_options: []
|
87
67
|
require_paths:
|