asanghi / fiscali Goto Github PK
View Code? Open in Web Editor NEWFiscal Year Date Functions
Home Page: http://asanghi.github.com/fiscali
License: MIT License
Fiscal Year Date Functions
Home Page: http://asanghi.github.com/fiscali
License: MIT License
My project sets Date.fiscal_zone in an initializer, but the app is acting like Date.fiscal_zone is still nil. Looking at your code, it looks like this is caused by this being stored in the Thread.current hash - the initializer is being run in a different thread than the application itself, and so modifications to the Thread.current hash in the initializer don't carry over.
Here's an example of what's happening - I triggered the debugger at the end of the initializer and in the controller:
=> Rails 3.1.6 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
/Users/sagroup/.rvm/gems/ruby-1.9.2-p290-patched@drachmas/gems/activesupport-3.1.6/lib/active_support/dependencies.rb:641
aborting = false
(rdb:1) pp Date.fiscal_zone
:us
(rdb:1) pp Thread.current[:fiscali_zone]
:us
(rdb:1) pp Thread.current
# <Thread:0x00000109c3b360 run>
(rdb:1) cont
[2012-07-12 11:36:38] INFO WEBrick 1.3.1
[2012-07-12 11:36:38] INFO ruby 1.9.2 (2011-07-09) [x86_64-darwin11.3.0]
[2012-07-12 11:36:38] INFO WEBrick::HTTPServer#start: pid=41940 port=3000
/Users/sagroup/dev/drachmas3/app/controllers/core_dashboard_controller.rb:22
dt = params[:dt] || Date.today.beginning_of_financial_q1
(rdb:2) pp Date.fiscal_zone
nil
(rdb:2) pp Thread.current[:fiscali_zone]
nil
(rdb:2) pp Thread.current
# <Thread:0x0000012ffcd2a0 run>```
irb(main):005:0> @start_date = Date.new(2013,2,1) => Fri, 01 Feb 2013 irb(main):006:0> @start_date.financial_year #correct => 2013 irb(main):007:0> @start_date.beginning_of_financial_year => Mon, 01 Jul 2013 #correct irb(main):008:0> @second_date = DateTime.new(2013,2,1) => Fri, 01 Feb 2013 00:00:00 +0000 irb(main):009:0> @second_date.financial_year => 2014 #incorrect irb(main):010:0> @second_date.beginning_of_financial_year => Wed, 01 Jan 2014 00:00:00 +0000 #incorrect
Seems to struggle to differentiate between Date and DateTime, maybe?
I found an inconsistency and potential bug in the gem:
>> Date.fiscal_zone
:us
>> Date.uses_forward_year?
true
>> Date.today
Mon, 08 Oct 2018
>> Date.today.financial_year
2019
>> Date.financial_year_start
Mon, 01 Oct 2018
>> Date.financial_year_start(2019)
Tue, 01 Oct 2019
The last statement returns a wrong result. The financial_year_start
of 2019 should be Mon, 01 Oct 2018
not Tue, 01 Oct 2019
.
Hi,
I am still learning Ruby and Rails. I'd like to define my own method on this that does the following.
Assuming I am in financial year 2014 I can call Date.today.financial_periods
and have an array [201501,201502,201503,201504,201505,201506,201507,201508,201509,201510,201511,201512]
returned.
Where would I put this to define it?
I have tried creating a new file under my lib directory called fiscali.rb and adding
module RisingSun
module Fiscali
def financial_periods
year = self.financial_year
financial_periods = []
(1..12).each do |period|
period.format("%02d",4)
financial_periods << period
end
end
end
end
But no luck... ๐
Is CI set up for this project? If not, could I set one up?
I love that you have a configuration for start_month
. However, it would also be nice to have a similar configuration for start_week
, because some companies start their fiscal years in the middle of the month โ for example, the 4th week of a month.
Start week would be an integer ranging from 1โ5. By default it would be 1, since most companies start their fiscal year in the first week of the month.
I quickly spiked-out a working version of this change here: moubry@9121ba2. Tests pass.
Either a) can we get a new gem release or b) Can i get added to release a new version?
Thank you.
fiscali-1.2.5/lib/rising_sun/fiscali.rb:16:in fiscal_zone=': undefined method
write_inheritable_attribute' for Date:Class (NoMethodError)
... simply trying to launch the console on an otherwise empty rails-3.1 or rails-3.2 project
Under Using in your rails project it says:
Date.fiscal_zone = :india
Time.fiscal_zone = :india
or Date.start_month = 4
When setting it manually I had to use:
Date.fy_start_month=4
It may also be worth noting that you have to set it for each class Date, Time, and DateTime, so my initializer looks like:
Date.fy_start_month = 2
Time.fy_start_month = 2
DateTime.fy_start_month = 2
Not really a bug, but a feature request. GREAT gem, by the way. Saved me hours!
Fiscal years are often named future-tense. For example, July 2012 - June 2013 is referred to as FY 2013. Your system returns FY2012 here:
def financial_year self.month < start_month ? self.year - 1 : self.year end
I changed it to:
`def financial_year
self.month < start_month ? self.year : self.year + 1
end``
It might be nice to be able to set that as a default option.
Thanks again for a good, clean gem.
In v2.2.0, with use_forward_year set on Date and Time and fiscal_zone set to :us, Date.today.financial_year returns 2014, which is correct, but now Date.today.beginning_of_financial_year and Date.today.end_of_financial_year return the start/end dates for FY 2015.
jruby-1.7.13 :018 > Date.today.financial_year
=> 2014
jruby-1.7.13 :019 > Date.today.beginning_of_financial_year
=> Wed, 01 Oct 2014
jruby-1.7.13 :020 > Date.today.end_of_financial_year
=> Wed, 30 Sep 2015
jruby-1.7.13 :023 > Date.uses_forward_year?
=> true
Hi,
I'm using your gem in a Sinatra application, and don't have (nor want to install) ActiveSupport.
If I comment out the two ActiveSupport 'requires' in fiscali/lib/fiscali.rb everything appears to work for me, so should ActiveSupport be in the gemspec (and fiscali.rb)?
Mike.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.