Created
December 7, 2015 09:19
-
-
Save rajputvai/9889b96e1e939c10c476 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
| module ActiveSupport | |
| class TimeZone | |
| def parse(str, now=now) | |
| parts = Date._parse(str, false) | |
| return if parts.empty? | |
| if parts[:hour] > 23 | |
| return str | |
| end | |
| time = Time.new( | |
| parts.fetch(:year, now.year), | |
| parts.fetch(:mon, now.month), | |
| parts.fetch(:mday, now.day), | |
| parts.fetch(:hour, 0), | |
| parts.fetch(:min, 0), | |
| parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), | |
| parts.fetch(:offset, 0) | |
| ) | |
| if parts[:offset] | |
| TimeWithZone.new(time.utc, self) | |
| else | |
| TimeWithZone.new(nil, self, time) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment