Browse Source

New data handler class!

v1.2.3
Abhishek Banthia 9 years ago
parent
commit
a1f52ce832
  1. 37
      Clocker/Model/CLTimezoneData.m

37
Clocker/Model/CLTimezoneData.m

@ -6,15 +6,16 @@
// //
// //
#import "CLAPI.h"
#import "CLTimezoneData.h" #import "CLTimezoneData.h"
#import "CommonStrings.h" #import "CommonStrings.h"
#import "DateTools.h" #import "DateTools.h"
#import "CLAPI.h"
#import "PanelController.h" #import "PanelController.h"
#import <Parse/Parse.h> #import <Parse/Parse.h>
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h> #include <IOKit/IOKitLib.h>
@implementation CLTimezoneData @implementation CLTimezoneData
-(instancetype)initWithDictionary:(NSDictionary *)dictionary -(instancetype)initWithDictionary:(NSDictionary *)dictionary
@ -57,6 +58,10 @@
} }
+ (instancetype)getCustomObject:(NSData *)encodedData + (instancetype)getCustomObject:(NSData *)encodedData
{
if (encodedData)
{ {
if ([encodedData isKindOfClass:[NSDictionary class]]) if ([encodedData isKindOfClass:[NSDictionary class]])
{ {
@ -68,6 +73,10 @@
} }
return nil;
}
- (void)encodeWithCoder:(NSCoder *)coder - (void)encodeWithCoder:(NSCoder *)coder
{ {
[coder encodeObject:self.place_id forKey:@"place_id"]; [coder encodeObject:self.place_id forKey:@"place_id"];
@ -211,6 +220,9 @@
- (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date - (NSString *)compareSystemDate:(NSString *)systemDate toTimezoneDate:(NSString *)date
{ {
NSParameterAssert(systemDate);
NSParameterAssert(date);
NSDateFormatter *formatter = [NSDateFormatter new]; NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy" formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"MM/dd/yyyy"
options:0 options:0
@ -219,9 +231,8 @@
NSDate *localDate = [formatter dateFromString:systemDate]; NSDate *localDate = [formatter dateFromString:systemDate];
NSDate *timezoneDate = [formatter dateFromString:date]; NSDate *timezoneDate = [formatter dateFromString:date];
if (localDate == nil || timezoneDate == nil) { NSAssert(localDate != nil, @"Local date cannot be nil");
return @"Today"; NSAssert(timezoneDate != nil, @"Local date cannot be nil");
}
// Specify which units we would like to use // Specify which units we would like to use
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
@ -310,6 +321,7 @@
- (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger - (NSString *)getWeekdayFromInteger:(NSInteger)weekdayInteger
{ {
if (weekdayInteger > 7) { if (weekdayInteger > 7) {
weekdayInteger = weekdayInteger - 7; weekdayInteger = weekdayInteger - 7;
} }
@ -359,12 +371,17 @@
if (shouldCityBeShown.boolValue == 0) if (shouldCityBeShown.boolValue == 0)
{ {
self.customLabel.length > 0 ?
[menuTitle appendString:self.customLabel] :
[menuTitle appendString:self.formattedAddress]; [menuTitle appendString:self.formattedAddress];
} }
if (shouldDayBeShown.boolValue == 0) if (shouldDayBeShown.boolValue == 0)
{ {
NSString *substring = [self getDateForTimeZoneWithFutureSliderValue:0 andDisplayType:CLMenuDisplay]; NSString *substring = [self getDateForTimeZoneWithFutureSliderValue:0 andDisplayType:CLMenuDisplay];
substring = [substring substringToIndex:3]; substring = [substring substringToIndex:3];
if (menuTitle.length > 0) if (menuTitle.length > 0)
@ -406,10 +423,20 @@
- (void)sendAnalyticsData - (void)sendAnalyticsData
{ {
NSAssert(self.formattedAddress != nil, @"Formatted Address cannot be nil before sending analytics");
NSAssert(self.timezoneID != nil, @"Timezone ID cannot be nil before sending analytics");
NSString *uniqueIdentifier = [self getSerialNumber];
if (uniqueIdentifier == nil)
{
uniqueIdentifier = @"N/A";
}
PFObject *feedbackObject = [PFObject objectWithClassName:@"CLTimezoneData"]; PFObject *feedbackObject = [PFObject objectWithClassName:@"CLTimezoneData"];
feedbackObject[@"formattedAddress"] = self.formattedAddress; feedbackObject[@"formattedAddress"] = self.formattedAddress;
feedbackObject[@"timezoneID"] = self.timezoneID; feedbackObject[@"timezoneID"] = self.timezoneID;
feedbackObject[@"uniqueID"] = [self getSerialNumber]; feedbackObject[@"uniqueID"] = uniqueIdentifier;
[feedbackObject saveEventually]; [feedbackObject saveEventually];
} }

Loading…
Cancel
Save