lib/cocoa/sugarcube-nsdate/date_parser.rb in sugarcube-3.4.1 vs lib/cocoa/sugarcube-nsdate/date_parser.rb in sugarcube-3.4.2
- old
+ new
@@ -6,15 +6,14 @@
#
# SugarCube::DateParser.parse_date "There is a date in here tomorrow at 9:00 AM"
#
# => 2013-02-20 09:00:00 -0800
def parse_date(date_string)
- result = sugarcube_detect(date_string).first
- if result
+ if result = iso8601(date_string)
+ return result
+ elsif result = sugarcube_detect(date_string).first
return result.date
- else
- return iso8601(date_string)
end
end
# Parse time zone from date
#
@@ -43,9 +42,16 @@
def match(date_string)
sugarcube_detect(date_string)
end
def iso8601(date_string)
+ if defined? NSISO8601DateFormatter
+ formatter = NSISO8601DateFormatter.alloc.init
+ formatter.timeZone = NSTimeZone.timeZoneWithAbbreviation "UTC"
+ date = formatter.dateFromString date_string
+ return date if date
+ end
+
@@sugarcube_iso_detectors ||= [
"yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss.S",
"yyyy-MM-dd'T'HH:mm:ss.SZ",