diff options
Diffstat (limited to 'Volta/Views/StatsTabBarController.m')
| -rw-r--r-- | Volta/Views/StatsTabBarController.m | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/Volta/Views/StatsTabBarController.m b/Volta/Views/StatsTabBarController.m index cce66bb..8e53591 100644 --- a/Volta/Views/StatsTabBarController.m +++ b/Volta/Views/StatsTabBarController.m @@ -12,6 +12,8 @@ @interface StatsTabBarController () +@property (strong, nonatomic) NSDateFormatter *dateFormatter; + @end @implementation StatsTabBarController @@ -26,6 +28,20 @@ } +- (NSDateFormatter *)dateFormatter +{ + if (!_dateFormatter) + { + _dateFormatter = [[NSDateFormatter alloc] init]; + [_dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; + NSCalendar* calendar = [NSCalendar currentCalendar]; + [calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; + [_dateFormatter setCalendar:calendar]; + } + return _dateFormatter; +} + + // -------------------------------------------------------------------------------------- - (void)updateData { @@ -38,13 +54,14 @@ [httpClient setDefaultHeader:@"Accept" value:@"application/json"]; [httpClient setParameterEncoding:AFJSONParameterEncoding]; - // NSString *startDate = [self.queryDateFormatter stringFromDate:[NSDate date]]; + NSString *startDateUTC = [self.dateFormatter stringFromDate:self.startDate]; + NSString *endDateUTC = [self.dateFormatter stringFromDate:self.endDate]; NSError *error; NSString *token = [SSKeychain passwordForService:KEYCHAIN_API_TOKEN account:KEYCHAIN_ACCOUNT error:&error]; NSMutableURLRequest *request; - request = [httpClient requestWithMethod:@"GET" path:[NSString stringWithFormat:URL_READINGS, token] parameters:nil]; + request = [httpClient requestWithMethod:@"GET" path:[NSString stringWithFormat:URL_READINGS, token, startDateUTC, endDateUTC] parameters:nil]; NSLog(@"GET: %@", request); @@ -55,14 +72,15 @@ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; NSLog(@"%@", JSON); + if (!self.data) + { + self.data = [[MGOrderedDictionary alloc] init]; + } + for (NSDictionary *data in JSON) { VoltaReading *aReading = [VoltaReading initFromJSON:data]; NSString *dictKey = aReading.dictionaryKey; - if (!self.data) - { - self.data = [[MGOrderedDictionary alloc] init]; - } // we now group data by day (calc totals for days usage and cost) if (![self.data objectForKey:dictKey]) |
