IncidentLog.m
2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// IncidentLog.m
// DUREX Vendor Control
//
// Created by Imanol Barba on 10/8/14.
// Copyright (c) 2014 Emmoco. All rights reserved.
//
#import "IncidentLog.h"
@implementation IncidentLog
- (id) init
{
[self setIncidents:[[NSMutableArray alloc] init]];
return self;
}
- (void) setResponseValue:(NSString *)response
{
[self setResponse: response];
[self parseResponse];
}
- (void) parseResponse
{
NSInteger currentIncident = 0;
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
NSDateComponents *incidentDate = [[NSDateComponents alloc] init];
NSInteger currentYear = [[calendar components:units fromDate:[NSDate date]] year];
currentYear = (currentYear/100)*100;
while(![[[self response] substringWithRange:NSMakeRange((currentIncident*INCIDENT_STRING_LENGTH), 4)] isEqualToString:@"P3P3"])
{
Incident *incident = [[Incident alloc] init];
[incidentDate setYear:(currentYear + [[[self response] substringWithRange:NSMakeRange(2 + currentIncident*SALE_STRING_LENGTH, 2)] intValue])];
[incidentDate setMonth:[[[self response] substringWithRange:NSMakeRange(4 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]];
[incidentDate setDay:[[[self response] substringWithRange:NSMakeRange(6 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]];
[incidentDate setHour:[[[self response] substringWithRange:NSMakeRange(8 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]];
[incidentDate setMinute:[[[self response] substringWithRange:NSMakeRange(10 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]];
[incidentDate setMinute:[[[self response] substringWithRange:NSMakeRange(12 + currentIncident*SALE_STRING_LENGTH, 2)] intValue]];
[incident setIncidentTime:[calendar dateFromComponents:incidentDate]];
NSLog(@"date: %@",[calendar dateFromComponents:incidentDate]);
[incident setErrorCode:[[self response] substringWithRange:NSMakeRange(14 + currentIncident*SALE_STRING_LENGTH, 2)]];
NSLog(@"errorCode: %@",[incident errorCode]);
[incident setErrorValue:[[self response] substringWithRange:NSMakeRange(16 + currentIncident*SALE_STRING_LENGTH, 4)]];
NSLog(@"errorValue: %@",[incident errorValue]);
[[self incidents] insertObject:incident atIndex:currentIncident];
currentIncident++;
}
NSLog(@"%@",[self incidents]);
}
@end