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
113 114 115 |
# File 'lib/timecop/time_extensions.rb', line 113 def mock_time mocked_time_stack_item.nil? ? nil : mocked_time_stack_item.datetime(self) end |
.mocked_time_stack_item ⇒ Object
146 147 148 |
# File 'lib/timecop/time_extensions.rb', line 146 def mocked_time_stack_item Timecop.top_stack_item end |
.now_with_mock_time ⇒ Object Also known as: now
117 118 119 |
# File 'lib/timecop/time_extensions.rb', line 117 def now_with_mock_time mock_time || now_without_mock_time end |
.parse_with_mock_date(*args) ⇒ Object Also known as: parse
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/timecop/time_extensions.rb', line 125 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[:wday] Date.closest_wday(date_hash[:wday]).to_datetime else parsed_date + mocked_time_stack_item.travel_offset_days end end |