Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
update for GM
Browse files Browse the repository at this point in the history
  • Loading branch information
kgn committed Sep 11, 2016
1 parent 6f1041c commit 6ff9080
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Framework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.6</string>
<string>1.0.7</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
40 changes: 20 additions & 20 deletions NSDate+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ extension Date {
public var timeAgoSimple: String {
let components = self.dateComponents()

if components.year > 0 {
if components.year! > 0 {
return self.string(fromFormat: "%%d%@yr", withValue: components.year!)
}

if components.month > 0 {
if components.month! > 0 {
return self.string(fromFormat: "%%d%@mo", withValue: components.month!)
}

// TODO: localize for other calanders
if components.day >= 7 {
if components.day! >= 7 {
let value = components.day!/7
return self.string(fromFormat: "%%d%@w", withValue: value)
}

if components.day > 0 {
if components.day! > 0 {
return self.string(fromFormat: "%%d%@d", withValue: components.day!)
}

if components.hour > 0 {
if components.hour! > 0 {
return self.string(fromFormat: "%%d%@h", withValue: components.hour!)
}

if components.minute > 0 {
if components.minute! > 0 {
return self.string(fromFormat: "%%d%@m", withValue: components.minute!)
}

if components.second > 0 {
if components.second! > 0 {
return self.string(fromFormat: "%%d%@s", withValue: components.second! )
}

Expand All @@ -76,24 +76,24 @@ extension Date {
public var timeAgo: String {
let components = self.dateComponents()

if components.year > 0 {
if components.year < 2 {
if components.year! > 0 {
if components.year! < 2 {
return NSDateTimeAgoLocalizedStrings("Last year")
} else {
return self.string(fromFormat: "%%d %@years ago", withValue: components.year!)
}
}

if components.month > 0 {
if components.month < 2 {
if components.month! > 0 {
if components.month! < 2 {
return NSDateTimeAgoLocalizedStrings("Last month")
} else {
return self.string(fromFormat: "%%d %@months ago", withValue: components.month!)
}
}

// TODO: localize for other calanders
if components.day >= 7 {
if components.day! >= 7 {
let week = components.day!/7
if week < 2 {
return NSDateTimeAgoLocalizedStrings("Last week")
Expand All @@ -102,32 +102,32 @@ extension Date {
}
}

if components.day > 0 {
if components.day < 2 {
if components.day! > 0 {
if components.day! < 2 {
return NSDateTimeAgoLocalizedStrings("Yesterday")
} else {
return self.string(fromFormat: "%%d %@days ago", withValue: components.day!)
}
}

if components.hour > 0 {
if components.hour < 2 {
if components.hour! > 0 {
if components.hour! < 2 {
return NSDateTimeAgoLocalizedStrings("An hour ago")
} else {
return self.string(fromFormat: "%%d %@hours ago", withValue: components.hour!)
}
}

if components.minute > 0 {
if components.minute < 2 {
if components.minute! > 0 {
if components.minute! < 2 {
return NSDateTimeAgoLocalizedStrings("A minute ago")
} else {
return self.string(fromFormat: "%%d %@minutes ago", withValue: components.minute!)
}
}

if components.second > 0 {
if components.second < 5 {
if components.second! > 0 {
if components.second! < 5 {
return NSDateTimeAgoLocalizedStrings("Just now")
} else {
return self.string(fromFormat: "%%d %@seconds ago", withValue: components.second!)
Expand Down
4 changes: 2 additions & 2 deletions Tests/NSDateTimeAgoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class NSDateTimeAgoTests: XCTestCase {
super.tearDown()
}

func dateForComponents(block: ( components: inout DateComponents) -> Void) -> Date? {
func dateForComponents(block: (_ components: inout DateComponents) -> Void) -> Date? {
let calander = Calendar.current
var components = DateComponents()
block(components: &components)
block(&components)
return calander.date(byAdding: components, to: Date())
}

Expand Down

0 comments on commit 6ff9080

Please sign in to comment.