Class: UserTime

Inherits:
Object
  • Object
show all
Defined in:
lib/user_time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ UserTime

Returns a new instance of UserTime.



6
7
8
9
# File 'lib/user_time.rb', line 6

def initialize(user)
  @user = user
  @timezone = ActiveSupport::TimeZone[user.prefs.time_zone]
end

Instance Attribute Details

#timezoneObject (readonly)

Returns the value of attribute timezone.



4
5
6
# File 'lib/user_time.rb', line 4

def timezone
  @timezone
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/user_time.rb', line 4

def user
  @user
end

Instance Method Details

#dateObject



19
20
21
# File 'lib/user_time.rb', line 19

def date
  time.to_date
end

#midnight(date) ⇒ Object



11
12
13
# File 'lib/user_time.rb', line 11

def midnight(date)
  timezone.local(date.year, date.month, date.day, 0, 0, 0)
end

#timeObject



15
16
17
# File 'lib/user_time.rb', line 15

def time
  timezone.now
end