-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from deasmi/master
Rotation bug fix and updated pull to refresh time/date label
- Loading branch information
Showing
7 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// ZelNSDateFormatter+Extras.h | ||
// | ||
// Created by Dean Smith on 16/03/2011. | ||
// | ||
|
||
#import <Foundation/NSDateFormatter.h> | ||
|
||
@interface NSDateFormatter (Extras) | ||
+ (NSString *)dateDifferenceStringFromString:(NSString *)dateString | ||
withFormat:(NSString *)dateFormat; | ||
|
||
|
||
|
||
+(NSString*)dateDifferenceStringFromDate:(NSDate*)date; | ||
|
||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// ZelNSDateFormatter+Extras.m | ||
// | ||
// Created by Dean Smith on 16/03/2011. | ||
// | ||
|
||
#import "ZelNSDateFormatter+Extras.h" | ||
|
||
@implementation NSDateFormatter (Extras) | ||
|
||
+ (NSString *)dateDifferenceStringFromString:(NSString *)dateString | ||
withFormat:(NSString *)dateFormat | ||
{ | ||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | ||
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; | ||
[dateFormatter setDateFormat:dateFormat]; | ||
NSDate *date = [dateFormatter dateFromString:dateString]; | ||
return [NSDateFormatter dateDifferenceStringFromDate:date]; | ||
} | ||
|
||
|
||
+(NSString*)dateDifferenceStringFromDate:(NSDate*)date { | ||
NSDate *now = [NSDate date]; | ||
double time = [date timeIntervalSinceDate:now]; | ||
time *= -1; | ||
if (time < 60) { | ||
return @"seconds ago"; | ||
} else if (time < 3600) { | ||
int diff = round(time / 60); | ||
if (diff == 1) | ||
return [NSString stringWithFormat:@"1 minute ago", diff]; | ||
return [NSString stringWithFormat:@"%d minutes ago", diff]; | ||
} else if (time < 86400) { | ||
int diff = round(time / 60 / 60); | ||
if (diff == 1) | ||
return [NSString stringWithFormat:@"1 hour ago", diff]; | ||
return [NSString stringWithFormat:@"%d hours ago", diff]; | ||
} else if (time < 604800) { | ||
int diff = round(time / 60 / 60 / 24); | ||
if (diff == 1) | ||
return [NSString stringWithFormat:@"yesterday", diff]; | ||
if (diff == 7) | ||
return [NSString stringWithFormat:@"last week", diff]; | ||
return[NSString stringWithFormat:@"%d days ago", diff]; | ||
} else { | ||
int diff = round(time / 60 / 60 / 24 / 7); | ||
if (diff == 1) | ||
return [NSString stringWithFormat:@"last week", diff]; | ||
return [NSString stringWithFormat:@"%d weeks ago", diff]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters