mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
remove returns and clean up some conditionals
This commit is contained in:
parent
c71dc9afc9
commit
55e2f5b6a1
1 changed files with 49 additions and 53 deletions
|
|
@ -194,17 +194,15 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_every_x_day
|
def monthly_every_x_day
|
||||||
return self.every_other1
|
self.every_other1
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_monthly_every_x_day
|
def is_monthly_every_x_day
|
||||||
return self.recurrence_selector == 0 if recurring_period == 'monthly'
|
recurring_period == 'monthly' && self.recurrence_selector == 0
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_monthly_every_xth_day
|
def is_monthly_every_xth_day
|
||||||
return self.recurrence_selector == 1 if recurring_period == 'monthly'
|
recurring_period == 'monthly' && self.recurrence_selector == 1
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_every_x_month=(x)
|
def monthly_every_x_month=(x)
|
||||||
|
|
@ -214,7 +212,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
def monthly_every_x_month
|
def monthly_every_x_month
|
||||||
# in case monthly pattern is every day x, return every_other2 otherwise
|
# in case monthly pattern is every day x, return every_other2 otherwise
|
||||||
# return a default value
|
# return a default value
|
||||||
return self.recurrence_selector == 0 ? self.every_other2 : 1
|
self.recurrence_selector == 0 ? self.every_other2 : 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_every_x_month2=(x)
|
def monthly_every_x_month2=(x)
|
||||||
|
|
@ -224,7 +222,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
def monthly_every_x_month2
|
def monthly_every_x_month2
|
||||||
# in case monthly pattern is every xth day, return every_other2 otherwise
|
# in case monthly pattern is every xth day, return every_other2 otherwise
|
||||||
# return a default value
|
# return a default value
|
||||||
return self.recurrence_selector == 1 ? self.every_other2 : 1
|
self.recurrence_selector == 1 ? self.every_other2 : 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_every_xth_day=(x)
|
def monthly_every_xth_day=(x)
|
||||||
|
|
@ -232,8 +230,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_every_xth_day(default=nil)
|
def monthly_every_xth_day(default=nil)
|
||||||
return self.every_other3 unless self.every_other3.nil?
|
self.every_other3 || default
|
||||||
return default
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_day_of_week=(dow)
|
def monthly_day_of_week=(dow)
|
||||||
|
|
@ -241,7 +238,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def monthly_day_of_week
|
def monthly_day_of_week
|
||||||
return self.every_count
|
self.every_count
|
||||||
end
|
end
|
||||||
|
|
||||||
# YEARLY
|
# YEARLY
|
||||||
|
|
@ -257,7 +254,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
def yearly_month_of_year
|
def yearly_month_of_year
|
||||||
# if recurrence pattern is every x day in a month, return month otherwise
|
# if recurrence pattern is every x day in a month, return month otherwise
|
||||||
# return a default value
|
# return a default value
|
||||||
return self.recurrence_selector == 0 ? self.every_other2 : Time.zone.now.month
|
self.recurrence_selector == 0 ? self.every_other2 : Time.zone.now.month
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_month_of_year2=(moy)
|
def yearly_month_of_year2=(moy)
|
||||||
|
|
@ -267,7 +264,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
def yearly_month_of_year2
|
def yearly_month_of_year2
|
||||||
# if recurrence pattern is every xth day in a month, return month otherwise
|
# if recurrence pattern is every xth day in a month, return month otherwise
|
||||||
# return a default value
|
# return a default value
|
||||||
return self.recurrence_selector == 1 ? self.every_other2 : Time.zone.now.month
|
self.recurrence_selector == 1 ? self.every_other2 : Time.zone.now.month
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_every_x_day=(x)
|
def yearly_every_x_day=(x)
|
||||||
|
|
@ -275,7 +272,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_every_x_day
|
def yearly_every_x_day
|
||||||
return self.every_other1
|
self.every_other1
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_every_xth_day=(x)
|
def yearly_every_xth_day=(x)
|
||||||
|
|
@ -283,7 +280,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_every_xth_day
|
def yearly_every_xth_day
|
||||||
return self.every_other3
|
self.every_other3
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_day_of_week=(dow)
|
def yearly_day_of_week=(dow)
|
||||||
|
|
@ -291,7 +288,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_day_of_week
|
def yearly_day_of_week
|
||||||
return self.every_count
|
self.every_count
|
||||||
end
|
end
|
||||||
|
|
||||||
# target
|
# target
|
||||||
|
|
@ -303,9 +300,9 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
def recurring_target_as_text
|
def recurring_target_as_text
|
||||||
case self.target
|
case self.target
|
||||||
when 'due_date'
|
when 'due_date'
|
||||||
return I18n.t("todos.recurrence.pattern.due")
|
I18n.t("todos.recurrence.pattern.due")
|
||||||
when 'show_from_date'
|
when 'show_from_date'
|
||||||
return I18n.t("todos.recurrence.pattern.show")
|
I18n.t("todos.recurrence.pattern.show")
|
||||||
else
|
else
|
||||||
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
||||||
end
|
end
|
||||||
|
|
@ -320,19 +317,20 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def daily_recurrence_pattern
|
def daily_recurrence_pattern
|
||||||
return I18n.t("todos.recurrence.pattern.on_work_days") if only_work_days
|
if only_work_days
|
||||||
if every_other1 > 1
|
I18n.t("todos.recurrence.pattern.on_work_days")
|
||||||
return I18n.t("todos.recurrence.pattern.every_n", :n => every_other1) + " " + I18n.t("common.days_midsentence.other")
|
elsif every_other1 > 1
|
||||||
|
I18n.t("todos.recurrence.pattern.every_n", :n => every_other1) + " " + I18n.t("common.days_midsentence.other")
|
||||||
else
|
else
|
||||||
return I18n.t("todos.recurrence.pattern.every_day")
|
I18n.t("todos.recurrence.pattern.every_day")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def weekly_recurrence_pattern
|
def weekly_recurrence_pattern
|
||||||
if every_other1 > 1
|
if every_other1 > 1
|
||||||
return I18n.t("todos.recurrence.pattern.every_n", :n => every_other1) + " " + I18n.t("common.weeks")
|
I18n.t("todos.recurrence.pattern.every_n", :n => every_other1) + " " + I18n.t("common.weeks")
|
||||||
else
|
else
|
||||||
return I18n.t('todos.recurrence.pattern.weekly')
|
I18n.t('todos.recurrence.pattern.weekly')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -341,27 +339,27 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
if self.recurrence_selector == 0
|
if self.recurrence_selector == 0
|
||||||
on_day = " #{I18n.t('todos.recurrence.pattern.on_day_n', :n => self.every_other1)}"
|
on_day = " #{I18n.t('todos.recurrence.pattern.on_day_n', :n => self.every_other1)}"
|
||||||
if self.every_other2>1
|
if self.every_other2>1
|
||||||
return I18n.t("todos.recurrence.pattern.every_n", :n => self.every_other2) + " " + I18n.t('common.months') + on_day
|
I18n.t("todos.recurrence.pattern.every_n", :n => self.every_other2) + " " + I18n.t('common.months') + on_day
|
||||||
else
|
else
|
||||||
return I18n.t("todos.recurrence.pattern.every_month") + on_day
|
I18n.t("todos.recurrence.pattern.every_month") + on_day
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if self.every_other2>1
|
n_months = if self.every_other2 > 1
|
||||||
n_months = "#{self.every_other2} #{I18n.t('common.months')}"
|
"#{self.every_other2} #{I18n.t('common.months')}"
|
||||||
else
|
else
|
||||||
n_months = I18n.t('common.month')
|
I18n.t('common.month')
|
||||||
end
|
end
|
||||||
return I18n.t('todos.recurrence.pattern.every_xth_day_of_every_n_months',
|
I18n.t('todos.recurrence.pattern.every_xth_day_of_every_n_months',
|
||||||
:x => self.xth, :day => self.day_of_week, :n_months => n_months)
|
:x => self.xth, :day => self.day_of_week, :n_months => n_months)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def yearly_recurrence_pattern
|
def yearly_recurrence_pattern
|
||||||
if self.recurrence_selector == 0
|
if self.recurrence_selector == 0
|
||||||
return I18n.t("todos.recurrence.pattern.every_year_on",
|
I18n.t("todos.recurrence.pattern.every_year_on",
|
||||||
:date => I18n.l(DateTime.new(Time.zone.now.year, self.every_other2, self.every_other1), :format => :month_day))
|
:date => I18n.l(DateTime.new(Time.zone.now.year, self.every_other2, self.every_other1), :format => :month_day))
|
||||||
else
|
else
|
||||||
return I18n.t("todos.recurrence.pattern.every_year_on",
|
I18n.t("todos.recurrence.pattern.every_year_on",
|
||||||
:date => I18n.t("todos.recurrence.pattern.the_xth_day_of_month", :x => self.xth, :day => self.day_of_week, :month => self.month_of_year))
|
:date => I18n.t("todos.recurrence.pattern.the_xth_day_of_month", :x => self.xth, :day => self.day_of_week, :month => self.month_of_year))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -374,7 +372,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
when 'monthly' then monthly_recurrence_pattern
|
when 'monthly' then monthly_recurrence_pattern
|
||||||
when 'yearly' then yearly_recurrence_pattern
|
when 'yearly' then yearly_recurrence_pattern
|
||||||
else
|
else
|
||||||
return 'unknown recurrence pattern: period unknown'
|
'unknown recurrence pattern: period unknown'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -382,28 +380,28 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
xth_day = [
|
xth_day = [
|
||||||
I18n.t('todos.recurrence.pattern.first'),I18n.t('todos.recurrence.pattern.second'),I18n.t('todos.recurrence.pattern.third'),
|
I18n.t('todos.recurrence.pattern.first'),I18n.t('todos.recurrence.pattern.second'),I18n.t('todos.recurrence.pattern.third'),
|
||||||
I18n.t('todos.recurrence.pattern.fourth'),I18n.t('todos.recurrence.pattern.last')]
|
I18n.t('todos.recurrence.pattern.fourth'),I18n.t('todos.recurrence.pattern.last')]
|
||||||
return self.every_other3.nil? ? '??' : xth_day[self.every_other3-1]
|
self.every_other3.nil? ? '??' : xth_day[self.every_other3-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def day_of_week
|
def day_of_week
|
||||||
return self.every_count.nil? ? '??' : I18n.t('todos.recurrence.pattern.day_names')[self.every_count]
|
self.every_count.nil? ? '??' : I18n.t('todos.recurrence.pattern.day_names')[self.every_count]
|
||||||
end
|
end
|
||||||
|
|
||||||
def month_of_year
|
def month_of_year
|
||||||
return self.every_other2.nil? ? '??' : I18n.t('todos.recurrence.pattern.month_names')[self.every_other2]
|
self.every_other2.nil? ? '??' : I18n.t('todos.recurrence.pattern.month_names')[self.every_other2]
|
||||||
end
|
end
|
||||||
|
|
||||||
def starred?
|
def starred?
|
||||||
return has_tag?(Todo::STARRED_TAG_NAME)
|
has_tag?(Todo::STARRED_TAG_NAME)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_due_date(previous)
|
def get_due_date(previous)
|
||||||
case self.target
|
case self.target
|
||||||
when 'due_date'
|
when 'due_date'
|
||||||
return get_next_date(previous)
|
get_next_date(previous)
|
||||||
when 'show_from_date'
|
when 'show_from_date'
|
||||||
# so leave due date empty
|
# so leave due date empty
|
||||||
return nil
|
nil
|
||||||
else
|
else
|
||||||
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
||||||
end
|
end
|
||||||
|
|
@ -507,7 +505,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
|
|
||||||
# go back to day
|
# go back to day
|
||||||
end
|
end
|
||||||
return Time.zone.local(start.year, start.month, day)
|
Time.zone.local(start.year, start.month, day)
|
||||||
|
|
||||||
when 1 # relative weekday of a month
|
when 1 # relative weekday of a month
|
||||||
the_next = get_xth_day_of_month(self.every_other3, self.every_count, start.month, start.year)
|
the_next = get_xth_day_of_month(self.every_other3, self.every_count, start.month, start.year)
|
||||||
|
|
@ -526,11 +524,10 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
# support 5th day of the month, we need to handle this case
|
# support 5th day of the month, we need to handle this case
|
||||||
the_next = get_xth_day_of_month(self.every_other3, self.every_count, the_next.month, the_next.year)
|
the_next = get_xth_day_of_month(self.every_other3, self.every_count, the_next.month, the_next.year)
|
||||||
end
|
end
|
||||||
return the_next
|
the_next
|
||||||
else
|
else
|
||||||
raise Exception.new, "unknown monthly recurrence selection (#{self.recurrence_selector})"
|
raise Exception.new, "unknown monthly recurrence selection (#{self.recurrence_selector})"
|
||||||
end
|
end
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_xth_day_of_month(x, weekday, month, year)
|
def get_xth_day_of_month(x, weekday, month, year)
|
||||||
|
|
@ -542,7 +539,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
last_day -= 1.day
|
last_day -= 1.day
|
||||||
end
|
end
|
||||||
# convert back to local timezone
|
# convert back to local timezone
|
||||||
return Time.zone.local(last_day.year, last_day.month, last_day.day)
|
Time.zone.local(last_day.year, last_day.month, last_day.day)
|
||||||
else
|
else
|
||||||
# 1-4th -> count upwards last -> count backwards. use UTC to avoid strange
|
# 1-4th -> count upwards last -> count backwards. use UTC to avoid strange
|
||||||
# timezone oddities where last_day -= 1.day seems to shift tz+0100 to
|
# timezone oddities where last_day -= 1.day seems to shift tz+0100 to
|
||||||
|
|
@ -557,7 +554,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
start += 1.day unless n==0
|
start += 1.day unless n==0
|
||||||
end
|
end
|
||||||
# convert back to local timezone
|
# convert back to local timezone
|
||||||
return Time.zone.local(start.year, start.month, start.day)
|
Time.zone.local(start.year, start.month, start.day)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -576,7 +573,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
# if there is a next month n, stay in this year
|
# if there is a next month n, stay in this year
|
||||||
start = Time.zone.local(start.year, month, 1)
|
start = Time.zone.local(start.year, month, 1)
|
||||||
end
|
end
|
||||||
return Time.zone.local(start.year, month, day)
|
Time.zone.local(start.year, month, day)
|
||||||
|
|
||||||
when 1 # relative weekday of a specific month
|
when 1 # relative weekday of a specific month
|
||||||
# if there is no next month n in this year, search in next year
|
# if there is no next month n in this year, search in next year
|
||||||
|
|
@ -589,11 +586,10 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
# year
|
# year
|
||||||
the_next = get_xth_day_of_month(self.every_other3, self.every_count, month, start.year+1) if the_next <= start
|
the_next = get_xth_day_of_month(self.every_other3, self.every_count, month, start.year+1) if the_next <= start
|
||||||
|
|
||||||
return the_next
|
the_next
|
||||||
else
|
else
|
||||||
raise Exception.new, "unknown monthly recurrence selection (#{self.recurrence_selector})"
|
raise Exception.new, "unknown monthly recurrence selection (#{self.recurrence_selector})"
|
||||||
end
|
end
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def continues_recurring?(previous)
|
def continues_recurring?(previous)
|
||||||
|
|
@ -602,9 +598,9 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
|
|
||||||
case self.target
|
case self.target
|
||||||
when 'due_date'
|
when 'due_date'
|
||||||
return get_due_date(previous) <= self.end_date
|
get_due_date(previous) <= self.end_date
|
||||||
when 'show_from_date'
|
when 'show_from_date'
|
||||||
return get_show_from_date(previous) <= self.end_date
|
get_show_from_date(previous) <= self.end_date
|
||||||
else
|
else
|
||||||
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
||||||
end
|
end
|
||||||
|
|
@ -615,7 +611,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_completion!
|
def toggle_completion!
|
||||||
return completed? ? activate! : complete!
|
completed? ? activate! : complete!
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_star!
|
def toggle_star!
|
||||||
|
|
@ -665,7 +661,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
start = self.start_from if ( self.start_from && self.start_from > previous )
|
start = self.start_from if ( self.start_from && self.start_from > previous )
|
||||||
end
|
end
|
||||||
|
|
||||||
return start
|
start
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_first_day_in_this_week(start)
|
def find_first_day_in_this_week(start)
|
||||||
|
|
@ -673,7 +669,7 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
start.wday().upto 6 do |i|
|
start.wday().upto 6 do |i|
|
||||||
return start + (i-start.wday()).days unless self.every_day[i,1] == ' '
|
return start + (i-start.wday()).days unless self.every_day[i,1] == ' '
|
||||||
end
|
end
|
||||||
return -1
|
-1
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue