Skip to content

Commit

Permalink
Merge pull request #214 from bokmann/remove-sorted-set
Browse files Browse the repository at this point in the history
Remove dependency on SortedSet
  • Loading branch information
rmm5t authored Jun 7, 2022
2 parents bdc310b + bc878a3 commit 9aeff65
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com//), and thi
## [Unreleased] - TBD

- Update build matrix for ActiveSupport 7 support (#215)
- Remove dependency on sorted_set and rbtree (#214)

Both `BusinessTime::Config.holidays` and `BusinessTime::Config.weekdays` now
return a `Set` instead of a `SortedSet`.

Warning: `BusinessTime::Config.holidays` no longer keeps holidays in sorted
order. If you rely on `holidays` returning in sorted order, please be sure to
load them in sorted order.

## [0.11.0] - 2021-11-22

Expand Down
1 change: 0 additions & 1 deletion business_time.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Gem::Specification.new do |s|

s.add_dependency("activesupport", ">= 3.2.0")
s.add_dependency("tzinfo")
s.add_dependency("sorted_set") # for Ruby 3 support

s.add_development_dependency "rake"
s.add_development_dependency "rdoc"
Expand Down
7 changes: 4 additions & 3 deletions lib/business_time.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'thread'
require 'active_support'
require 'active_support/time'
require 'set'
require 'time'
require 'yaml'

require 'active_support'
require 'active_support/time'

require 'business_time/parsed_time'
require 'business_time/version'
require 'business_time/config'
Expand Down
4 changes: 2 additions & 2 deletions lib/business_time/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module BusinessTime
# manually, or with a yaml file and the load method.
class Config
DEFAULT_CONFIG = {
holidays: SortedSet.new,
holidays: Set.new,
beginning_of_workday: ParsedTime.parse('9:00 am'),
end_of_workday: ParsedTime.parse('5:00 pm'),
work_week: %w(mon tue wed thu fri),
Expand Down Expand Up @@ -144,7 +144,7 @@ def weekdays
wday_to_int(day_name)
end.compact

self._weekdays = SortedSet.new(days)
self._weekdays = days.sort.to_set
end

# loads the config data from a yaml file written as:
Expand Down
13 changes: 7 additions & 6 deletions test/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
end

it "map work week to weekdays" do
assert_equal SortedSet.new([1,2,3,4,5]), BusinessTime::Config.weekdays
BusinessTime::Config.work_week = %w[sun mon tue wed thu]
assert_equal SortedSet.new([0,1,2,3,4]), BusinessTime::Config.weekdays
assert_equal Set.new([1,2,3,4,5]), BusinessTime::Config.weekdays
BusinessTime::Config.work_week = %w[thu mon sun tue wed]
assert_equal Set.new([0,1,2,3,4]), BusinessTime::Config.weekdays
assert_equal [0,1,2,3,4], BusinessTime::Config.weekdays.to_a
BusinessTime::Config.work_week = %w[tue wed] # Hey, we got it made!
assert_equal SortedSet.new([2,3]), BusinessTime::Config.weekdays
assert_equal Set.new([2,3]), BusinessTime::Config.weekdays
end

it "keep track of the start of the day using work_hours" do
Expand Down Expand Up @@ -78,7 +79,7 @@
assert_equal BusinessTime::ParsedTime.new(11, 0), BusinessTime::Config.beginning_of_workday
assert_equal BusinessTime::ParsedTime.new(14, 0), BusinessTime::Config.end_of_workday
assert_equal ['mon'], BusinessTime::Config.work_week
assert_equal SortedSet.new([Date.parse('2012-12-25')]), BusinessTime::Config.holidays
assert_equal Set.new([Date.parse('2012-12-25')]), BusinessTime::Config.holidays
end

it "include holidays read from YAML config files" do
Expand All @@ -103,7 +104,7 @@
assert_equal BusinessTime::ParsedTime.new(9, 0), BusinessTime::Config.beginning_of_workday
assert_equal BusinessTime::ParsedTime.new(17, 0), BusinessTime::Config.end_of_workday
assert_equal %w[mon tue wed thu fri], BusinessTime::Config.work_week
assert_equal SortedSet.new, BusinessTime::Config.holidays
assert_equal Set.new, BusinessTime::Config.holidays
end

it "is threadsafe" do
Expand Down

0 comments on commit 9aeff65

Please sign in to comment.