Class: DateTime

Inherits:
Object
  • Object
show all
Defined in:
lib/cotcube-helpers/datetime_ext.rb

Overview

Monkey patching the Ruby class DateTime

Instance Method Summary collapse

Instance Method Details

#seconds_until_next_minute(offset: 60) ⇒ Object



16
17
18
19
20
21
# File 'lib/cotcube-helpers/datetime_ext.rb', line 16

def seconds_until_next_minute(offset: 60)
  offset = offset % 60
  offset = 60 if offset.zero?
  seconds = (self + offset - (self.to_f % 60).round(3) - self).to_f
  seconds + (seconds.negative? ? 60 : 0)
end

#to_seconds_since_sunday_morningObject Also known as: to_sssm

based on the fact that sunday is ‘wday 0’ plus that trading week starts

sunday 0:00 (as trading starts sunday 5pm CT to fit tokyo monday morning)

TODO: there is a slight flaw, that 1 sunday per year is 1 hour too short and another is 1 hour too long



10
11
12
# File 'lib/cotcube-helpers/datetime_ext.rb', line 10

def to_seconds_since_sunday_morning
  wday * 86_400 + hour * 3600 + min * 60 + sec
end