asanghi-fiscali 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/fiscali.gemspec +49 -0
- data/init.rb +3 -0
- data/install.rb +1 -0
- data/lib/fiscali.rb +0 -0
- data/lib/rising_sun/fiscali.rb +124 -0
- data/test/fiscali_test.rb +58 -0
- data/test/test_helper.rb +3 -0
- metadata +67 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 asanghi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "fiscali"
|
8
|
+
gem.summary = %Q{Fiscal Year Date Functions}
|
9
|
+
gem.email = "aditya.sanghi@risingsunbilling.com"
|
10
|
+
gem.homepage = "http://github.com/asanghi/fiscali"
|
11
|
+
gem.authors = ["asanghi"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "fiscali #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.0
|
data/fiscali.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{fiscali}
|
5
|
+
s.version = "1.1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["asanghi"]
|
9
|
+
s.date = %q{2009-07-24}
|
10
|
+
s.email = %q{aditya.sanghi@risingsunbilling.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"fiscali.gemspec",
|
23
|
+
"init.rb",
|
24
|
+
"install.rb",
|
25
|
+
"lib/fiscali.rb",
|
26
|
+
"lib/rising_sun/fiscali.rb",
|
27
|
+
"test/fiscali_test.rb",
|
28
|
+
"test/test_helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/asanghi/fiscali}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.5}
|
34
|
+
s.summary = %q{Fiscal Year Date Functions}
|
35
|
+
s.test_files = [
|
36
|
+
"test/fiscali_test.rb",
|
37
|
+
"test/test_helper.rb"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/fiscali.rb
ADDED
File without changes
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module RisingSun
|
2
|
+
module Fiscali
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
unless included_modules.include? InstanceMethods
|
6
|
+
base.send(:include, InstanceMethods)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
FISCAL_ZONE = {:india => 4, :uk => 4, :us => 10, :pakistan => 7,
|
11
|
+
:australia => 7, :ireland => 1, :nz => 7, :japan => 4}
|
12
|
+
FY_START_MONTH = 1
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def fiscal_zone=(zone)
|
16
|
+
write_inheritable_attribute(:start_month, FISCAL_ZONE[zone] || FY_START_MONTH)
|
17
|
+
write_inheritable_attribute(:zone,zone)
|
18
|
+
end
|
19
|
+
|
20
|
+
def fy_start_month
|
21
|
+
read_inheritable_attribute(:start_month)
|
22
|
+
end
|
23
|
+
|
24
|
+
def fiscal_zone
|
25
|
+
read_inheritable_attribute(:zone)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fy_start_month=(month)
|
29
|
+
write_inheritable_attribute(:start_month,month)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module InstanceMethods
|
34
|
+
def financial_year
|
35
|
+
self.month < start_month ? self.year - 1 : self.year
|
36
|
+
end
|
37
|
+
|
38
|
+
def beginning_of_financial_year
|
39
|
+
change(:year => financial_year, :month => start_month, :day => 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
def end_of_financial_year
|
43
|
+
(beginning_of_financial_year + 1.year - 1.month).end_of_month
|
44
|
+
end
|
45
|
+
|
46
|
+
alias :beginning_of_financial_q1 :beginning_of_financial_year
|
47
|
+
def end_of_financial_q1
|
48
|
+
end_of_financial_year - 9.months
|
49
|
+
end
|
50
|
+
|
51
|
+
def beginning_of_financial_q2
|
52
|
+
beginning_of_financial_year + 3.months
|
53
|
+
end
|
54
|
+
|
55
|
+
def end_of_financial_q2
|
56
|
+
end_of_financial_year - 6.months
|
57
|
+
end
|
58
|
+
|
59
|
+
def beginning_of_financial_q3
|
60
|
+
beginning_of_financial_year + 6.months
|
61
|
+
end
|
62
|
+
|
63
|
+
def end_of_financial_q3
|
64
|
+
end_of_financial_year - 3.months
|
65
|
+
end
|
66
|
+
|
67
|
+
def beginning_of_financial_q4
|
68
|
+
beginning_of_financial_year + 9.months
|
69
|
+
end
|
70
|
+
alias :end_of_financial_q4 :end_of_financial_year
|
71
|
+
|
72
|
+
alias :beginning_of_financial_h1 :beginning_of_financial_year
|
73
|
+
alias :end_of_financial_h1 :end_of_financial_q2
|
74
|
+
|
75
|
+
alias :beginning_of_financial_h2 :beginning_of_financial_q3
|
76
|
+
alias :end_of_financial_h2 :end_of_financial_year
|
77
|
+
|
78
|
+
def financial_quarter
|
79
|
+
"Q#{( months_between / 3 ).floor + 1} #{financial_year}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def financial_half
|
83
|
+
"H#{( months_between / 6 ).floor + 1} #{financial_year}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def next_financial_quarter
|
87
|
+
beginning_of_financial_year.months_since(((months_between / 3).floor + 1 ) * 3)
|
88
|
+
end
|
89
|
+
|
90
|
+
def next_financial_half
|
91
|
+
beginning_of_financial_year.months_since(((months_between / 6).floor + 1) * 6)
|
92
|
+
end
|
93
|
+
|
94
|
+
def beginning_of_financial_quarter
|
95
|
+
beginning_of_financial_year.months_since(((months_between / 3).floor) * 3)
|
96
|
+
end
|
97
|
+
|
98
|
+
def beginning_of_financial_half
|
99
|
+
beginning_of_financial_year.months_since(((months_between / 6).floor) * 6)
|
100
|
+
end
|
101
|
+
|
102
|
+
def previous_financial_quarter
|
103
|
+
beginning_of_financial_quarter.months_ago(3)
|
104
|
+
end
|
105
|
+
|
106
|
+
def previous_financial_half
|
107
|
+
beginning_of_financial_half.months_ago(6)
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def months_between
|
113
|
+
soy = self.beginning_of_financial_year
|
114
|
+
(self.month - soy.month) + 12 * (self.year - soy.year)
|
115
|
+
end
|
116
|
+
|
117
|
+
def start_month
|
118
|
+
self.class.read_inheritable_attribute(:start_month) || FY_START_MONTH
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FiscaliTest < ActiveSupport::TestCase
|
4
|
+
test "date test" do
|
5
|
+
Date.fiscal_zone = :india
|
6
|
+
assert_equal(Date.fiscal_zone,:india)
|
7
|
+
assert_equal(Date.fy_start_month,4)
|
8
|
+
Date.fy_start_month = 2
|
9
|
+
assert_equal(Date.fy_start_month,2)
|
10
|
+
|
11
|
+
Date.fiscal_zone = :india
|
12
|
+
d = Date.new(2009,1,1)
|
13
|
+
assert_equal(d.financial_year,2008,'Financial Year is not correct')
|
14
|
+
assert_equal(d.beginning_of_financial_year,Date.new(2008,4,1),'Beginning of FY is not correct')
|
15
|
+
assert_equal(d.beginning_of_financial_h1,Date.new(2008,4,1),'Beginning of h1 is not correct')
|
16
|
+
assert_equal(d.beginning_of_financial_h2,Date.new(2008,10,1),'Beginning of h2 is not correct')
|
17
|
+
assert_equal(d.beginning_of_financial_q1,Date.new(2008,4,1),'Beginning of q1 is not correct')
|
18
|
+
assert_equal(d.beginning_of_financial_q2,Date.new(2008,7,1),'Beginning of q2 is not correct')
|
19
|
+
assert_equal(d.beginning_of_financial_q3,Date.new(2008,10,1),'Beginning of q3 is not correct')
|
20
|
+
assert_equal(d.beginning_of_financial_q4,Date.new(2009,1,1),'Beginning of q4 is not correct')
|
21
|
+
|
22
|
+
assert_equal(d.end_of_financial_year,Date.new(2009,3,31),'End of FY is not correct')
|
23
|
+
assert_equal(d.end_of_financial_h1,Date.new(2008,9,30),'End of h1 is not correct')
|
24
|
+
assert_equal(d.end_of_financial_h2,Date.new(2009,3,31),'End of h2 is not correct')
|
25
|
+
assert_equal(d.end_of_financial_q1,Date.new(2008,6,30),'End of q1 is not correct')
|
26
|
+
assert_equal(d.end_of_financial_q2,Date.new(2008,9,30),'End of q2 is not correct')
|
27
|
+
assert_equal(d.end_of_financial_q3,Date.new(2008,12,31),'End of q3 is not correct')
|
28
|
+
assert_equal(d.end_of_financial_q4,Date.new(2009,3,31),'End of q4 is not correct')
|
29
|
+
|
30
|
+
assert_equal(d.financial_quarter,'Q4 2008','Financial Quarter is not correct')
|
31
|
+
assert_equal(Date.new(2008,4,1).financial_quarter,'Q1 2008','Financial Quarter is not correct')
|
32
|
+
assert_equal(d.financial_half,'H2 2008','Financial Half is not correct')
|
33
|
+
assert_equal(Date.new(2009,11,30).financial_half,'H2 2009','Financial Half is not correct')
|
34
|
+
|
35
|
+
assert_equal(d.next_financial_half,Date.new(2009,4,1),'Next Financial Half is not correct')
|
36
|
+
assert_equal(d.next_financial_quarter,Date.new(2009,4,1),'Next Financial Quarter is not correct')
|
37
|
+
assert_equal(Date.new(2009,6,1).next_financial_half,Date.new(2009,10,1), 'Next Financial Half is not correct')
|
38
|
+
assert_equal(Date.new(2009,10,30).next_financial_quarter,Date.new(2010,1,1),'Next Financial Quarter is not correct')
|
39
|
+
|
40
|
+
assert_equal(d.beginning_of_financial_half,
|
41
|
+
Date.new(2008,10,1),'Beginning of Financial Half is not correct')
|
42
|
+
assert_equal(d.beginning_of_financial_quarter,
|
43
|
+
Date.new(2009,1,1),'Beginning of Financial Quarter is not correct')
|
44
|
+
assert_equal(Date.new(2009,6,1).beginning_of_financial_half,
|
45
|
+
Date.new(2009,4,1), 'Beginning of Financial Half is not correct')
|
46
|
+
assert_equal(Date.new(2009,10,30).beginning_of_financial_quarter,
|
47
|
+
Date.new(2009,10,1),'Beginning of Financial Quarter is not correct')
|
48
|
+
|
49
|
+
assert_equal(d.previous_financial_half,
|
50
|
+
Date.new(2008,4,1),'Previous Financial Half is not correct')
|
51
|
+
assert_equal(d.previous_financial_quarter,
|
52
|
+
Date.new(2008,10,1),'Previous Financial Quarter is not correct')
|
53
|
+
assert_equal(Date.new(2009,6,1).previous_financial_half,
|
54
|
+
Date.new(2008,10,1), 'Previous Financial Half is not correct')
|
55
|
+
assert_equal(Date.new(2009,10,30).previous_financial_quarter,
|
56
|
+
Date.new(2009,7,1),'Previous Financial Quarter is not correct')
|
57
|
+
end
|
58
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: asanghi-fiscali
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- asanghi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: aditya.sanghi@risingsunbilling.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- fiscali.gemspec
|
33
|
+
- init.rb
|
34
|
+
- install.rb
|
35
|
+
- lib/fiscali.rb
|
36
|
+
- lib/rising_sun/fiscali.rb
|
37
|
+
- test/fiscali_test.rb
|
38
|
+
- test/test_helper.rb
|
39
|
+
has_rdoc: false
|
40
|
+
homepage: http://github.com/asanghi/fiscali
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options:
|
43
|
+
- --charset=UTF-8
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.2.0
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Fiscal Year Date Functions
|
65
|
+
test_files:
|
66
|
+
- test/fiscali_test.rb
|
67
|
+
- test/test_helper.rb
|