Class: DateTime

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

Constant Summary collapse

DAY_SECONDS =
60 * 60 * 24

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.local(year, month, day, hour = 0, minute = 0, second = 0) ⇒ Object



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

def self.local(year, month, day, hour = 0, minute = 0, second = 0)
  Time.local(year, month, day, hour, minute, second).to_datetime
end

.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 / DAY_SECONDS.to_f
end

.zowObject



7
8
9
# File 'lib/dohutil/core_ext/datewithtime.rb', line 7

def self.zow
  now.zowify
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 + self.class.seconds_to_days(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) * DAY_SECONDS).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

#zowifyObject



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

def zowify
  self.class.new(year, month, mday, hour, min, sec, 0)
end