A "time ago", "time since", "relative date", or "fuzzy date" category for NSDate and iOS, Objective-C, Cocoa Touch, iPhone, iPad

Overview

Carthage compatible

Migration 2014.04.12

NSDate+TimeAgo has merged with DateTools. DateTools is the parent project and Matthew York is the project head.

This project is now part of DateTools. Please visit https://github.com/MatthewYork/DateTools

This repo is here in archive form. New work should be contributed to DateTools.

2016.01.04. To reiterate, all issues and contributions should go to DateTools, there is zero promise anything here will be looked at. Kevin's attention is on Kerf.

Description

This is an iOS, Objective-C, Cocoa Touch, iPhone, iPad category 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.

NSDate+TimeAgo 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)

If you know a language not listed here, please consider submitting a translation. Localization codes by language.

This project is user driven (by people like you). Pull requests close faster than issues (merged or rejected).

Use

  1. Add the files to your project - manually or via Cocoapods (pod 'NSDate+TimeAgo')
  2. Import the header using #import "NSDate+TimeAgo.h"
  3. Call the timeAgo method in the following way:
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:0];
NSString *ago = [date timeAgo];
NSLog(@"Output is: \"%@\"", ago);
2011-11-12 17:19:25.608 Proj[0:0] 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 than dateTimeAgo but more natural

Those three methods can be interchanged as they have the same signature.

Future Directions

Would be nice to

  1. add customization options (e.g., should it report seconds or just "a minute ago")
  2. add string customization
  3. have more localizations
  4. make dateTimeUntilNow more precise: instead of "Last week" use "Last Friday", "Last Monday" etc.
  5. other

License

Released under ISC (similar to 2-clause BSD)

http://wikipedia.org/wiki/ISC_license

Credits

Originally based on code Christopher Pickslay posted to Forrst. Used with permission. http://twitter.com/cpickslay

Ramon Torres began support for internationalization/localization. Added es strings. http://rtorres.me/

Dennis Zhuang added zh_Hans Chinese Simplified strings. http://fnil.net/

Mozart Petter added pt_BR Brazilian Portuguese strings. http://www.mozartpetter.com/

Stéphane Gerardot added fr French strings.

Marco Sanson added it Italian strings. http://marcosanson.tumblr.com/

Almas Adilbek added ru Russian strings. Extended logic to support Russian idioms. http://mixdesign.kz/

Mallox51 added de German strings. https://github.com/Mallox51

Tieme van Veen added nl Dutch strings. http://www.tiemevanveen.nl

Árpád Goretity added hu Hungarian strings. http://apaczai.elte.hu/~13akga/

Anajavi added fi Finnish strings. https://github.com/anajavi

Tonydyb added ja Japanese strings.

Vinhnx added vi Vietnamese strings. http://vinhnx.github.io/

Ronail added zh_Hant Traditional Chinese strings. https://github.com/ronail

SorinAntohi added ro Romanian strings. https://github.com/SorinAntohi

spookd added da Danish strings. https://github.com/spookd

Barrett Jacobsen added cs Czech strings. https://github.com/barrettj

Dmitry Shmidt added nb Norwegian strings. https://github.com/shmidt

Martins Rudens added lv Latvian strings. https://github.com/rudensm

Osman Saral added tr Turkish strings. https://github.com/osrl

analogstyle added ko Korean strings. http://almacreative.net/

Flavio Caetano fixed pt Portuguese strings. http://flaviocaetano.com

kolarski added bg Bulgarian strings. http://github.com/kolarski

Vladimir Kofman added he Hebrew strings. https://github.com/vladimirkofman

Viraf Sarkari added ar Arabic, gre Greek, pl Polish, sv Swedish, and th Thai strings. https://github.com/viraf

Vasyl Skrypii added uk Ukranian strings. https://github.com/medlay

Maggi Trymbill added is Icelandic strings. https://github.com/grundvollur

Erid Bardhaj added sq Albanian strings. https://github.com/eridbardhaj

Joan Biscarri added ca Catalan strings. https://github.com/jbiscarri

Gantulga added mn Mongolian strings. https://github.com/gangstarmn

ali-ehsan added ur Urdu strings. https://github.com/ali-ehsan

Zonily Jame Pesquera added id Bahasa Indonesia strings. https://github.com/kuyazee

Zonily Jame Pesquera added km Khmer strings. https://github.com/kuyazee

