Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/time_freeze.rb,
lib/time_freeze/time_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.nowObject



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_unfrozenObject



32
# File 'lib/time_freeze.rb', line 32

alias :now_unfrozen :now

Instance Method Details

#to_datetimeObject

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_timeObject

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