Browse Source

New way to calculate relative day.

v1.4.1
Abhishek Banthia 8 years ago
parent
commit
bbdf0134c5
  1. 72
      Clocker/Model/CLTimezoneDataOperations.m

72
Clocker/Model/CLTimezoneDataOperations.m

@ -128,18 +128,20 @@
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date - (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date
{ {
NSDateFormatter *formatter = [NSDateFormatter new]; NSDateFormatter *localFormatter = [NSDateFormatter new];
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; localFormatter.timeStyle = NSDateFormatterMediumStyle;
formatter.timeStyle = NSDateFormatterMediumStyle; localFormatter.dateStyle = NSDateFormatterMediumStyle;
formatter.dateStyle = NSDateFormatterMediumStyle; localFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSDate *localDate = [formatter dateFromString:systemDate]; NSDate *localDate = [localFormatter dateFromString:systemDate];
NSDate *timezoneDate = [formatter dateFromString:date]; NSDate *timezoneDate = [localFormatter dateFromString:date];
// Specify which units we would like to use // Specify which units we would like to use
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:localDate]; NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:localDate];
NSInteger timezoneWeekday = [calendar component:NSCalendarUnitWeekday fromDate:timezoneDate];
if ([self.dataObject.nextUpdate isKindOfClass:[NSString class]]) if ([self.dataObject.nextUpdate isKindOfClass:[NSString class]])
{ {
@ -198,23 +200,53 @@
dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.dataObject.timezoneID]; dateFormatter.timeZone = [NSTimeZone timeZoneWithName:self.dataObject.timezoneID];
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateStyle = NSDateFormatterMediumStyle;
formatter.timeStyle = NSDateFormatterMediumStyle;
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSDate *convertedDate = [formatter dateFromString:[dateFormatter stringFromDate:newDate]];
NSCalendar *calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
NSInteger timezoneWeekday = [calendar component:NSCalendarUnitWeekday fromDate:convertedDate];
NSNumber *relativeDayPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLRelativeDateKey]; NSNumber *relativeDayPreference = [[NSUserDefaults standardUserDefaults] objectForKey:CLRelativeDateKey];
if (relativeDayPreference.integerValue == 0 && type == CLPanelDisplay) {
return [self compareSystemDate:[self getLocalCurrentDate] if (relativeDayPreference.integerValue == 0 && type == CLPanelDisplay)
toTimezoneDate:[dateFormatter stringFromDate:newDate]];
}
else
{ {
NSDateFormatter *formatter = [NSDateFormatter new]; NSDateFormatter *localFormatter = [NSDateFormatter new];
formatter.dateStyle = NSDateFormatterMediumStyle; localFormatter.timeStyle = NSDateFormatterMediumStyle;
formatter.timeStyle = NSDateFormatterMediumStyle; localFormatter.dateStyle = NSDateFormatterMediumStyle;
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; localFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSDate *convertedDate = [formatter dateFromString:[formatter stringFromDate:newDate]]; NSDate *localDate = [localFormatter dateFromString:[self getLocalCurrentDate]];
NSCalendar *calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]; // Specify which units we would like to use
NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:convertedDate]; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
return [self getWeekdayFromInteger:weekday]; NSInteger weekday = [calendar component:NSCalendarUnitWeekday fromDate:localDate];
if (weekday == timezoneWeekday + 1)
{
return @"Yesterday";
}
else if (weekday == timezoneWeekday)
{
return @"Today";
}
else if (weekday + 1 == timezoneWeekday)
{
return @"Tomorrow";
}
else
{
return @"Day after Tomorrow";
}
}
else
{
return [self getWeekdayFromInteger:timezoneWeekday];
} }
} }
@ -223,8 +255,8 @@
NSDateFormatter *dateFormatter = [NSDateFormatter new]; NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateStyle = kCFDateFormatterMediumStyle; dateFormatter.dateStyle = kCFDateFormatterMediumStyle;
dateFormatter.timeStyle = kCFDateFormatterMediumStyle; dateFormatter.timeStyle = kCFDateFormatterMediumStyle;
dateFormatter.timeZone = [NSTimeZone localTimeZone];
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"]; dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
dateFormatter.timeZone = [NSTimeZone systemTimeZone];
return [dateFormatter stringFromDate:[NSDate date]]; return [dateFormatter stringFromDate:[NSDate date]];

Loading…
Cancel
Save