Skip to content

Instantly share code, notes, and snippets.

@johnkoht
Last active December 22, 2015 22:49
Show Gist options
  • Save johnkoht/6542488 to your computer and use it in GitHub Desktop.
Save johnkoht/6542488 to your computer and use it in GitHub Desktop.
Adds ActiveSupport convenience method for Date and Time objects for identifying if a date is within this year or not.
# Patch for Date and Time that adds a conveneince method for identifying
# if a date is within this year
# config/initializers/date_time.rb
class Date
def this_year?
self.year == ::Date.current.year
end
end
class Time
def this_year?
self.year == ::Date.current.year
end
end
class DateTime
def this_year?
self.year == ::Date.current.year
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment