kevinlawler / NSDate-TimeAgo

A "time ago", "time since", "relative date", or "fuzzy date" category for NSDate and iOS, Objective-C, Cocoa Touch, iPhone, iPad
ISC License
1.75k stars 322 forks source link

Swift timeAgo returns empty string. #90

Open jacks205 opened 9 years ago

jacks205 commented 9 years ago

I am calling timeAgo from NSDate and it returns an empty string.

if let validDate = lastUpdated{
    let dateText = validDate.timeAgo
    self.updatedLabel.text = dateText
    print(validDate.timeAgo)
}

I tried to debug the Swift extension and found it gets an empty string there.

screen shot 2015-09-28 at 3 16 46 pm

This is how I am creating my NSDate if it is important:

let dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSX"
if let date = dateFormatter.dateFromString(dateString) {
    // I get valid a NSDate object
}
victtavares commented 9 years ago

Hi jack,

Did you import the .bundle folder into your project? It was also returning an empty string for me before I do it.

jacks205 commented 9 years ago

No I just added the pod. That could be the issue.

slangley commented 9 years ago

Under Cocoapods and Swift you are likely using use_frameworks. The currently released version on Cocoapods uses the main bundle as the location for the resource bundle, which will be broken when frameworks are used.

This issue seems to be fixed in the most recent master branch, so as a workaround until it's released, try a git repo line in your Podfile

shafqat-muneer commented 8 years ago

@jacks205 is empty string issue resolved? As i am still getting it. Thanks

jacks205 commented 8 years ago

@shafqat-muneer I'm not sure about the state of the pod, but I opted using this fuction someone put into a gist.

khakha010 commented 5 years ago

let dateFormatter: NSDateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC") dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSX" if let date = dateFormatter.dateFromString(dateString) { // I get valid a NSDate object }