mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-25 02:59:28 +00:00
Added humanized Date formatting (simple)
Fixed errors that would occur if undo was mixed with emptying the trash Updated localizations Added localized descriptions Fixed #31 Database name is displayed, if none is given fallback is used
This commit is contained in:
39
MacPass/NSDate+Humanized.m
Normal file
39
MacPass/NSDate+Humanized.m
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// NSDate+Humanized.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 10.07.13.
|
||||
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSDate+Humanized.h"
|
||||
|
||||
@implementation NSDate (Humanized)
|
||||
|
||||
+ (NSString *)humanizedDate:(NSDate *)date {
|
||||
return [date humanized];
|
||||
}
|
||||
|
||||
- (NSString *)humanized {
|
||||
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
|
||||
NSDateComponents *components = [calendar components:NSMinuteCalendarUnit|NSHourCalendarUnit|NSDayCalendarUnit fromDate:self toDate:[NSDate date] options:0];
|
||||
if([components day] > 1) {
|
||||
return [NSDateFormatter localizedStringFromDate:self
|
||||
dateStyle:NSDateFormatterShortStyle
|
||||
timeStyle:NSDateFormatterShortStyle];
|
||||
}
|
||||
if([components day] == 1) {
|
||||
return NSLocalizedString(@"YESTERDAY", "Yesterday");
|
||||
}
|
||||
if([components hour] > 1) {
|
||||
NSString *hourTemplate = NSLocalizedString(@"%ld_HOURS_AGO", "% Hours ago");
|
||||
return [NSString stringWithFormat:hourTemplate, [components hour]];
|
||||
}
|
||||
NSInteger minutes = [components minute];
|
||||
if(minutes > 1) {
|
||||
NSString *minuteTemplate = NSLocalizedString(@"%ld_MINUTES_AGO", "% Minutes ago");
|
||||
return [NSString stringWithFormat:minuteTemplate, minutes];
|
||||
}
|
||||
return NSLocalizedString(@"JUST_NOW", "Just now");
|
||||
}
|
||||
@end
|
||||
Reference in New Issue
Block a user