Module: Redmineup::DatetimeHelper

Defined in:
lib/redmineup/helpers/datetime_helper.rb

Instance Method Summary collapse

Instance Method Details

#convert_time_to_user_timezone(time) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/redmineup/helpers/datetime_helper.rb', line 3

def convert_time_to_user_timezone(time)
  if User.current.time_zone
    time.in_time_zone(User.current.time_zone)
  else
    time.utc? ? time.localtime : time
  end
end

#convert_time_to_utc(time = Time.now) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/redmineup/helpers/datetime_helper.rb', line 11

def convert_time_to_utc(time = Time.now)
  return Time.now.utc if time.blank?
  return time.utc if time.respond_to?(:utc)

  time_zone = User.current.time_zone
  return Time.parse(time).utc unless time_zone

  Time.use_zone(time_zone) do
    Time.zone.parse(time).utc
  end
end