Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/yapper/extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(string) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/yapper/extensions.rb', line 24

def self.parse(string)
  return nil if string.nil?

  unless time = NSDate.dateWithString(string)
    # XXX Try iso8601 date
    time = NSDate.dateWithString(string.gsub('T',' ').gsub('Z', ' +0000').gsub(/([-+]\d{2}:\d{2})/,' \1'))
  end
  time
end

Instance Method Details

#to_iso8601Object



34
35
36
37
38
39
40
41
# File 'lib/yapper/extensions.rb', line 34

def to_iso8601
  dateFormatter = NSDateFormatter.alloc.init
  locale = NSLocale.alloc.initWithLocaleIdentifier("en_US_POSIX")
  dateFormatter.setLocale(locale)
  dateFormatter.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")

  dateFormatter.stringFromDate(self)
end