134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/timecop/time_extensions.rb', line 134
def parse_with_mock_date(*args)
parsed_date = parse_without_mock_date(*args)
return parsed_date unless mocked_time_stack_item
date_hash = DateTime._parse(*args)
case
when date_hash[:year] && date_hash[:mon]
parsed_date
when date_hash[:mon] && date_hash[:mday]
DateTime.new(mocked_time_stack_item.year, date_hash[:mon], date_hash[:mday])
when date_hash[:mday]
DateTime.new(mocked_time_stack_item.year, mocked_time_stack_item.month, date_hash[:mday])
when date_hash[:wday] && date_hash[:hour] && date_hash[:min]
closest_date = Date.closest_wday(date_hash[:wday]).to_datetime
DateTime.new(
closest_date.year, closest_date.month, closest_date.day,
date_hash[:hour], date_hash[:min]
)
when date_hash[:wday]
Date.closest_wday(date_hash[:wday]).to_datetime
when date_hash[:hour] && date_hash[:min] && date_hash[:sec]
DateTime.new(mocked_time_stack_item.year, mocked_time_stack_item.month, mocked_time_stack_item.day, date_hash[:hour], date_hash[:min], date_hash[:sec])
else
parsed_date + mocked_time_stack_item.travel_offset_days
end
end
|