Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/time_freeze.rb,
lib/time_freeze/time_extensions.rb
Class Method Summary collapse
-
.freeze!(*args, &block) ⇒ Object
a handy shortcut to TimeFreeze.freeze!.
- .now ⇒ Object
- .now_unfrozen ⇒ Object
Instance Method Summary collapse
-
#to_datetime ⇒ Object
Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
-
#to_time ⇒ Object
A method to keep Time, Date and DateTime instances interchangeable on conversions.
Class Method Details
.freeze!(*args, &block) ⇒ Object
a handy shortcut to TimeFreeze.freeze!
42 43 44 |
# File 'lib/time_freeze.rb', line 42 def freeze!(*args, &block) TimeFreeze.freeze!(*args, &block) end |
.now ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/time_freeze.rb', line 33 def now if TimeFreeze.frozen_time TimeFreeze.frozen_time.to_time else self.now_unfrozen end end |
.now_unfrozen ⇒ Object
32 |
# File 'lib/time_freeze.rb', line 32 alias :now_unfrozen :now |
Instance Method Details
#to_datetime ⇒ Object
Converts a Time instance to a Ruby DateTime instance, preserving UTC offset.
my_time = Time.now # => Mon Nov 12 23:04:21 -0500 2007
my_time.to_datetime # => Mon, 12 Nov 2007 23:04:21 -0500
your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
your_time.to_datetime # => Tue, 13 Jan 2009 13:13:03 -0500
32 33 34 |
# File 'lib/time_freeze/time_extensions.rb', line 32 def to_datetime ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400)) end |
#to_time ⇒ Object
A method to keep Time, Date and DateTime instances interchangeable on conversions. In this case, it simply returns self
.
21 22 23 |
# File 'lib/time_freeze/time_extensions.rb', line 21 def to_time self end |