RIOFuzzyTime is a project mainly written in Objective-C, based on the Apache-2.0 license.
Calculates the time since/to a given NSDate. E.g. About 30 minutes ago, About a day ago or About 2 months from now.
Calculates the time since/to a given NSDate. E.g. About 30 minutes ago
, About a day ago
or About 2 months from now
.
The goal for this library is to support multiple languages. As of today it only supports English and Norwegian. If you want to contribute to the translations or the code, please feel free to contact me.
These steps are targeted for Xcode 4, but they may also work for earlier versions.
git init
(Skip this step if you opted for: Create local git repository for this project)git submodule add git://github.com/skohorn/RIOFuzzyTime.git Components/RIOFuzzyTime
git submodule update --init --recursive
-all_load
to the Other Linker Flags-settingComponents
and enable Recursive in the User Header Search Paths-settingIf you want a better explanation of each step, please check out The state of iOS Open Source - and what to do about it! from the awesome Jayway Team Blog.
Remember to import RIOFuzzyTime.h before using any of these methods.
NSDate *now = [NSDate date];
NSLog(@"Fuzzy time: %@", [now fuzzyTimeString]);
Outputs:
Fuzzy time: Just now
NSLog(@"Fuzzy time: %@", [RIOFuzzyTime fuzzyTimeStringWithTimeInterval:-1234.0]);
Outputs:
Fuzzy time: About 20 minutes ago
Time | Singular form | Limit | Scale |
---|---|---|---|
0-59 seconds | Just now | 60 | 1 |
1-59 minutes | About a minute ago | 60*60 | 60 |
1-23 hours | About an hour ago | 60*60*24 | 60*60 |
1-6 days | About a day ago | 60*60*24*7 | 60*60*24 |
1-4 weeks | About a week ago | 60*60*24*365,25/12 | 60*60*24*7 |
1-11 months | About a month ago | 60*60*24*365,25 | 60*60*24*365,25/12 |
1-99 years | About a year ago | 60*60*24*365,25*100 | 60*60*24*365,25 |
It is important that the limit of one category is higher than or equal to the scale of the next category. For example: In 1 month there are approximately 30.4375 days (2629800 seconds). In 4 weeks there are only 28 days (2419200 seconds). To accommodate this I have set the limit for the week category to about 4.35 weeks == 1 month (2629800 seconds). Otherwise, an input of 29 days would have returned 0 months.
This library is licensed under the Apache 2.0 license. See LICENSE for more details.