Created
November 22, 2011 22:36
-
-
Save epall/1387274 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| overwrite_accessor :date= do |date| | |
| # We want to end up with a Time object with one-day resolution. | |
| # This is the cleanest, most-readable, faster-than-using-Date | |
| # way to do it. | |
| case date | |
| when String then | |
| @date = if /\A(\d{4})-(\d{2})-(\d{2})\Z/ =~ date then | |
| Time.local($1.to_i, $2.to_i, $3.to_i) | |
| else | |
| require 'time' | |
| Time.parse date | |
| end | |
| when Time then | |
| @date = Time.local(date.year, date.month, date.day) | |
| when Date then | |
| @date = Time.local(date.year, date.month, date.day) | |
| else | |
| @date = TODAY | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment