1

Is there a way to get time ago in words in rubymotion such that when I have a date I can get the 2 days ago 5 days ago etc. from the current date? like its possible to do in rails.

The date format I am getting from mysql database is TIMESTAMP and the returned data is like this:

2014-05-17 22:59:07
2011-05-17 22:56:02

Question

How can I convert the above string to NSDate and then compare it to today's date and get "X days ago" etc...

birdy
  • 9,286
  • 24
  • 107
  • 171

2 Answers2

0

You can use BubbleWrap to convert your timestamp into a NSDate instance.

The Time Ruby class was added a class level method to convert a iso8601 formatted string into a Time instance.

Time.iso8601("2012-05-31T19:41:33Z")
=> 2012-05-31 21:41:33 +0200

Then you can do as you wish with it, sugar cube has some nice extensions for NSDate.

More answers here...

Community
  • 1
  • 1
ahmet
  • 4,955
  • 11
  • 39
  • 64
0

Looks like there is a CocoaPod that can handle that: https://github.com/MatthewYork/DateTools

Add pod 'DateTools' to your Rakefile. Run rake pod:install and now you can convert your date objects like this:

my_date = NSDate.dateWithNaturalLanguageString('2015-08-18T23:58:40.000+00:00')
my_date.timeAgoSinceNow
Andrew
  • 227,796
  • 193
  • 515
  • 708