Low commit activity in last 3 years
Date utilities including business day counting and arithmetic, quarter boundaries, weekend detection, and natural language relative date parsing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

philiprehberger-date_kit

Tests Gem Version Last updated

Date utilities for business days, relative expressions, and period calculations

Requirements

  • Ruby >= 3.1

Installation

Add to your Gemfile:

gem "philiprehberger-date_kit"

Or install directly:

gem install philiprehberger-date_kit

Usage

require "philiprehberger/date_kit"

Philiprehberger::DateKit.business_days_between(Date.new(2026, 3, 16), Date.new(2026, 3, 23))
# => 4

Adding Business Days

Philiprehberger::DateKit.add_business_days(Date.new(2026, 3, 20), 3)
# => 2026-03-25 (skips weekend)

holidays = [Date.new(2026, 3, 23)]
Philiprehberger::DateKit.add_business_days(Date.new(2026, 3, 20), 1, holidays: holidays)
# => 2026-03-24 (skips weekend and holiday)

Next / Previous Business Day

Philiprehberger::DateKit.next_business_day(Date.new(2026, 3, 20))
# => 2026-03-23 (skips weekend)

Philiprehberger::DateKit.prev_business_day(Date.new(2026, 3, 23))
# => 2026-03-20 (skips weekend)

holidays = [Date.new(2026, 3, 23)]
Philiprehberger::DateKit.next_business_day(Date.new(2026, 3, 20), holidays: holidays)
# => 2026-03-24 (skips weekend and holiday)

Business Days in Range

Philiprehberger::DateKit.business_days_in_range(Date.new(2026, 3, 16), Date.new(2026, 3, 20))
# => [2026-03-16, 2026-03-17, 2026-03-18, 2026-03-19, 2026-03-20]

Philiprehberger::DateKit.each_business_day(Date.new(2026, 3, 16), Date.new(2026, 3, 20)) do |date|
  puts date
end

# Without a block, returns an Enumerator
enum = Philiprehberger::DateKit.each_business_day(Date.new(2026, 3, 16), Date.new(2026, 3, 20))
enum.map { |d| d.strftime('%A') }

Quarter Boundaries

Philiprehberger::DateKit.quarter(Date.new(2026, 5, 15))
# => 2

Philiprehberger::DateKit.beginning_of_quarter(Date.new(2026, 5, 15))
# => 2026-04-01

Philiprehberger::DateKit.end_of_quarter(Date.new(2026, 5, 15))
# => 2026-06-30

Monthly Business Days

Philiprehberger::DateKit.business_day?(Date.new(2026, 3, 18))
# => true

Philiprehberger::DateKit.last_business_day_of_month(Date.new(2026, 5, 15))
# => 2026-05-29 (Friday; skips Sat/Sun month-end)

Philiprehberger::DateKit.first_business_day_of_month(Date.new(2026, 8, 15))
# => 2026-08-03 (Monday; skips Sat 8/1, Sun 8/2)

Philiprehberger::DateKit.business_days_in_month(Date.new(2026, 3, 15)).size
# => 22

Philiprehberger::DateKit.nth_business_day_of_month(Date.new(2026, 3, 15), 1)
# => 2026-03-02 (first business day of March)

Relative Date Parsing

Philiprehberger::DateKit.parse_relative('2 weeks ago')
Philiprehberger::DateKit.parse_relative('next month')
Philiprehberger::DateKit.parse_relative('yesterday')
Philiprehberger::DateKit.parse_relative('in 3 days')

Weekend Detection

Philiprehberger::DateKit.weekend?(Date.new(2026, 3, 21)) # => true (Saturday)
Philiprehberger::DateKit.weekend?(Date.new(2026, 3, 20)) # => false (Friday)

API

Method Description
.business_days_between(start, finish) Count business days between two dates
.add_business_days(date, n, holidays:) Add business days, skipping weekends and holidays
.next_business_day(date, holidays:) Return the next business day after the given date
.prev_business_day(date, holidays:) Return the previous business day before the given date
.business_days_in_range(start, finish, holidays:) Return array of business days in a date range
.each_business_day(start, finish, holidays:, &block) Iterate business days with Enumerator support
.quarter(date) Return the quarter number (1-4) for the given date
.beginning_of_quarter(date) Return the first day of the quarter
.end_of_quarter(date) Return the last day of the quarter
.weekend?(date) Check if a date falls on a weekend
.business_day?(date, holidays:) Check if a date is a business day (not weekend/holiday)
.last_business_day_of_month(date, holidays:) Return the last business day of the month
.first_business_day_of_month(date, holidays:) Return the first business day of the month
.business_days_in_month(date, holidays:) Return all business days in the month
.nth_business_day_of_month(date, n, holidays:) Return the nth business day of the month
.parse_relative(str, relative_to:) Parse a relative date expression

Development

bundle install
bundle exec rspec
bundle exec rubocop

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT