mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 00:00:12 +01:00
rename DateUtils to UserTime
This commit is contained in:
parent
6c695aa61a
commit
8512e8db3b
6 changed files with 18 additions and 9 deletions
|
|
@ -22,6 +22,6 @@ class Preference < ActiveRecord::Base
|
||||||
raise ArgumentError.new("Bad argument type:#{s.class}")
|
raise ArgumentError.new("Bad argument type:#{s.class}")
|
||||||
end
|
end
|
||||||
|
|
||||||
DateUtils::midnight_for(self, date)
|
UserTime.new(user).midnight(date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ class Todo < ActiveRecord::Base
|
||||||
activate
|
activate
|
||||||
else
|
else
|
||||||
# parse Date objects into the proper timezone
|
# parse Date objects into the proper timezone
|
||||||
date = DateUtils.midnight_for(user.prefs, date) if (date.is_a? Date)
|
date = UserTime.new(user).midnight(date) if (date.is_a? Date)
|
||||||
|
|
||||||
# show_from needs to be set before state_change because of "bug" in aasm.
|
# show_from needs to be set before state_change because of "bug" in aasm.
|
||||||
# If show_from is not set, the todo will not validate and thus aasm will not save
|
# If show_from is not set, the todo will not validate and thus aasm will not save
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def date
|
def date
|
||||||
time.midnight
|
UserTime.new(self).midnight(Time.now)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_token
|
def generate_token
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
class DateUtils
|
|
||||||
def self.midnight_for(prefs, date)
|
|
||||||
ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
14
lib/user_time.rb
Normal file
14
lib/user_time.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
require 'active_support/values/time_zone'
|
||||||
|
|
||||||
|
class UserTime
|
||||||
|
attr_reader :user, :timezone
|
||||||
|
|
||||||
|
def initialize(user)
|
||||||
|
@user = user
|
||||||
|
@timezone = ActiveSupport::TimeZone[user.prefs.time_zone]
|
||||||
|
end
|
||||||
|
|
||||||
|
def midnight(date)
|
||||||
|
timezone.local(date.year, date.month, date.day, 0, 0, 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -119,7 +119,7 @@ class RecurringTodosControllerTest < ActionController::TestCase
|
||||||
# due date should be the target_date
|
# due date should be the target_date
|
||||||
user = users(:admin_user)
|
user = users(:admin_user)
|
||||||
target_date = Date.new(target_date.year, target_date.month, target_date.day)
|
target_date = Date.new(target_date.year, target_date.month, target_date.day)
|
||||||
assert_equal DateUtils.midnight_for(user.prefs, target_date), new_todo.due
|
assert_equal UserTime.new(user).midnight(target_date), new_todo.due
|
||||||
|
|
||||||
# show_from should be nil since now+4.days-10.days is in the past
|
# show_from should be nil since now+4.days-10.days is in the past
|
||||||
assert_equal nil, new_todo.show_from
|
assert_equal nil, new_todo.show_from
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue