Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No love for cocoa relative formatting #97

Closed
redent opened this issue Dec 7, 2015 · 1 comment
Closed

No love for cocoa relative formatting #97

redent opened this issue Dec 7, 2015 · 1 comment

Comments

@redent
Copy link

redent commented Dec 7, 2015

In Swift 1.2 we had a parameter in toString method to enable doesRelativeDateFormatting flag in NSDateFormatter. That parameter is now gone and there's only one method to enable it:

public func toRelativeCocoaString() -> String? {
    let formatter = NSDateFormatter()
    formatter.locale = region.locale
    formatter.calendar = region.calendar
    formatter.timeZone = region.timeZone
    formatter.dateStyle = .MediumStyle
    formatter.doesRelativeDateFormatting = true
    return formatter.stringFromDate(UTCDate)
}

However this method forces dateStyle and timeStyle and create a new NSDateFormatter on each call. In addition. NSDateFormatter.cachedFormatter() is declared internal, so no other DateInRegion extensions can use it.

@malcommac
Copy link
Owner

Fixed in d85c3bb
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants