Permalink
Browse files

somehow I wacked a method in a previous merge, fixed here, optional f…

…orcing display of time
  • Loading branch information...
1 parent 1038001 commit 74b7c4979631cae13eeff9cde2d9f5d1ee0c02f0 @billymeltdown committed Jun 12, 2012
Showing with 23 additions and 5 deletions.
  1. +23 −5 NSDate+Helper.m
View
@@ -101,8 +101,8 @@ + (NSString *)stringFromDate:(NSDate *)date {
return [date string];
}
-+ (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed {
- /*
++ (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed alwaysDisplayTime:(BOOL)displayTime {
+ /*
* if the date is in today, display 12-hour time with meridian,
* if it is within the last 7 days, display weekday name (Friday)
* if within the calendar year, display as Jan 23
@@ -134,7 +134,11 @@ + (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed {
[componentsToSubtract release];
NSComparisonResult lastweek_result = [date compare:lastweek];
if (lastweek_result == NSOrderedDescending) {
- [displayFormatter setDateFormat:@"EEEE"]; // Tuesday
+ if (displayTime) {
+ [displayFormatter setDateFormat:@"EEEE h:mm a"];
+ } else {
+ [displayFormatter setDateFormat:@"EEEE"]; // Tuesday
+ }
} else {
// check if same calendar year
NSInteger thisYear = [offsetComponents year];
@@ -143,9 +147,19 @@ + (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed {
fromDate:date];
NSInteger thatYear = [dateComponents year];
if (thatYear >= thisYear) {
- [displayFormatter setDateFormat:@"MMM d"];
+ if (displayTime) {
+ [displayFormatter setDateFormat:@"MMM d h:mm a"];
+ }
+ else {
+ [displayFormatter setDateFormat:@"MMM d"];
+ }
} else {
- [displayFormatter setDateFormat:@"MMM d, yyyy"];
+ if (displayTime) {
+ [displayFormatter setDateFormat:@"MMM d, yyyy h:mm a"];
+ }
+ else {
+ [displayFormatter setDateFormat:@"MMM d, yyyy"];
+ }
}
}
if (prefixed) {
@@ -163,6 +177,10 @@ + (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed {
return displayString;
}
++ (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed {
+ return [[self class] stringForDisplayFromDate:date prefixed:prefixed alwaysDisplayTime:NO];
+}
+
+ (NSString *)stringForDisplayFromDate:(NSDate *)date {
return [self stringForDisplayFromDate:date prefixed:NO];
}

0 comments on commit 74b7c49

Please sign in to comment.