class ErpBaseErpSvcs::Helpers::Time::Client

Public Class Methods

new(client_utc_offset=nil) click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 7
def initialize(client_utc_offset=nil)
  @offset_in_hours = get_offset_in_hours(client_utc_offset)
end

Public Instance Methods

beginning_of_day() click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 19
def beginning_of_day
  (::Time.now  + @offset_in_hours.hours).beginning_of_day
end
beginning_of_week() click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 27
def beginning_of_week
  (::Time.now  + @offset_in_hours.hours).beginning_of_week
end
client_to_utc_time(time) click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 15
def client_to_utc_time(time)
  time - @offset_in_hours.hours
end
end_of_day() click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 23
def end_of_day
  (::Time.now  + @offset_in_hours.hours).end_of_day
end
end_of_week() click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 31
def end_of_week
  (::Time.now  + @offset_in_hours.hours).end_of_week
end
in_client_time(time) click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 11
def in_client_time(time)
  time + @offset_in_hours.hours
end

Protected Instance Methods

get_offset_in_hours(client_utc_offset=nil) click to toggle source
# File lib/erp_base_erp_svcs/time_zone_helper.rb, line 37
def get_offset_in_hours(client_utc_offset=nil)
  if client_utc_offset.nil?
    offset = ::Time.now.formatted_offset
    if offset.is_a? Integer
      offset/60.0
    else
      hours_and_minutes = offset.split(':').map(&:to_f)
      hours_and_minutes[0] + hours_and_minutes[1]/60
    end
  else
    client_utc_offset = client_utc_offset.to_i
    hours = client_utc_offset / 60.0
    -hours
  end
end