duffy 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/duffy/date.rb +14 -1
- data/lib/duffy/version.rb +2 -1
- data/spec/date_spec.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19def3df1322596d60ac2001478437990ca3bc36
|
4
|
+
data.tar.gz: ec6c3281a8b0e5f3c1c03fe5369184acc64944c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34cae9c0336a238ea8ee3725b178be58fa4429a0f1d7e67281872a6e269fd4ab86cd423fb553899bc4ada59f9a86ef9ceec461bf0ee20a68c974e7c84d025233
|
7
|
+
data.tar.gz: 04d8d1711b3ed59fd4ac3b8d9517c909fba3859ec11fa5a33c4f587a13e4bea35166c8f99402b382648483aed4faffe0fb45062f0da7a62548867e926f9a9926
|
data/README.md
CHANGED
@@ -40,10 +40,13 @@ smart_titlecase | "this and that" | "This and That" (Note: Has config options.
|
|
40
40
|
|
41
41
|
|
42
42
|
## Date Patches:
|
43
|
+
* See config to set your organization's fiscal year start.
|
43
44
|
|
44
|
-
Method
|
45
|
-
|
46
|
-
fiscal_year
|
45
|
+
Method | Example | Output
|
46
|
+
-------------------------|-------------------------------------|-------
|
47
|
+
fiscal_year | Date.today.fiscal_year | 2018
|
48
|
+
beginning_of_fiscal_year | Date.today.beginning_of_fiscal_year | 2017-07-01
|
49
|
+
end_of_fiscal_year | Date.today.end_of_fiscal_year | 2018-06-30
|
47
50
|
|
48
51
|
|
49
52
|
## NilClass Patches:
|
data/lib/duffy/date.rb
CHANGED
@@ -7,10 +7,23 @@ class Date
|
|
7
7
|
(self < Date.new(year, Duffy.configuration.fiscal_month, Duffy.configuration.fiscal_day)) ? year : year + 1
|
8
8
|
end
|
9
9
|
|
10
|
+
# Like beginning_of_year, but for Fiscal Years.
|
11
|
+
# Date.new(2015,10,1).beginning_of_fiscal_year => 2015-07-01
|
12
|
+
def beginning_of_fiscal_year
|
13
|
+
Date.new(fiscal_year - 1, Duffy.configuration.fiscal_month, Duffy.configuration.fiscal_day)
|
14
|
+
end
|
15
|
+
alias_method :at_beginning_of_fiscal_year, :beginning_of_fiscal_year
|
16
|
+
|
17
|
+
# Like end_of_year, but for Fiscal Years
|
18
|
+
# Date.new(2015,10,1).end_of_fiscal_year => 2016-06-30
|
19
|
+
def end_of_fiscal_year
|
20
|
+
Date.new(fiscal_year, Duffy.configuration.fiscal_month, Duffy.configuration.fiscal_day).prev_day
|
21
|
+
end
|
22
|
+
alias_method :at_end_of_fiscal_year, :end_of_fiscal_year
|
10
23
|
end
|
11
24
|
|
12
25
|
class NilClass
|
13
26
|
def to_date
|
14
27
|
self
|
15
28
|
end
|
16
|
-
end
|
29
|
+
end
|
data/lib/duffy/version.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Duffy
|
2
|
-
VERSION = "0.3.
|
2
|
+
VERSION = "0.3.3"
|
3
3
|
end
|
4
4
|
|
5
5
|
# History
|
6
|
+
# 0.3.3 - Added beginning_of_fiscal_year and end_of_fiscal_year methods to Date
|
6
7
|
# 0.3.2 - Added mem_percentage as a convenience and safeguard against div/0 in user code.
|
7
8
|
# 0.3.1 - Fixed mem_available for old linux distros.
|
8
9
|
# 0.3.0 - Added system memory methods. Removed deprecated icon methods.
|
data/spec/date_spec.rb
CHANGED
@@ -21,5 +21,37 @@ describe Date do
|
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
+
describe "beginning_of_fiscal_year (Assuming July 1st Start)" do
|
25
|
+
|
26
|
+
# First day stays the same
|
27
|
+
it "2000-07-01 => 2000-07-01" do
|
28
|
+
expect(Date.new(2000, 7, 1).beginning_of_fiscal_year).to eq Date.new(2000, 7, 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Previous day is the previous FY
|
32
|
+
it "2000-06-30 => 1999-07-01" do
|
33
|
+
expect(Date.new(2000, 6, 30).beginning_of_fiscal_year).to eq Date.new(1999, 7, 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Date into the next calendar year but before the FY change.
|
37
|
+
it "2001-01-01 => 2000-07-01" do
|
38
|
+
expect(Date.new(2001, 1, 1).beginning_of_fiscal_year).to eq Date.new(2000, 7, 1)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "end_of_fiscal_year (Assuming July 1st Start)" do
|
44
|
+
|
45
|
+
# Last day stays the same
|
46
|
+
it "2000-06-30 => 2000-06-30" do
|
47
|
+
expect(Date.new(2000, 6, 30).end_of_fiscal_year).to eq Date.new(2000, 6, 30)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Day after the last day is the next FY end
|
51
|
+
it "2000-07-01 => 2001-06-30" do
|
52
|
+
expect(Date.new(2000, 7, 1).end_of_fiscal_year).to eq Date.new(2001, 6, 30)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
24
56
|
|
25
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duffy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Duffy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|