mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 04:42:29 +00:00
using non deprecated NSCalendar and NSDate API
This commit is contained in:
@@ -39,23 +39,23 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) {
|
|||||||
NSArray *dateItems = @[ NSLocalizedString(@"TOMORROW", ""), NSLocalizedString(@"ONE_WEEK", ""), NSLocalizedString(@"ONE_MONTH", ""), NSLocalizedString(@"90_DAYS", ""), NSLocalizedString(@"ONE_YEAR", "") ];
|
NSArray *dateItems = @[ NSLocalizedString(@"TOMORROW", ""), NSLocalizedString(@"ONE_WEEK", ""), NSLocalizedString(@"ONE_MONTH", ""), NSLocalizedString(@"90_DAYS", ""), NSLocalizedString(@"ONE_YEAR", "") ];
|
||||||
|
|
||||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SELECT_DATE_PRESET", "") action:NULL keyEquivalent:@""];
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SELECT_DATE_PRESET", "") action:NULL keyEquivalent:@""];
|
||||||
[item setTag:MPDatePresetNone];
|
item.tag = MPDatePresetNone;
|
||||||
[presetMenu addItem:item];
|
[presetMenu addItem:item];
|
||||||
[presetMenu addItem:[NSMenuItem separatorItem]];
|
[presetMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
for(NSInteger iIndex = 0; iIndex < sizeof(tags)/sizeof(NSUInteger); iIndex++) {
|
for(NSInteger iIndex = 0; iIndex < sizeof(tags)/sizeof(NSUInteger); iIndex++) {
|
||||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:dateItems[iIndex] action:NULL keyEquivalent:@""];
|
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:dateItems[iIndex] action:NULL keyEquivalent:@""];
|
||||||
[item setTag:tags[iIndex]];
|
item.tag = tags[iIndex];
|
||||||
[presetMenu addItem:item];
|
[presetMenu addItem:item];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.datePicker setDateValue:[NSDate date]];
|
self.datePicker.dateValue = [NSDate date];
|
||||||
[self.presetPopupButton setMenu:presetMenu];
|
self.presetPopupButton.menu = presetMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)useDate:(id)sender {
|
- (IBAction)useDate:(id)sender {
|
||||||
self.didCancel = NO;
|
self.didCancel = NO;
|
||||||
self.date = [self.datePicker dateValue];
|
self.date = self.datePicker.dateValue;
|
||||||
[self.popover performClose:self];
|
[self.popover performClose:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,32 +65,32 @@ typedef NS_ENUM(NSUInteger, MPDatePreset) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction)setDatePreset:(id)sender {
|
- (IBAction)setDatePreset:(id)sender {
|
||||||
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
|
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
|
||||||
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
|
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
|
||||||
|
|
||||||
MPDatePreset preset = [[sender selectedItem] tag];
|
MPDatePreset preset = ((NSPopUpButton *)sender).selectedTag;
|
||||||
switch(preset) {
|
switch(preset) {
|
||||||
case MPDatePresetTomorrow:
|
case MPDatePresetTomorrow:
|
||||||
[offsetComponents setDay:1];
|
offsetComponents.day = 1;
|
||||||
break;
|
break;
|
||||||
case MPDatePresetOneWeek:
|
case MPDatePresetOneWeek:
|
||||||
[offsetComponents setWeek:1];
|
offsetComponents.weekOfMonth = 1;
|
||||||
break;
|
break;
|
||||||
case MPDatePresetOneMonth:
|
case MPDatePresetOneMonth:
|
||||||
[offsetComponents setMonth:1];
|
offsetComponents.month = 1;
|
||||||
break;
|
break;
|
||||||
case MPDatePreset90Days:
|
case MPDatePreset90Days:
|
||||||
[offsetComponents setDay:90];
|
offsetComponents.day = 90;
|
||||||
break;
|
break;
|
||||||
case MPDatePresetOneYear:
|
case MPDatePresetOneYear:
|
||||||
[offsetComponents setYear:1];
|
offsetComponents.year = 1;
|
||||||
break;
|
break;
|
||||||
case MPDatePresetNone:
|
case MPDatePresetNone:
|
||||||
default:
|
default:
|
||||||
return; // Nothing to do;
|
return; // Nothing to do;
|
||||||
}
|
}
|
||||||
NSDate *newDate = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];
|
NSDate *newDate = [gregorian dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];
|
||||||
[self.datePicker setDateValue:newDate];
|
self.datePicker.dateValue = newDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -15,15 +15,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)humanized {
|
- (NSString *)humanized {
|
||||||
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
|
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
|
||||||
NSDateComponents *components = [calendar components:NSMinuteCalendarUnit|NSHourCalendarUnit|NSDayCalendarUnit|NSWeekCalendarUnit|NSMonthCalendarUnit fromDate:self toDate:[NSDate date] options:0];
|
NSDateComponents *components = [calendar components:NSCalendarUnitMinute|NSCalendarUnitHour|NSCalendarUnitDay|NSCalendarUnitWeekOfMonth|NSCalendarUnitMonth fromDate:self toDate:[NSDate date] options:0];
|
||||||
/* More than one month in the past, give full date */
|
/* More than one month in the past, give full date */
|
||||||
if([components month] > 1) {
|
if(components.month > 1) {
|
||||||
return [NSDateFormatter localizedStringFromDate:self
|
return [NSDateFormatter localizedStringFromDate:self
|
||||||
dateStyle:NSDateFormatterShortStyle
|
dateStyle:NSDateFormatterShortStyle
|
||||||
timeStyle:NSDateFormatterShortStyle];
|
timeStyle:NSDateFormatterShortStyle];
|
||||||
}
|
}
|
||||||
NSUInteger weeks = [components week];
|
NSUInteger weeks = components.weekOfMonth;
|
||||||
/* More than one week, less than a month */
|
/* More than one week, less than a month */
|
||||||
if(weeks > 1) {
|
if(weeks > 1) {
|
||||||
NSString *weekTemplate = NSLocalizedString(@"%ld_WEEKS_AGO", "% Weeks ago");
|
NSString *weekTemplate = NSLocalizedString(@"%ld_WEEKS_AGO", "% Weeks ago");
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
return NSLocalizedString(@"ONE_WEEK_AGO", "one week ago");
|
return NSLocalizedString(@"ONE_WEEK_AGO", "one week ago");
|
||||||
}
|
}
|
||||||
/* Last week */
|
/* Last week */
|
||||||
NSUInteger days = [components day];
|
NSUInteger days = components.day;
|
||||||
if(days > 3) {
|
if(days > 3) {
|
||||||
return NSLocalizedString(@"LAST_WEEK", "last week");
|
return NSLocalizedString(@"LAST_WEEK", "last week");
|
||||||
}
|
}
|
||||||
@@ -48,14 +48,13 @@
|
|||||||
return NSLocalizedString(@"YESTERDAY", "Yesterday");
|
return NSLocalizedString(@"YESTERDAY", "Yesterday");
|
||||||
}
|
}
|
||||||
/* Hours ago */
|
/* Hours ago */
|
||||||
if([components hour] > 1) {
|
if(components.hour > 1) {
|
||||||
NSString *hourTemplate = NSLocalizedString(@"%ld_HOURS_AGO", "% Hours ago");
|
NSString *hourTemplate = NSLocalizedString(@"%ld_HOURS_AGO", "% Hours ago");
|
||||||
return [NSString stringWithFormat:hourTemplate, [components hour]];
|
return [NSString stringWithFormat:hourTemplate, components.hour];
|
||||||
}
|
}
|
||||||
NSInteger minutes = [components minute];
|
if(components.minute > 1) {
|
||||||
if(minutes > 1) {
|
|
||||||
NSString *minuteTemplate = NSLocalizedString(@"%ld_MINUTES_AGO", "% Minutes ago");
|
NSString *minuteTemplate = NSLocalizedString(@"%ld_MINUTES_AGO", "% Minutes ago");
|
||||||
return [NSString stringWithFormat:minuteTemplate, minutes];
|
return [NSString stringWithFormat:minuteTemplate, components.minute];
|
||||||
}
|
}
|
||||||
return NSLocalizedString(@"JUST_NOW", "Just now");
|
return NSLocalizedString(@"JUST_NOW", "Just now");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user