gocardless / business Goto Github PK
View Code? Open in Web Editor NEWRuby business day calculations
License: MIT License
Ruby business day calculations
License: MIT License
Hello in the doc to load extra calendars we are supposed to do
Business::Calendar.load_paths("lib/calendars") # your_project/lib/calendars/ contains bacs.yml
Business::Calendar.load("bacs")
the resulting error is wrong number of arguments (given 1, expected 0)
load_paths is an attr_accessor accepting an array so the doc should be
Business::Calendar.load_paths = [Rails.root.join("lib/calendars")] # your_project/lib/calendars/ contains bacs.yml
Business::Calendar.load("bacs")
Hi:
Amazing gem you have created. It's working really good. I have two questions, so I hope you can help me:
1.- Where can I find the yml files that comes along with the gem so I can edit them?
2.- How can I use my own .yml file on my lib/data directory?
Thanks for your answer.!
Loving the gem - however I noticed that for some reason June 2015 (with the BST timezone) reports incorrect business days.
calendar = Business::Calendar.new(working_days: %w( mon tue wed thu fri ))
start_date = Date.parse("23 June 2015")
end_date = Date.parse("30 June 2015")
calendar.business_days_between(start_date, end_date) #=> 5
(start_date..end_date).to_a.select {|d| calendar.business_day?(d)}.size #=> 6
Any ideas what's wrong? Is it only me that sees this?
Version: 1.16.0
Ruby: 2.6.3p62
Rails: 5.0.1
The roll_forward and roll_backward methods are returning the current date instead of previous and next business day
current_date = Date.today.in_time_zone('Australia/Melbourne')
calendar = Business::Calendar.new(
working_days: %w[mon tue wed thu fri],
holidays: HolidayList.holidays(current_date)
)
p calendar
p calendar.roll_forward(Time.now.in_time_zone('Australia/Melbourne').to_date)
Expected:
#<Business::Calendar:0x00007f8933f20d00 @extra_working_dates=[], @working_days=["mon", "tue", "wed", "thu", "fri"], @holidays=[Wed, 25 Dec 2019, Thu, 26 Dec 2019]>
Fri, 06 Dec 2019
Received:
#<Business::Calendar:0x00007f8933f20d00 @extra_working_dates=[], @working_days=["mon", "tue", "wed", "thu", "fri"], @holidays=[Wed, 25 Dec 2019, Thu, 26 Dec 2019]>
Thu, 05 Dec 2019
I realize this would be a disruptive change, but I have to maintain my own fork with the Business
module renamed to BusinessDay
because my application has a class named Business
. Probably not a common problem, but I think a best practice would be to establish a namespace that's more specific and descriptive, and as such less likely to conflict with other code. Happy to submit a PR if there's any interest in pursuing this.
It seems 1.15.0 was the last release tagged, but there are 3 released versions since then.
#next_business_day
and #previous_business_day
are useful public methods of Business::Calendar
:
business/lib/business/calendar.rb
Lines 106 to 122 in 936546b
The README’s “Business day arithmetic” section does not document those methods. It should.
Where I think this documentation belongs in that section of the README:
next_business_day
– documentation neededprevious_business_day
– documentation neededadd_business_days
subtract_business_days
roll_forward
roll_backward
business_days_between
Define these instance methods of Business::Calendar
:
earliest_business_date_on_or_after
– alias for roll_forward
latest_business_date_on_or_before
– alias for roll_backward
While these names are more verbose, my team agrees that they are easier to understand.
Part of the problem with the current names roll_forward
and roll_backward
is that the imperative verb “roll” makes the methods sound like they will mutate the passed date, though they do not. (It’s good that they do not.)
Define these new names as aliases instead of renaming the existing methods to preserve backwards compatibility.
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.