Comments
  • I cannot import pod to Swift project

    I cannot import pod to Swift project

    I cannot import pod to Swift project for some reason, when trying to bridge it all I get is a "not found" error. What am I doing wrong? Thanks!!

    opened by moyoteg 8
  • [NSPlaceholderString initWithFormat:locale:arguments:]: nil argument issue

    [NSPlaceholderString initWithFormat:locale:arguments:]: nil argument issue

    Hi there!

    I am trying to use NSDate-TimeAgo for the first time. I've reproduced all steps to set up it. But still have an exception

    [NSPlaceholderString initWithFormat:locale:arguments:]: nil argument

    Debuggingly I conclude that app crashes during execution of this line

    return [self stringFromFormat:@"%%d %@years ago" withValue:minutes];

    How we can solve it?

    opened by pmor13 8
  • Push to Cocoapods Trunk

    Push to Cocoapods Trunk

    hi @kevinlawler is there any reason why the latest version isn't pushed/published? so we can stop doing to get the latest stable version :)

     pod 'NSDate+TimeAgo', :git => 'https://github.com/kevinlawler/NSDate-TimeAgo'
    
    opened by rad182 7
  • Localization is not working for pt

    Localization is not working for pt

    Hi guys,

    I'm using the NSDate-TimeAgo pod and the bundle was added to copy bundle resources on build phases but the translation is not working. Do you know if I need to set anything else? It would be great if you guys can add the how-to on readme file.

    Thanks

    opened by phelipemaia 7
  • Move localization files in bundle

    Move localization files in bundle

    My application is not supporting some of the locales provided by your pod. If you use a bundle instead, that will not affect my project's setting. For example, if I set my device to spanish, the app will not fallback to my default locale because it will found your localization file.

    opened by payotte 6
  • Use of the term

    Use of the term "Yesterday" is incorrect

    Looking at the code, I see that the library returns the string "yesterday" if the difference in time between the given date and now is more than 24 hours ago but less than 2*24 hours ago. Saying "yesterday" is wrong because the given date could be actually the day before yesterday. For instance:

    Date: Monday 11am Now: Wednesday 10am difference : 1day and 23hours => returns "Yesterday", but "Yesterday" here was Tuesday.

    I suggest using "calendar days" instead of just plain days (=24 hours) to calculate the difference. Yesterday will have its true meaning then.

    For an example on how to do this, see the second answer: http://stackoverflow.com/questions/4739483/number-of-days-between-two-nsdates

    By the way, same problem with "last month" / "last year" => months are not always 31 days long, and years are not 365.25 days long.

    opened by chrisben 6
  • string capitalization

    string capitalization

    Hi there,

    Thanks for this piece of code, it's very useful.

    I'd like to get strings in a non-capitalized way. If we take some output: "A moment ago", "30 seconds ago", "5 minutes ago", "Yesterday", "Last Month", "2 Years Ago", and so on

    some have capitalized words, other not.

    I want to create a full sentence out of the output date string like:- "Somebody posted a document 3 hours ago"

    if it's now been one day since the string is now: "Somebody posted a document Yesterday"

    the capital letter 'Y' looks odd in this sentence.

    For now I just lowercase everything that comes out of your library, but it's not very good as in some languages (cf. translations for your library) this transformation might change letters within words. Could you instead output everything in lowercase? If we need capitalization of words/sentences it's then quite easy to do so with NSString.

    Hope I made sense. Cheers.

    opened by chrisben 5
  • Adding new localized strings.

    Adding new localized strings.

    Hi.

    Since I am new to ios development, it might sounds silly but need to ask about it. I'd like to add new localized strings for Korean developers. But I couldn't find solution to add new file to NSDateTimeAgo.bundle. I, of course, need the time-ago method for the current project. Please let me know how to add new locazlied string so that I can make pull request to enrich this fascinating category.

    Thanks.

    opened by colus001 4
  • Issue #15 : added 2 new methods

    Issue #15 : added 2 new methods

    As discussed in issue #15, added two new methods that can be used as drop-in replacement to timeAgo: dateTimeAgo and dateTimeUntilNow. See header file for more details about those methods.

    Also refactored some code in timeAgo to simplify it.

    opened by chrisben 4
  • Time Until

    Time Until

    By changing a few strings the library supports Time Until too.

    E.g. "A minute ago" becomes "In a minute" or "4 days ago" becomes "In 4 days"

    It does mean a few more LocalizedStrings though.

    opened by al-little 4
  • Returns null when used through cocoapods

    Returns null when used through cocoapods

    When you use this category as a pod timeAgo method returns null, when adding the category directly to my main project it works fine.

    I think it might be because the resources are not added to the mainBundle when they are in cocoapod project, so NSLocalizedStringFromTableInBundle is unable to read translated values

    opened by aryaxt 3
  • let dateFormatter: NSDateFormatter = NSDateFormatter()

    let dateFormatter: NSDateFormatter = NSDateFormatter()

    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 }

    Originally posted by @khakha010 in https://github.com/kevinlawler/NSDate-TimeAgo/issues/90#issuecomment-480986436

    opened by khakha010 0
  • How to add New Language ?

    How to add New Language ?

    Hi,

    I am willing to add a new language. I have already cloned the repository. I have seen that language supports are in a bundle named NSDateTimeAgo.bundle. But i have a added a new folder inside the bundle NSDateTimeAgo.bundle. Renamed the folder to bn.lproj, but after that i was unable to add any file inside that newly created directory.

    It would be great if you share that how a language support can be added in the NSDateTimeAgo.bundle.

    Here i have added a gif which demonstrating that, how i attempted this.

    Thanks in Advance.

    opened by ratulSharker 0
  • Slovak strings - rename file

    Slovak strings - rename file

    The Slovak strings file (in DateTools.bundle - sk.lproj) should be named "DateTools.strings" like in any other lproj. Otherwise the Slovak translations aren't working.

    opened by dblazek 0
