motion/core/time.rb in bubble-wrap-0.4.0 vs motion/core/time.rb in bubble-wrap-1.0.0.pre

- old
+ new

@@ -1,8 +1,19 @@ class Time + def self.iso8601(time) - formatter = NSDateFormatter.alloc.init - formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" - formatter.timeZone = NSTimeZone.timeZoneWithAbbreviation "UTC" - formatter.dateFromString time + cached_date_formatter("yyyy-MM-dd'T'HH:mm:ss'Z'"). + dateFromString(time) end + + private + + def self.cached_date_formatter(dateFormat) + Thread.current[:date_formatters] ||= {} + Thread.current[:date_formatters][dateFormat] ||= + NSDateFormatter.alloc.init.tap do |formatter| + formatter.dateFormat = dateFormat + formatter.timeZone = NSTimeZone.timeZoneWithAbbreviation "UTC" + end + end + end