Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
date_holidays-reader
Advanced tools
This is a read-only Ruby wrapper for the date-holidays Node module. Note that Node does not have to be installed on many machines in order to use this gem. See the configuration section for more details.
Holiday information is available for many different locales. The first step is to create a locale object which represents a country or part of a country. For example, to retrieve all holidays for this year in the United States:
us = DateHolidays::Reader::Locale.new(country: :us)
us.holidays(Date.today.year) # returns a list of US holidays for the current year
Locales can be refined to just one state or even a region within a state:
louisiana = DateHolidays::Reader::Locale.new(country: :us, state: :la)
louisiana.holidays(Date.today.year) # returns US and Louisiana holidays
new_orleans = DateHolidays::Reader::Locale.new(country: :us, state: :la, region: :no)
new_orleans.holidays(Date.today.year) # includes Mardi Gras plus all state country holidays
Some countries support more than one language:
mx = DateHolidays::Reader::Locale.new(country: :mx)
mx.languages # ["en", "es"]
mx.holidays(Date.year)
mx.holidays(Date.today.year).first.name # "New Year's Day"
mx.holidays(Date.today.year, language: :es).first.name # "Año Nuevo"
Country, state, and region codes are defined in the ISO 3166-2 standard. These examples pass in the codes using Ruby symbols. However, it is also valid to specify them as Ruby strings. The supported codes can also be retrived using the following meta-data methods:
# Returns a hash of all supported countries keyed by two letter ISO 3166-2 code
# and values of the country name:
DateHolidays::Reader::Config.countries
# {"AD"=>"Andorra", "AE"=>"دولة الإمارات العربية المتحدة", ... }
# Returns a hash of all supported states keyed by two letter ISO 3166-2 code
# and values of the state name:
DateHolidays::Reader::Locale.new(country: :us).states
# {"AL"=>"Alabama", "AK"=>"Alaska", "AZ"=>"Arizona", ... }
# Returns a hash of all supported regions keyed by two letter ISO 3166-2 code
# and values of the region name:
DateHolidays::Reader::Locale.new(country: :us, state: :la).regions
# {"NO"=>"New Orleans"}
DateHolidays::Reader::Locale#holidays
returns a list containing an instance of DateHolidays::Reader::Holiday
objects which have the following fields:
Date
instance.Time
instance. Note that these times represent when the holiday starts in this locale. For example, US New Year's day in 2019 has a time of '2019-01-01 05:00:00 UTC' as Washington DC is five hours behind UTC.String
or nil
.Note that this is a wrapper for the JavaScript Holiday object described here.
The API provided by this gem is somewhat different than the API provided by the date-holidays node module. This is intentional in order to make the Ruby API more object-oriented. The biggest change is that the JavaScript API does not have a locale class.
Add this line to your application's Gemfile:
gem 'date_holidays-reader'
And then execute:
$ bundle
Or install it yourself as:
$ gem install date_holidays-reader
If you are running a Linux or Mac OS X machine running an x86-64 compatible processor then everything should work at this point. If you are running a different OS, different processor, or would like to use Node directly then continue to the configuration section.
This gem ships with pre-compiled wrapper programs for the date-holidays Node module for Mac OS X and Linux running on x86-64 processors. If you are running on those architectures then no configuration is needed as one those binaries will be used by default. If the gem detects that you are running on a different architecture then it will attempt to use the version of Node.js in your path. In this case, you will need to install the date-holidays Node module before using this gem. It is also possible to explicitly tell the gem where your Node.js binary is located:
DateHolidays::Reader::Config.node_path = '/path/to/your/version/of/node'
Note that setting node_path
will also force the gem to use Node instead of the provided binaries when running on a supported OS and processor combination.
Note that native Windows support would not be difficult to add. Pull requests are welcome!
The holidays gem is very similar and is a pure Ruby implementation. This gem was created as the date-holidays node module has support for more countries. An advantage of the holidays gem over this gem is that holidays is faster as it does not have to fork a Node.js process in order to retrieve data. Also, the holidays gem has support for some niche data such as US Federal Reserve Banks, the New York Stock Exchange, and others. Use the right tool for your needs.
The holiday definitions provided by the date-holidays Node module are defined by a specific grammar housed in YAML files. The next logical step would be to build a pure Ruby parser for this grammar. Time is the only limit here. If this work is done, it would be in a separate gem as it would not have to be a read-only interface; it would be trivial to support user defined holiday definitions like the Node module.
You may be wondering: "Why the underscore and dash in the name?" This is intentional to match the name of of the main Ruby module of DateHolidays::Reader
. The Ruby convention is to use underscores to separate words and dashes for namespaces. Note that if another gem is created which is not just a Node module wrapper then the module will be just DateHolidays
and the gem will be named date_holidays.
Since this gem wraps a Node module, a Node.js installation is required. See the .nvmrc
file for a recommended Node version. Yarn is also required to install requisite Node modules.
After checking out the repo and installing Node and Yarn, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
.
Note that rake clobber
can be used to removed the pre-compiled Node wrappers.
There is also a Dockerfile
provided which can be used to verify the Linux binaries.
Update the version number in version.rb
and add a new entry to CHANGELOG.md
.
Commit and push the above changes.
Then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
yarn upgrade
Verify from the Yarn output that date-holidays was updated.
bundle exec rake node_compile
Update the node module version in spec/date_holidays/reader/version_spec.rb
.
Verify by running the tests and check in yarn.lock.
Bug reports and pull requests are welcome on GitHub at https://github.com/bluemarblepayroll/date_holidays-reader. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Before submitting a pull requests, please do the following:
Everyone interacting in the DateHolidays::Reader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
This project is MIT and Creative Commons Attribution-ShareAlike 3.0 Licensed. See the LICENSE file for more information.
FAQs
Unknown package
We found that date_holidays-reader 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.