Proper timezone handling without needing activesupport
This commit is contained in:
parent
912292b087
commit
b94712703d
2 changed files with 16 additions and 5 deletions
|
@ -87,8 +87,18 @@ module Holidays
|
||||||
start_date = start_date.new_offset(0) if start_date.respond_to?(:new_offset)
|
start_date = start_date.new_offset(0) if start_date.respond_to?(:new_offset)
|
||||||
end_date = end_date.new_offset(0) if end_date.respond_to?(:new_offset)
|
end_date = end_date.new_offset(0) if end_date.respond_to?(:new_offset)
|
||||||
|
|
||||||
start_date = start_date.to_date if start_date.respond_to?(:to_date)
|
# get simple dates
|
||||||
end_date = end_date.to_date if end_date.respond_to?(:to_date)
|
if start_date.respond_to?(:to_date)
|
||||||
|
start_date = start_date.to_date
|
||||||
|
else
|
||||||
|
start_date = Date.civil(start_date.year, start_date.mon, start_date.mday)
|
||||||
|
end
|
||||||
|
|
||||||
|
if end_date.respond_to?(:to_date)
|
||||||
|
end_date = end_date.to_date
|
||||||
|
else
|
||||||
|
end_date = Date.civil(end_date.year, end_date.mon, end_date.mday)
|
||||||
|
end
|
||||||
|
|
||||||
regions, observed, informal = parse_options(options)
|
regions, observed, informal = parse_options(options)
|
||||||
holidays = []
|
holidays = []
|
||||||
|
|
|
@ -107,7 +107,8 @@ class DateTests < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_datetime_holiday?
|
def test_datetime_holiday?
|
||||||
assert DateTime.now.to_date.holiday?('test')
|
# in situations with activesupport
|
||||||
|
assert DateTime.now.to_date.holiday?('test') if DateTime.now.respond_to?(:to_date)
|
||||||
assert DateTime.now.holiday?('test')
|
assert DateTime.now.holiday?('test')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue