Giter Club home page Giter Club logo

datetools's People

Contributors

albinekcom avatar bendihossan avatar danthorpe avatar dezinezync avatar divergio avatar edpelesh avatar fahlout avatar faizmokh avatar greysonwright avatar hlfcoding avatar ikhsan avatar itsmebhavin avatar jlubeck avatar kevinlawler avatar m1kachu avatar matthewyork avatar mjanda avatar morizotter avatar mortonfox avatar ndbroadbent avatar pikdays avatar piotrzbyszynski avatar raphaelcruzeiro avatar readmecritic avatar rmannion avatar romainbiard avatar sendoa avatar tbaranes avatar tiberius33 avatar zhukn1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

datetools's Issues

Start of week

Is there an easy way to find the start of the week? Or is there some detailed documentation available somewhere?

If there is no easy way to get the start of the week this might be a nice-to-have feature.

Thanks in advance

Thread Safety

It has been brought to my attention that NSDateFormatter and NSCalendar are both thread-unsafe. We need to introduce a locking system to ensure that no NSCalendar or NSDateFormatter instances are mutated on different threads at the same time.

Comparing difference in "calendar days"

If I'm not wrong, the date comparison methods requires 24 hours for a day to be counted as 1 day. How can I get the difference between days as calendar days?

As quoted from the comments of this SO answer:

If fromDateTime = Feb 1st 11:00pm and toDateTime = Feb 2nd 01:00am the result should be 1 (even though it's only 2 hours, but it's another date).

That SO answer also returns the difference of days in "calendar days".

I was using that SO answer initially and I realised the abnormality after switching to DateTools. Is there a way that I can achieve that "calendar days difference" result with DateTools?

dateWithString:format: returning nil

If I try and create a date from a format string every so often it will return nil, whilst using dateWithYear:month:day: with the same parameters will return the correct value.

Unsure if this is a bug with the library, looking at the method it seems like it might be something I am doing wrong, however I would like to know what I may be doing wrong.

NSNumber *year = @(2015);
NSNumber *month = @(10);

NSString *dateString = [NSString stringWithFormat:@"01/%@/%@", month, year];
NSDate *key = [NSDate dateWithString:dateString formatString:@"dd/MM/yyyy"]; // Sometimes nil
NSDate *key2 = [NSDate dateWithYear:year month:month day:1]; // Always successful

Compiler error "unknown type name NSInteger"

Recent version of XCode does not generate the always-included .pch file so each header and implementation file should explicitly declare the full list of the necessary include files.

DTConstants.h refers to NSInteger but does not include any system framework (e.g. #import <Foundation/Foundation.h>). If DateTools.h is included to the user code before any other includes than this generates a compile time error as follows:

In file included from 
DateTools/DateTools.h:23:
DateTools/DTConstants.h:24:14: error: unknown type name 'NSInteger'
static const NSInteger SECONDS_IN_MONTH_28 = 2419200;
             ^

No translations for localized strings in DTError

There doesn't seem to be any translations included for the localized strings used in DTError.m:
NSLocalizedString(@"Operation was unsuccessful.", nil)
NSLocalizedString(@"Please try again by inserting a DTTimePeriod object.", nil)

This throws "Missing key" project warnings on build.

Property List error: Unexpected character at line 1 (JSON error)

I am trying to implement DateTools into a rubymotion project that I am working on. I added DateTools to the project last night and installed it and everything was great. This morning I added another cocoapod, installed that, and now I can't compile my app because I'm getting the following error. I deleted DateTools from the project and I still get the same error on compile.

2015-10-07 09:00:06.403 plutil[25244:5881404] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 5. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug.
vendor/Pods/Resources/DateTools.bundle/hr.lproj/DateTools.strings: Property List error: Unexpected character / at line 1 / JSON error: JSON text did not start with array or object and option to allow fragments not set.
rake aborted!

Any thoughts? Am I just missing something silly because I'm a beginner? This just started happening all of a sudden and I can't figure out any way to trouble shoot it.

UPDATE!

I was able to get things back to normal by running rake clean which wiped out whatever cocoapod cache was lying around, but I still had DateTools uninstalled. I thought maybe it just got messed up in the initial install or something? So, I reinstalled it and got the same error. Had to uninstall and clean and now I'm working but no DateTools. :(

timeAgo() 1000k+ times is slightly slow due to [NSLocale preferredLanguages].

Calling timeAgo multiple times (over 1000) in a row is a bit slow because of a repeated call to [NSLocale preferredLanguages].

The method getLocaleFormatUnderscoresWithValue: calls the preferred languages method.

Is there any way we could cache that array instead of calling preferredLanguages.objectAtIndex[0] every time timeAgo() is called?

Thanks!

More detailed localization description needed to be added to the readme file

I've added DateTools to my app using cocoapods. My app supports only English language and there are no more localizations specified in project info. When I use Time Ago on a phone (or simulator) with English localization, I see exactly what I expect to see. But when launched on phone with Russian language selected I see underscores in time. Something like "2 _days ago". And I have no idea how to remove them. Please someone tell me. And I think it should be also added to readme file.

Swift Support

I am about to do a full port of DateTools to Swift. Before getting started, I want to open this thread for suggestions on ways to utilize the Swift language in new and unique ways to make DateTools even easier to use.

timeAgo cause app crash

for DateTools, I do think either clearly specify that even if cocoapods is used, we still need to drag the bundle over, or have this automatically solved...

[Feature request] Morre details for shortTimeAgoSinceDate

Actually, shortTimeAgoSinceDate of 710 days ago and 365 days ago have both the same output 1y (ago). It is possible to add more detail in the output ? Ex:

  • 1y11m (ago)
  • 11m3w (ago)
  • 3w6d (ago)
  • 6d23h (ago)
  • 23h59m (ago)
  • 59m59s (ago)

Thank you.

Crash when using with cocoapods

Crashes on the following line

NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DateTools.bundle"]], nil)

The new cocoapods now uses swift modules and embedded frameworks, so DateTools.bundle is no longer at its old location, thus causing a crash due to nil being returned.

Excellent library, butโ€ฆ

is there any chance of getting a mention of / nod to
Pretty Timestamp, which a large chunk of the time ago methods are based on?

As @MatthewYork has submitted pull requests to me before, it's quite clear where the influence came from and that the majority of it has actually been copy-pasted.

Update cocoapod for latest code

Some changes that remove warnings from the code were merged in (Thanks!!! :)...now could we also rev the cocoapod version to pick up those changes?

Thanks in advance

Any plan to support "Time Later" beside "Time Ago"?

I'm developing a Timer app and I need display something like "It will run in 5 minutes".
In android I can use DateUtils.getRelativeTimeSpanString and it works fine. But in iOS I cannot find any solution.
Actually I can write my own codes, but the most difficulty is localization.
"Time Ago" is perfect for many(maybe most) projects, but it's not enough for me...
Btw I can contribute Chinese localization.

Create dates in a certain time zone

I'm looking for a way to create a date in a specific time zone (not necessarily the current time zone). What I found was this method:

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;

However, this method (and the one including seconds etc.) uses the implicit calendar, for which there's no way to set a certain time zone from the outside. Only the methods requiring a date string (starting mostly with formattedDateWithFormat:) allow you to specify a time zone that will be used by the date formatter for getting the date. It would be very helpful to have something like this:

+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day timeZone:(NSTimeZone *)timeZone;

Are there any plans on supporting this or am I overlooking something?

timeAgoSinceDate returns "yesterday" when it should be "day before yesterday"

I found that the timeAgoSinceDate method does not return the correct day. For [yesterday22h timeAgoSinceDate:tomorrow1h] I expected something like "the day before yesterday", but instead "yesterday" was returned, which is wrong.

I use German localization, so the actual example looks like this:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDate* yesterday2h = [dateFormat dateFromString:@"2000-01-31 02:00:00"];
NSDate* tomorrow1h = [dateFormat dateFromString:@"2000-02-02 01:00:00"];

XCTAssertNotEqualObjects([yesterday2h timeAgoSinceDate:tomorrow1h], @"Gestern");

I use DateTools 1.4.3.

Crash on shortTimeAgoSinceNow

I'm sure it not really a bug - but something with my code but I have no more leads...

This crash happens on the field - so all I have is a crash log.

I'm passing an NSDate which is taken from passing a "seconds since epoch" through
"dateWithTimeIntervalSince1970"

The crash:

Terminating app due to an uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithFormat:locale:arguments:]: nil argument'

0   CoreFoundation                  0x2f954f83 __exceptionPreprocess + 131
1   libobjc.A.dylib                 0x3a105ccf objc_exception_throw + 39
2   CoreFoundation                  0x2f954ec5 -[NSException initWithCoder:] + 1
3   Foundation                      0x3027213f -[NSPlaceholderString initWithFormat:locale:arguments:] + 95
4   Foundation                      0x30272069 +[NSString stringWithFormat:] + 61
5   Cookila copy                    0x000cdeff -[NSDate(DateTools) logicLocalizedStringFromFormat:withValue:] (NSDate+DateTools.m:224)
6   Cookila copy                    0x000cdd05 -[NSDate(DateTools) shortTimeAgoSinceDate:] (NSDate+DateTools.m:207)
7   Cookila copy                    0x000cd1c7 -[NSDate(DateTools) shortTimeAgoSinceNow] (NSDate+DateTools.m:97)

On my device (both device and simulator) parsing the user's data - everything works...

Any leads would be appreciated...

Minimum ios 6.1

Hi,

I saw that you require a minimum of ios 6.1. My project usually supports 6.0 and up. Is there anything in your lib that prevents you to support 6.0?

Localization not working using Cocoapods Frameworks

The localization bundle doesn't seem to respect the device used language. I temporary fixed this by including the DateTools.bundle directly in my main project.

Any ways to fix this directly in the pod?

isWeekend() returning true on a monday

I have an NSDate object that is set to February 16, 2015 which is a Monday. When I use isWeekend() on it, it returns true. This is a swift app using a bridging header.

//Monday, Presidents Day
println(date)
2015-02-16 00:00:00 +0000

println(date.isWeekend())
true

Comparing date fails (due to NSTimeInterval - a floating point)

Hello,
while trying to compare dates I get the following results (is slot in range startDate/endDate?)

NO - slot/startDate/endDate:2015-02-14 03:30:00 +0000/2015-02-14 03:30:00 +0000/2015-02-14 23:30:00 +0000
timeInterval slot/startDate/endDate : 1423884600.000000/1423884600.570670/1423956600.570670

Comparison is done with this code

[slotDate isLaterThanOrEqualTo:startDate] && [slotDate isEarlierThanOrEqualTo:endDate]

Please correct

tomorrow?

great library, and great selection of utilities in here but must throw it out there that i find it a little strange that i'm not seeing a concept of 'tomorrow' in there.

:-)

Reusing formatter instances

Hello,

Thanks for this great library. I have started using it as soon as I discovered.

I was maintaining a project and making sure that I am reusing formatter instances after reading this article of Matt Thompson.

I'll try to apply apply this methodology to this library and I'd love to send a pull request if you are interested. I just wanted to open a discussion because I want to hear thoughts of other developers on this issue.

Can we add a `isSameDay` method?

Currently we have two methods: daysFrom and isToday. isToday is very usefull when comparing with today. However daysFrom is not that usefull when checking if two dates is in the same day.
Can we add a isSameDay method?
Thanks.

isEqual instead of isEqualToString? (Russian and Ukrainian locales)

Hi, I might be wrong because Im pretty new to objc, but in NSDate+DateTools.m in the method getLocaleFormatUnderscoresWithValue there are two NSString compared using isEqual.

// Russian (ru) and Ukrainian (uk)
if([localeCode isEqual:@"ru"] || [localeCode isEqual:@"uk"]) {

should be replaced with

// Russian (ru) and Ukrainian (uk)
if([localeCode isEqualToString:@"ru"] || [localeCode isEqualToString:@"uk"]) {

Cheers, Luca

Short Time displaying wrong in very short interval

I am using this library into tableview. When data loaded from server and displayed in table at that time when ther is no big time diffrence (i.e 4-5 s) it first shows that time difference but after scrolling table and coming back to that cell time diefference will decrease instead of increasing . And this will continue up to 0 s and then time difference will increase and will work fine.
Here How I am using this library :

lblTime.text = [dateFromServer shortTimeAgoSinceNow];

Here is one sample date format : 2014-09-30 07:38:03 +0000

Can't integrate v1.2.0 with CocoaPods

Hey,
I'm having some issues with v1.2.0 and integrating into a cocoapods project. I cleaned the project, cleared derived data, and tried installing multiple times but the only files that install are these:
screen shot 2014-05-07 at 7 00 07 pm

Finding void periods in a collection

Hey,

I love Datetools, it's solving so many issues for me and it seems pretty solid - congrats Matt.

I need to be able to find the void areas in a collection (i.e. areas where there are no timespans) and looking for solutions to this problem.

I've been pondering on the solution and I think it would probably require a collection to be merged together to form a chain, from there it would be easily enough to invert the chain to produce a group of timespans of void areas.

Is there any easy solution to merge a collection of timespans together?

Cheers

Chris

No localization for short time strings?

I checked localized strings and could not find any localization for shortened time strings. I want to localize short time strings as well. How can I achieve this?

Support Cocoapods 0.36

At the moment DateTools crashes when installed through version of cocoapods 0.36+

The main change is that now the resources bundle are not included into the main one, but they are inside the framework. You can find more information here: http://blog.cocoapods.org/CocoaPods-0.36/

Caveats
One caveat about bundling resources is, that until now we had to embed all resources into the application bundle. The resources were referenced programmatically by [NSBundle mainBundle]. Pod authors were able to use mainBundle referencing to include resources the Pod brought into the app bundle. But with frameworks, you have to make sure that you reference them more specifically by getting a reference to your framework's bundle e.g.

Objective-C
[NSBundle bundleForClass:<#ClassFromPodspec#>]

Swift
NSBundle(forClass: <#ClassFromPodspec#>)

For DateTools the problem is in this macro:

NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DateTools.bundle"]], nil)
Which can't find the bundle and returns nil causing the crash.

A possible solution, even if probably not the more elegant is to replace the macro with:

NSLocalizedStringFromTableInBundle(key, @"DateTools", [NSBundle bundleForClass:NSClassFromString(@"DTTimePeriod")], nil)

Compare two times?

Is there a way to compare two time discarding the date component?
Ie: 15:00 is earlier than 17:00.
(I could create two NSDate of the same day with these two hours but it's the best way to use DateTools?)

StartDate / EndDate

In DTTimePeriodGroup.h you define two properties and their accessors called StartDate and EndDate. This is not following Apple's recommendation of using camel case starting with a lowercase letter. If I were you I'd change those to startDate and endDate

OS X platform in .podspec

My iOS project has an OS X target, used for data generation. I recently migrated to DateTools, but I can not use it from cocoa pods with a mentioned target, because .podspec declares that DateTools are iOS only. Can you add OS X as platform to .podspec? Or is it somehow incompatible with OS X? My idea was that NSDate / date / time operations should be relevant for both platforms. Thank you.

Want to add floor/ceil days feature.

I encountered a requirement that I need to know the days between two date. For example

2015-09-15 10:44:51
2015-09-20 10:00:00

The daysFrom: method will return 4. Actually it's 4 days 23 hours 15 minutes and 8 seconds. I want it return 5 days, that is the ceil days between the two date.

Could I Add features like this to this repo?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.