Skip to content

Instantly share code, notes, and snippets.

@pccl
Created September 16, 2009 08:37
Show Gist options
  • Save pccl/187933 to your computer and use it in GitHub Desktop.
Save pccl/187933 to your computer and use it in GitHub Desktop.
# Tasks can fall through the gaps when matching on '='
# e.g. for a task where due_at = 2009-09-16 23:00:00, and where Time.now = 2009-09-16,
# it would not match due_today or due_tomorrow, hence would not appear in Fat Free.
named_scope :due_today, lambda { { :conditions => [ "due_at = ?", Time.zone.now.midnight.utc ], :order => "id DESC" } }
named_scope :due_tomorrow, lambda { { :conditions => [ "due_at = ?", Time.zone.now.midnight.tomorrow.utc ], :order => "id DESC" } }
# By specifying a range of dates, tasks would always match with one of the bucket dates.
named_scope :due_today, lambda {
{ :conditions => [ "due_at >= ? AND due_at < ?", Time.zone.now.midnight.utc, Time.zone.now.midnight.tomorrow.utc ], :order => "id DESC" }
}
named_scope :due_tomorrow, lambda {
{ :conditions => [ "due_at >= ? AND due_at < ?", Time.zone.now.midnight.tomorrow.utc, Time.zone.now.midnight.tomorrow.utc + 1.day ], :order => "id DESC" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment