business
business copied to clipboard
Attempt partial implementation in Rust using rutie
Set up for mac (other platforms not tested)
-
Install rust
-
Ensure that your ruby installation has "enabled shared" configured You can check this by running:
ruby -e "pp RbConfig::CONFIG['ENABLE_SHARED']"
. If it prints"yes"
then you are good to go. If you have installed Ruby usingrbenv
(like I had), then you will have to recompile your ruby installation, by running:
RUBY_CONFIGURE_OPTS=--enable-shared rbenv install
Usage
Run cargo build --release
to compile the rust code
You can open a ruby interpreter to test the code, run:
irb -r bundler/setup -r ./lib/business -r date
Interface should work as expected:
irb(main):001:0> calendar = Business::Calendar.new(holidays: ["2020-12-25"])
irb(main):002:0> calendar.business_day?("2020-12-25")
=> false
irb(main):003:0> calendar.business_day?("2020-12-24")
=> true
irb(main):004:0> calendar.add_business_days("2020-12-24", 1)
=> "2020-12-28"
irb(main):005:0> calendar.working_days
=> ["mon", "tue", "wed", "thu", "fri"]
Caveat
I have not yet figured out how to pass ruby Date
objects across the primitives, so it only uses the primitives specified by rutie
(eg. calendar.business_day?(Date.today)
will not work, do calendar.business_day?(Date.today.to_s)
instead.
If you want to load calendar data from the, use Calendar#sanitise_and_load
instead of Calendar#load
.
Specs
About half the specs still don't pass (locally), because of the limit interface (eg. only accepts String
instead of Date
/DateTime
. Circle specs don't work because they aren't configured.