Skip to content

Commit

Permalink
somehow I wacked a method in a previous merge, fixed here, optional f…
Browse files Browse the repository at this point in the history
…orcing display of time
  • Loading branch information
billymeltdown committed Jun 12, 2012
1 parent 1038001 commit 74b7c49
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions NSDate+Helper.m
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand All @@ -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];
}
Expand Down

0 comments on commit 74b7c49

Please sign in to comment.