Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/sg_common/core_ext/date/sg_date.rb

Overview

This class contains Date extensions used by SG

Constant Summary collapse

SG_TIME_OFFSET =

SG date start at 5am ET

5

Instance Method Summary collapse

Instance Method Details

#beginning_of_sg_day(time_zone) ⇒ Object



12
13
14
15
16
# File 'lib/sg_common/core_ext/date/sg_date.rb', line 12

def beginning_of_sg_day(time_zone)
  timezone = TZInfo::Timezone.get(time_zone)

  timezone.local_to_utc(Time.local(year, month, day, SG_TIME_OFFSET, 0, 0, 0))
end

#dtObject



26
27
28
# File 'lib/sg_common/core_ext/date/sg_date.rb', line 26

def dt
  strftime('%Y%m%d')
end

#end_of_sg_day(time_zone) ⇒ Object



18
19
20
# File 'lib/sg_common/core_ext/date/sg_date.rb', line 18

def end_of_sg_day(time_zone)
  (self + 1.day).beginning_of_sg_day(time_zone)
end

#hours_in_sg_day(time_zone) ⇒ Object



22
23
24
# File 'lib/sg_common/core_ext/date/sg_date.rb', line 22

def hours_in_sg_day(time_zone)
  ((end_of_sg_day(time_zone) - beginning_of_sg_day(time_zone)) / 1.hour).round
end

#utc_time_offset(time_zone) ⇒ Object



8
9
10
# File 'lib/sg_common/core_ext/date/sg_date.rb', line 8

def utc_time_offset(time_zone)
  (self.beginning_of_sg_day(time_zone) - self.to_time(:utc).midnight) / 3600
end