diff --git a/DateToolsSwift/DateTools/Date+TimeAgo.swift b/DateToolsSwift/DateTools/Date+TimeAgo.swift index 527d02de..80972bf6 100644 --- a/DateToolsSwift/DateTools/Date+TimeAgo.swift +++ b/DateToolsSwift/DateTools/Date+TimeAgo.swift @@ -68,8 +68,8 @@ public extension Date { let components = calendar.dateComponents(unitFlags, from: earliest, to: latest) - let yesterday = date.subtract(1.days) - let isYesterday = yesterday.day == self.day + let yesterday = latest.subtract(1.days) + let isYesterday = yesterday.day == earliest.day //Not Yet Implemented/Optional //The following strings are present in the translation files but lack logic as of 2014.04.05 @@ -112,12 +112,17 @@ public extension Date { else if (components.day! >= 2) { return self.logicalLocalizedStringFromFormat(format: "%%d %@days ago", value: components.day!) } - else if (isYesterday) { - if (numericDates) { - return DateToolsLocalizedStrings("1 day ago"); + else if (components.day! >= 1) { + if (isYesterday) { + if (numericDates) { + return DateToolsLocalizedStrings("1 day ago"); + } + + return DateToolsLocalizedStrings("Yesterday"); + } + else { + return DateToolsLocalizedStrings("1 day ago") } - - return DateToolsLocalizedStrings("Yesterday"); } else if (components.hour! >= 2) { return self.logicalLocalizedStringFromFormat(format: "%%d %@hours ago", value: components.hour!) @@ -200,9 +205,9 @@ public extension Date { private func logicalLocalizedStringFromFormat(format: String, value: Int) -> String{ #if os(Linux) - let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value)) as! CVarArg) // this may not work, unclear!! + let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value)) as! CVarArg) // this may not work, unclear!! #else - let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value))) + let localeFormat = String.init(format: format, getLocaleFormatUnderscoresWithValue(Double(value))) #endif return String.init(format: DateToolsLocalizedStrings(localeFormat), value) @@ -241,9 +246,9 @@ public extension Date { #if os(Linux) // NSLocalizedString() is not available yet, see: https://github.com/apple/swift-corelibs-foundation/blob/16f83ddcd311b768e30a93637af161676b0a5f2f/Foundation/NSData.swift // However, a seemingly-equivalent method from NSBundle is: https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSBundle.swift - return Bundle.main.localizedString(forKey: string, value: "", table: "DateTools") + return Bundle.main.localizedString(forKey: string, value: "", table: "DateTools") #else - return NSLocalizedString(string, tableName: "DateTools", bundle: Bundle.dateToolsBundle(), value: "", comment: "") + return NSLocalizedString(string, tableName: "DateTools", bundle: Bundle.dateToolsBundle(), value: "", comment: "") #endif }