Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input: some date in future, output: "just now" #1

Merged
merged 1 commit into from
May 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions NSDate+PrettyDate/NSDate+PrettyDate.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (NSString *)prettyDate
return [NSString stringWithFormat:NSLocalizedString(@"%d minutes ago", nil), comps.minute];
} else if (comps.second < 30) {
// HANDLE SECONDS
return NSLocalizedString(@"just now", nil);
return comps.second < 0 ? NSLocalizedString(@"future date", nil) : NSLocalizedString(@"just now", nil);
}
return [NSString stringWithFormat:NSLocalizedString(@"%d seconds ago", nil), comps.second];
}
Expand Down Expand Up @@ -100,7 +100,7 @@ - (NSString *)prettyDate2
NSLocalizedString(@"%d minutes and %d seconds ago", nil), comps.minute, comps.second];
} else if (comps.second < 30) {
// HANDLE SECONDS
return NSLocalizedString(@"a few seconds ago", nil);
return comps.second < 0 ? NSLocalizedString(@"future date", nil) : NSLocalizedString(@"a few seconds ago", nil);
}
return [NSString stringWithFormat:NSLocalizedString(@"%d seconds ago ...", nil), comps.second];
}
Expand Down
7 changes: 7 additions & 0 deletions NSDate+PrettyDateTests/NSDate_PrettyDateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ - (void)tearDown
[super tearDown];
}

- (void)testPrettyDateFuture {
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:5];
result = [date prettyDate];
expects = @"future date";
STAssertTrue([result isEqualToString:expects], [NSString stringWithFormat:@"Expected '%@' got '%@'", expects, result]);
}

- (void)testPrettyDateJustNow
{
NSDate *date = [NSDate date];
Expand Down
1 change: 1 addition & 0 deletions de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


// PrettyDate
"future date" = "zukünftiges Datum";
"just now" = "in diesem Moment";
"a minute ago" = "vor einer Minute";
"last hour" = "letzte Stunde";
Expand Down