Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚨 Fix warnings #202

Merged
merged 4 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gemfiles/active_support_3.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gemspec :path => '../'

group :development, :test do
gem 'activesupport', '~> 3.0'
gem 'tzinfo', '~> 1.2'
end
30 changes: 13 additions & 17 deletions lib/business_time/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,7 @@ def threadsafe_cattr_setter(name)
end
end

# You can set this yourself, either by the load method below, or
# by saying
# BusinessTime::Config.beginning_of_workday = "8:30 am"
# someplace in the initializers of your application.
threadsafe_cattr_reader :beginning_of_workday

# You can set this yourself, either by the load method below, or
# by saying
# BusinessTime::Config.end_of_workday = "5:30 pm"
# someplace in the initializers of your application.
threadsafe_cattr_reader :end_of_workday

# You can set this yourself, either by the load method below, or
# by saying
# BusinessTime::Config.work_week = [:sun, :mon, :tue, :wed, :thu]
# someplace in the initializers of your application.
threadsafe_cattr_accessor :work_week
threadsafe_cattr_reader :work_week

# You can set this yourself, either by the load method below, or
# by saying
Expand All @@ -118,6 +102,10 @@ def threadsafe_cattr_setter(name)
threadsafe_cattr_accessor :fiscal_month_offset

class << self
# You can set this yourself, either by the load method below, or
# by saying
# BusinessTime::Config.end_of_workday = "5:30 pm"
# someplace in the initializers of your application.
def end_of_workday(day=nil)
if day
wday = work_hours[int_to_wday(day.wday)]
Expand All @@ -127,6 +115,10 @@ def end_of_workday(day=nil)
end
end

# You can set this yourself, either by the load method below, or
# by saying
# BusinessTime::Config.beginning_of_workday = "8:30 am"
# someplace in the initializers of your application.
def beginning_of_workday(day=nil)
if day
wday = work_hours[int_to_wday(day.wday)]
Expand All @@ -136,6 +128,10 @@ def beginning_of_workday(day=nil)
end
end

# You can set this yourself, either by the load method below, or
# by saying
# BusinessTime::Config.work_week = [:sun, :mon, :tue, :wed, :thu]
# someplace in the initializers of your application.
def work_week=(days)
config[:work_week] = days
self._weekdays = nil
Expand Down
6 changes: 3 additions & 3 deletions test/test_business_days.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
assert 5.business_days < 10.business_days
assert !(10.business_days < 5.business_days)

assert -1.business_day < 1.business_day
assert(-1.business_day < 1.business_day)
assert !(1.business_day < -1.business_day)
end

Expand All @@ -253,8 +253,8 @@
assert 5.business_days == 5.business_days
assert 10.business_days != 5.business_days

assert -1.business_day == -1.business_day
assert -1.business_day != -5.business_days
assert(-1.business_day == -1.business_day)
assert(-1.business_day != -5.business_days)
end

it "won't compare days to hours" do
Expand Down
14 changes: 7 additions & 7 deletions test/test_business_hours.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
it "consider any time on a weekend as equivalent to monday morning" do
sunday = Time.parse("Sun Apr 25 12:06:56, 2010")
monday = Time.parse("Mon Apr 26, 09:00:00, 2010")
assert_equal -1.business_hour.before(monday), -1.business_hour.before(sunday)
assert_equal(-1.business_hour.before(monday), -1.business_hour.before(sunday))
end

it "respect work_hours" do
Expand Down Expand Up @@ -286,10 +286,10 @@
assert 5.business_hours < 10.business_hours
assert !(10.business_hours < 5.business_hours)

assert -10.business_hours < -5.business_hours
assert(-10.business_hours < -5.business_hours)
assert !(-5.business_hours < -10.business_hours)

assert -5.business_hours < 5.business_hours
assert(-5.business_hours < 5.business_hours)
assert !(5.business_hours < -5.business_hours)
end

Expand All @@ -298,7 +298,7 @@
assert 10.business_hours > 5.business_hours

assert !(-10.business_hours > -5.business_hours)
assert -5.business_hours > -10.business_hours
assert(-5.business_hours > -10.business_hours)

assert !(-5.business_hours > 5.business_hours)
assert 5.business_hours > -5.business_hours
Expand All @@ -308,10 +308,10 @@
assert 5.business_hours == 5.business_hours
assert 10.business_hours != 5.business_hours

assert -5.business_hours == -5.business_hours
assert -5.business_hours != -10.business_hours
assert(-5.business_hours == -5.business_hours)
assert(-5.business_hours != -10.business_hours)

assert -5.business_hours != 5.business_hours
assert(-5.business_hours != 5.business_hours)
end

it "won't compare hours and days" do
Expand Down
2 changes: 1 addition & 1 deletion test/test_business_hours_eastern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
it "consider any time on a weekend as equivalent to monday morning" do
sunday = Time.zone.parse("Sun Apr 25 12:06:56, 2010")
monday = Time.zone.parse("Mon Apr 26, 09:00:00, 2010")
assert_equal -1.business_hour.before(monday), -1.business_hour.before(sunday)
assert_equal(-1.business_hour.before(monday), -1.business_hour.before(sunday))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_business_hours_utc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe "with a TimeWithZone object in UTC" do
before { Time.zone = 'UTC' }

describe "when adding/subtracting positive business hours" do
describe "when adding/subtracting positive business hours" do
it "move to tomorrow if we add 8 business hours" do
first = Time.zone.parse("Aug 4 2010, 9:35 am")
later = 8.business_hours.after(first)
Expand Down Expand Up @@ -114,7 +114,7 @@
it "consider any time on a weekend as equivalent to monday morning" do
sunday = Time.zone.parse("Sun Apr 25 12:06:56, 2010")
monday = Time.zone.parse("Mon Apr 26, 09:00:00, 2010")
assert_equal -1.business_hour.before(monday), -1.business_hour.before(sunday)
assert_equal(-1.business_hour.before(monday), -1.business_hour.before(sunday))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_calculating_consecutive_days.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'calculating consecutive workdays' do
it 'return empty array if object is not a workday' do
sunday = Date.parse("December 26, 2010")
sunday.consecutive_workdays.must_equal []
_(sunday.consecutive_workdays).must_equal []
end

it 'return array with self if preceded and followed by non-working days' do
Expand All @@ -27,7 +27,7 @@
describe 'calculating consecutive non-working days' do
it 'return empty array if object is not a non-working day' do
monday = Date.parse("December 13, 2010")
monday.consecutive_non_working_days.must_equal []
_(monday.consecutive_non_working_days).must_equal []
end

it 'return array with self if preceded and followed by workdays' do
Expand Down