Owner
Kevin Lawler
Kevin Lawler
A Cocoa NSFormatter subclass to convert dates to and from ISO-8601-formatted strings. Supports calendar, week, and ordinal formats.

ISO 8601: The only date format worth using Obligatory relevant xkcd: How to use this code in your program Add the source files to your project. Parsin

Peter Hosey 601 Sep 4, 2022
NTP library for Swift and Objective-C. Get the true time impervious to device clock changes.

TrueTime for Swift Make sure to check out our counterpart too: TrueTime, an NTP library for Android. NTP client for Swift. Calculate the time "now" im

Instacart 515 Sep 9, 2022
A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

TimeZonePicker A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your

Gligor Kotushevski 124 Jun 6, 2022
A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Lucas Ausberger 1 Jan 8, 2022
Create your own faces for watchOS. Customize the watch hands, layout, colors, and images. Edit faces on your phone and switch them on the watch.

AppleWatchFaces Design your own watch faces for the apple watch. They are not real watch faces, but a watchOS app running on the watch that tells you

Mike Hill 390 Sep 23, 2022
Sudoless Frequency Metric Retrieval for MacOS (Supports Apple Silicon and Intel CPUs and iGPUs)

SFMRM ('sifˌmərˌim) Sudoless Frequency Metric Retrieval for MacOS This project is designed to retrieve active frequency and residency metrics from you

BitesPotatoBacks 14 Aug 19, 2022
SwiftMoment - A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.

SwiftMoment This framework is inspired by Moment.js. Its objectives are the following: Simplify the manipulation and readability of date and interval

Adrian Kosmaczewski 1.6k Sep 9, 2022
Dates and times made easy in iOS

DateTools DateTools was written to streamline date and time handling in iOS. Classes and concepts from other languages served as an inspiration for Da

Matthew York 7.2k Sep 15, 2022
Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS.

Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS. Installation Timekee

Andreas Pfurtscheller 1 Oct 18, 2021
Population Clock is an iOS tool for learning about geography and demographics.

PopulationClock Population Clock is an iOS tool for learning about geography and demographics. Download app on iTunes The project uses the most recent

Netfilter 12 Feb 8, 2022
Date and time manager for iOS/OSX written in Swift

Tempo was designed to work both in OSX and in iOS (7.0+). Work with the time or dates can be cumbersome, iOS development. Tempo allows you to deal easly with date and time. Basics manipulations are already implemented in Tempo.

Remi ROBERT 153 Jun 3, 2021
Infini-iOS - an InfiniTime Companion App for iOS

Infini-iOS - an InfiniTime Companion App for iOS This is a proof-of-concept, barely-functional iOS application to interact with your PineTime running

null 130 Aug 29, 2022
Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

Dave DeLong 2k Sep 20, 2022
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!

Datez ?? Breeze through Date, DateComponents, and TimeInterval Highlights Two Custom Structs Only (value types FTW!): DateView: An Date associated wit

Kitz 262 Sep 24, 2022
SwiftDate 🐔 Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.

Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift. What's This? SwiftDate is the definitive toolchain to ma

Daniele Margutti 7k Sep 20, 2022
A Swift micro library for generating Sunrise and Sunset times.

Solar A Swift helper for generating Sunrise and Sunset times. Solar performs its calculations locally using an algorithm from the United States Naval

Chris Howell 486 Sep 11, 2022
Custom Time Picker ViewController with Selection of start and end times in Swift 🔶

LFTimePicker Custom Time Picker ViewController with Selection of start and end times in Swift ?? . Based on Adey Salyard's design @ Dribbble One to tw

Awesome Labs 64 May 5, 2022
SwiftUI library to display a clock. You can move the arms to change the time, change the style of the clock and customise some configurations.

SwiftClockUI Clock UI for SwiftUI This library has been tested ✅ ?? macOS Catalina 10.15.3 ✅ ?? macOS Big Sur 11.6 ✅ ?? iOS 13 ✅ ?? iOS 14 ✅ ?? iOS 15

Renaud Jenny 232 Sep 18, 2022
A customizable date picker for watchOS and SwiftUI.

Watch Date Picker A customizable date picker for watchOS and SwiftUI. Installation .package(url: "https://github.com/freyaariel/watch-date-picker.git"

Freya Ariel 20 Sep 14, 2022