app/models/polymorphic/task.rb in fat_free_crm-0.13.2 vs app/models/polymorphic/task.rb in fat_free_crm-0.13.3

- old
+ new

@@ -142,35 +142,32 @@ # Check whether the due date has specific time ignoring 23:59:59 timestamp # set by Time.now.end_of_week. #---------------------------------------------------------------------------- def at_specific_time? - self.due_at && - (self.due_at.hour != 0 || self.due_at.min != 0 || self.due_at.sec != 0) && - (self.due_at.hour != 23 && self.due_at.min != 59 && self.due_at.sec != 59) + self.due_at.present? && !due_end_of_day? && !due_beginning_of_day? end # Convert specific due_date to "due_today", "due_tomorrow", etc. bucket name. #---------------------------------------------------------------------------- def computed_bucket return self.bucket if self.bucket != "specific_time" case - when self.due_at < Time.zone.now.midnight + when overdue? "overdue" - when self.due_at >= Time.zone.now.midnight && self.due_at < Time.zone.now.midnight.tomorrow + when due_today? "due_today" - when self.due_at >= Time.zone.now.midnight.tomorrow && self.due_at < Time.zone.now.midnight.tomorrow + 1.day + when due_tomorrow? "due_tomorrow" - when self.due_at >= (Time.zone.now.midnight.tomorrow + 1.day) && self.due_at < Time.zone.now.next_week + when due_this_week? && !due_today? && !due_tomorrow? "due_this_week" - when self.due_at >= Time.zone.now.next_week && self.due_at < (Time.zone.now.next_week.end_of_week + 1.day) + when due_next_week? "due_next_week" else "due_later" end end - # Returns list of tasks grouping them by due date as required by tasks/index. #---------------------------------------------------------------------------- def self.find_all_grouped(user, view) return {} unless ALLOWED_VIEWS.include?(view) settings = (view == "completed" ? Setting.task_completed : Setting.task_bucket) @@ -223,9 +220,44 @@ when "specific_time" self.calendar ? parse_calendar_date : nil else # due_later or due_asap nil end + end + + #---------------------------------------------------------------------------- + def due_end_of_day? + self.due_at.present? && (self.due_at == self.due_at.end_of_day) + end + + #---------------------------------------------------------------------------- + def due_beginning_of_day? + self.due_at.present? && (self.due_at == self.due_at.beginning_of_day) + end + + #---------------------------------------------------------------------------- + def overdue? + self.due_at < Time.zone.now.midnight + end + + #---------------------------------------------------------------------------- + def due_today? + self.due_at.between?(Time.zone.now.midnight, Time.zone.now.end_of_day) + end + + #---------------------------------------------------------------------------- + def due_tomorrow? + self.due_at.between?(Time.zone.now.midnight.tomorrow, Time.zone.now.tomorrow.end_of_day) + end + + #---------------------------------------------------------------------------- + def due_this_week? + self.due_at.between?(Time.zone.now.beginning_of_week, Time.zone.now.end_of_week) + end + + #---------------------------------------------------------------------------- + def due_next_week? + self.due_at.between?(Time.zone.now.next_week, Time.zone.now.next_week.end_of_week) end #---------------------------------------------------------------------------- def notify_assignee if self.assigned_to