forked from https://github.com/kevinlawler/NSDate-TimeAgo
This is a Swift class extension for NSDate. It gives NSDate the ability to report times like "A moment ago", "30 seconds ago", "5 minutes ago", "Yesterday", "Last month", "2 years ago", and so on.
This functionality has variously been referred to as a "time ago", "time since", "relative date", or "fuzzy date" feature.
NSDateTimeAgo currently supports the following languages:
- en (English)
- ee (Estonian)
- es (Spanish)
- zh_Hans (Chinese Simplified)
- zh_Hant (Chinese Traditional)
- pt (Portuguese)
- fr (French)
- it (Italian)
- ru (Russian)
- de (German)
- nl (Dutch)
- hu (Hungarian)
- fi (Finnish)
- ja (Japanese)
- vi (Vietnamese)
- ro (Romanian)
- da (Danish)
- cs (Czech)
- nb (Norwegian)
- lv (Latvian)
- tr (Turkish)
- ko (Korean)
- bg (Bulgarian)
- he (Hebrew)
- ar (Arabic)
- gre (Greek)
- pl (Polish)
- sv (Swedish)
- th (Thai)
- uk (Ukrainian)
- is (Icelandic)
- sq (Albanian)
- sk (Slovak)
- ms (Malay)
- km (Cambodian)
- id (Bahasa-Indonesia)
- mn (Mongolian)
- ur (Urdu)
Addthe swift package to your project- Import the package
import NSDateTimeAgo - Call the
timeAgomethod in the following way:
let date = NSDate()
let ago = date.timeAgo
print("Output is: \(ago)")
Output is: "41 years ago"
2 other methods are available:
dateTimeAgo: returns times with only strings of the type: "{value} {unit} ago"dateTimeUntilNow: returns only "yesterday" / "this morning" / "last week" / "this month" -- less precise thandateTimeAgobut more natural
Those three methods can be interchanged as they have the same signature.
Would be nice to
- add customization options (e.g., should it report seconds or just "a minute ago")
- add string customization
- have more localizations
- make
dateTimeUntilNowmore precise: instead of "Last week" use "Last Friday", "Last Monday" etc. - other
Released under ISC (similar to 2-clause BSD)