Class: DateTime
- Inherits:
-
Object
- Object
- DateTime
- Defined in:
- lib/timecop/time_extensions.rb
Overview
:nodoc:
Class Method Summary collapse
- .mock_time ⇒ Object
- .mocked_time_stack_item ⇒ Object
- .now_with_mock_time ⇒ Object (also: now)
- .parse_with_mock_date(*args) ⇒ Object (also: parse)
Class Method Details
.mock_time ⇒ Object
115 116 117 |
# File 'lib/timecop/time_extensions.rb', line 115 def mock_time mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self) end |
.mocked_time_stack_item ⇒ Object
150 151 152 |
# File 'lib/timecop/time_extensions.rb', line 150 def mocked_time_stack_item Timecop.top_stack_item end |
.now_with_mock_time ⇒ Object Also known as: now
119 120 121 |
# File 'lib/timecop/time_extensions.rb', line 119 def now_with_mock_time mock_time || now_without_mock_time end |
.parse_with_mock_date(*args) ⇒ Object Also known as: parse
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/timecop/time_extensions.rb', line 127 def parse_with_mock_date(*args) date_hash = Date._parse(*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.closest_wday(date_hash[:wday]).to_datetime else parsed_date + mocked_time_stack_item.travel_offset_days end end |