Class: DateTime

Inherits:
Object show all
Defined in:
lib/dohutil/to_display.rb,
lib/dohutil/core_ext/inspect.rb,
lib/dohutil/core_ext/datewithtime.rb

Constant Summary collapse

SECONDS_IN_DAY =
Rational(1, 60 * 60 * 24)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.seconds_to_days(seconds) ⇒ Object



15
16
17
# File 'lib/dohutil/core_ext/datewithtime.rb', line 15

def self.seconds_to_days(seconds)
  seconds.to_f * SECONDS_IN_DAY #.to_f
end

.zowObject



10
11
12
13
# File 'lib/dohutil/core_ext/datewithtime.rb', line 10

def self.zow
  obj = now
  new(obj.year, obj.month, obj.mday, obj.hour, obj.min, obj.sec, 0)
end

Instance Method Details

#inspectObject



13
14
15
# File 'lib/dohutil/core_ext/inspect.rb', line 13

def inspect
  "#<DateTime:#{strftime('%F %X %z')}>"
end

#next_second(n = 1) ⇒ Object



19
20
21
# File 'lib/dohutil/core_ext/datewithtime.rb', line 19

def next_second(n = 1)
  self + (SECONDS_IN_DAY * n)
end

#prev_second(n = 1) ⇒ Object



23
24
25
# File 'lib/dohutil/core_ext/datewithtime.rb', line 23

def prev_second(n = 1)
  next_second(-n)
end

#sub_dt(other) ⇒ Object

subtract another DateTime object, return difference in seconds



28
29
30
# File 'lib/dohutil/core_ext/datewithtime.rb', line 28

def sub_dt(other)
  ((self - other) / SECONDS_IN_DAY).to_i
end

#to_displayObject



10
11
12
# File 'lib/dohutil/to_display.rb', line 10

def to_display
  strftime('%m/%d/%Y %I:%M%P')
end