Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
imseng-business_time
Advanced tools
= business_time
{}[http://travis-ci.org/bokmann/business_time]
ActiveSupport gives us some great helpers so we can do things like:
5.days.ago
and
8.hours.from_now
as well as helpers to do that from any provided date or time.
I needed this, but taking into account business hours/days and holidays.
== Usage
install the gem
gem install business_time
or
sudo gem install business_time
if you require sudo to install gems
open up your console
require 'rubygems' require 'active_support' require 'business_time'
1.business_hour.from_now 4.business_hours.from_now 8.business_hours.from_now
1.business_hour.ago 4.business_hours.ago 8.business_hours.ago
1.business_day.from_now 4.business_days.from_now 8.business_days.from_now
1.business_day.ago 4.business_days.ago 8.business_days.ago
my_birthday = Date.parse("August 4th, 1969") 8.business_days.after(my_birthday) 8.business_days.before(my_birthday)
my_birthday = Time.parse("August 4th, 1969, 8:32 am") 8.business_days.after(my_birthday) 8.business_days.before(my_birthday)
BusinessTime::Config.beginning_of_workday = "8:30 am" BusinessTime::Config.end_of_workday = "5:30 pm"
three_day_weekend = Date.parse("July 5th, 2010") BusinessTime::Config.holidays << three_day_weekend friday_afternoon = Time.parse("July 2nd, 2010, 4:50 pm") tuesday_morning = 1.business_hour.after(friday_afternoon)
BusinessTime::Config.work_week = [:sun, :mon, :tue, :wed, :thu] thursday_afternoon = Time.parse("July 8th, 2010, 4:50 pm") sunday_morning = 1.business_hour.after(thursday_afternoon)
friday = Date.parse("December 24, 2010") monday = Date.parse("December 27, 2010") friday.business_days_until(monday) #=> 1
ticket_reported = Time.parse("February 3, 2012, 10:40 am") ticket_resolved = Time.parse("February 4, 2012, 10:50 am") ticket_reported.business_time_until(ticket_resolved) #=> 8.hours + 10.minutes
ticket_reported = Time.parse("February 3, 2012, 10:40 am") ticket_resolved = Time.parse("February 4, 2012, 10:40 am") ticket_reported.business_time_until(ticket_resolved) # will equal 6 hours and 20 minutes!
== Usage in Rails The code above should work on a rails console without any issue. You will want to add a line something like:
config.gem "business_time"
to your environment.rb file. Or if you're using bundler, add this line to your Gemfile:
gem "business_time"
This gem also includes a generator so you can bootstrap some stuff in your environment:
./script/generate business_time_config
Or in Rails 3:
script/rails generate business_time:config
The generator will add a /config/business_time.yml and a /config/initializers/business_time.rb file that will cause the start of business day, the end of business day, and your holidays to be loaded from the yaml file. You might want to programatically load your holidays from a database table, but you will want to pay attention to how the initializer works - you will want to make sure that the initializer sets stuff up appropriately so rails instances on mongrels or passenger will have the appropriate data as they come up and down.
== Outside of Rails This code does depend on ActiveSupport, but nothing else within rails. Even then, it would be pretty easy to break that dependency as well (but would add some code bloat and remove some clarity). Feel free to use it on any ruby project you'd like!
== Timezone support This gem strives to be timezone-agnostic. Due to some complications in the handling of timezones in the built in Time class, and some complexities (bugs?) in the timeWithZone class, this was harder than expected... but here's the idea:
This can lead to some wierd looking effects if, say, you are in the Eastern time zone but doing everything in UTC times... Your business day will appear to start and end at 9:00 and 5:00 UTC. If this seems perplexing to you, I can almost guarantee you are in over your head with timezones in other ways too, this is just the first place you encountered it. Timezone relative date handling gets more and more complicated every time you look at it and takes a long time before it starts to seem simple again. I'm hoping Arild and I write some good blog entries on the subject at http://blog.codesherpas.com.
== Integration with the Holidays gem
Chris Wise wrote up a great article[http://murmurinfo.wordpress.com/2012/01/11/handling-holidays-and-business-hours/] on using the business_time gem with the holidays[https://github.com/HealthyWeb/holidays] gem. It boils down to this:
Holidays.between(Date.civil(2011, 1, 1), 2.years.from_now, :ca_on, :o bserved).map{|holiday| BusinessTime::Config.holidays << holiday[:date]}
== Contributors
(Special thanks for Arild on the complexities of dealing with TimeWithZone)
== Note on Patches/Pull Requests
== TODO
== NOT TODO
I spent way too much time in my previous java-programmer life building frameworks that worshipped complexity, always trying to give the developer-user ultimate flexibility at the expense of the 'surface area' of the api. Never again - I will sooner limit functionality to 80% so that something stays usable and let people fork.
While there have been requests to add 'business minutes' and even 'business seconds' to this gem, I won't entertain a pullup request with such things. If you find it useful, great. Most users won't, and they don't need the baggage.
== Copyright
Copyright (c) 2010,2011,2012 bokmann. See LICENSE for details.
FAQs
Unknown package
We found that imseng-business_time demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.