diff --git a/QDateInlineTableViewCell.m b/QDateInlineTableViewCell.m index 30f9ca24..63ae3191 100644 --- a/QDateInlineTableViewCell.m +++ b/QDateInlineTableViewCell.m @@ -37,7 +37,7 @@ - (void)prepareDateTimePicker:(QDateTimeInlineElement *)element if (!self.pickerView) self.pickerView = [[UIDatePicker alloc] init]; - self.pickerView.timeZone = [NSTimeZone localTimeZone]; + self.pickerView.timeZone = element.timeZone ? element.timeZone : [NSTimeZone localTimeZone]; [self.pickerView sizeToFit]; self.pickerView.datePickerMode = element.mode; self.pickerView.maximumDate = element.maximumDate; @@ -64,6 +64,7 @@ - (void) dateChanged:(id)sender{ - (void)prepareForElement:(QDateTimeInlineElement *)element inTableView:(QuickDialogTableView *)tableView { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; + dateFormatter.timeZone = element.timeZone ? element.timeZone : [NSTimeZone localTimeZone]; self.element = element; if (element.customDateFormat!=nil){ diff --git a/quickdialog/QDateEntryTableViewCell.m b/quickdialog/QDateEntryTableViewCell.m index d074f982..b06963d1 100644 --- a/quickdialog/QDateEntryTableViewCell.m +++ b/quickdialog/QDateEntryTableViewCell.m @@ -54,7 +54,7 @@ - (void)prepareDateTimePicker:(QDateTimeInlineElement * const)element if (!_pickerView) _pickerView = [[UIDatePicker alloc] init]; - _pickerView.timeZone = [NSTimeZone localTimeZone]; + _pickerView.timeZone = element.timeZone ? element.timeZone : [NSTimeZone localTimeZone]; [_pickerView sizeToFit]; [_pickerView addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged]; _pickerView.datePickerMode = element.mode; @@ -100,6 +100,7 @@ - (void)prepareForElement:(QEntryElement *)element inTableView:(QuickDialogTable QDateTimeInlineElement *dateElement = ((QDateTimeInlineElement *) element); NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; + dateFormatter.timeZone = dateElement.timeZone ? dateElement.timeZone : [NSTimeZone localTimeZone]; if (element.customDateFormat!=nil){ dateFormatter.dateFormat = element.customDateFormat; diff --git a/quickdialog/QDateTimeInlineElement.h b/quickdialog/QDateTimeInlineElement.h index c27b5c6c..096d73a6 100755 --- a/quickdialog/QDateTimeInlineElement.h +++ b/quickdialog/QDateTimeInlineElement.h @@ -38,6 +38,8 @@ @property(nonatomic, strong) NSDate *minimumDate; +@property (nonatomic, strong) NSTimeZone *timeZone; + @property(nonatomic) BOOL showPickerInCell; - (QDateTimeInlineElement *)initWithDate:(NSDate *)date andMode:(UIDatePickerMode)mode; diff --git a/quickdialog/QDateTimeInlineElement.m b/quickdialog/QDateTimeInlineElement.m index a94d976f..660047ba 100755 --- a/quickdialog/QDateTimeInlineElement.m +++ b/quickdialog/QDateTimeInlineElement.m @@ -18,6 +18,7 @@ @implementation QDateTimeInlineElement { @private NSDate *_maximumDate; NSDate *_minimumDate; + NSTimeZone *_timeZone; __weak QTableViewCell *_cell; } @@ -26,6 +27,7 @@ @implementation QDateTimeInlineElement { @synthesize centerLabel = _centerLabel; @synthesize maximumDate = _maximumDate; @synthesize minimumDate = _minimumDate; +@synthesize timeZone = _timeZone; @synthesize onValueChanged = _onValueChanged; @synthesize minuteInterval = _minuteInterval; @@ -67,6 +69,7 @@ - (NSDate *)dateValue { if (self.mode == UIDatePickerModeDate) { NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; + gregorian.timeZone = self.timeZone ? self.timeZone : [NSTimeZone localTimeZone]; NSDateComponents *dateComponents = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:_dateValue]; _dateValue = [gregorian dateFromComponents:dateComponents]; } diff --git a/sample/SampleDataBuilder.m b/sample/SampleDataBuilder.m index ae88ed4b..f9a11d98 100644 --- a/sample/SampleDataBuilder.m +++ b/sample/SampleDataBuilder.m @@ -659,6 +659,11 @@ + (QRootElement *)createDateTimeRoot { QDateTimeInlineElement *el4 = [[QDateTimeInlineElement alloc] initWithTitle:@"Time only" date:[NSDate date] andMode:UIDatePickerModeTime]; [section addElement:el4]; + + QDateTimeInlineElement *el5 = [[QDateTimeInlineElement alloc] initWithTitle:@"Time only (UTC)" date:[NSDate date] andMode:UIDatePickerModeTime]; + el5.timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; + [section addElement:el5]; + QDateTimeInlineElement *elDiffTime = [[QDateTimeInlineElement alloc] initWithTitle:@"Different date" date: [NSDate dateWithTimeIntervalSinceNow:-36000] andMode:UIDatePickerModeDate]; @@ -672,19 +677,19 @@ + (QRootElement *)createDateTimeRoot { QSection *section2 = [[QSection alloc] init]; section2.title = @"Push editing"; - QDateTimeElement *el5 = [[QDateTimeElement alloc] initWithTitle:@"Time only" date:[NSDate date]]; - el5.mode = UIDatePickerModeTime; - [section2 addElement:el5]; - - QDateTimeElement *el6 = [[QDateTimeElement alloc] initWithTitle:@"Date only" date:[NSDate date]]; - el6.mode = UIDatePickerModeDate; + QDateTimeElement *el6 = [[QDateTimeElement alloc] initWithTitle:@"Time only" date:[NSDate date]]; + el6.mode = UIDatePickerModeTime; [section2 addElement:el6]; - QDateTimeElement *el7 = [[QDateTimeElement alloc] initWithTitle:@"Full Date" date:[NSDate date]]; - el7.mode = UIDatePickerModeDateAndTime; - el7.minuteInterval = 3; + QDateTimeElement *el7 = [[QDateTimeElement alloc] initWithTitle:@"Date only" date:[NSDate date]]; + el7.mode = UIDatePickerModeDate; [section2 addElement:el7]; + QDateTimeElement *el8 = [[QDateTimeElement alloc] initWithTitle:@"Full Date" date:[NSDate date]]; + el8.mode = UIDatePickerModeDateAndTime; + el8.minuteInterval = 3; + [section2 addElement:el8]; + [root addSection:section]; [root addSection:section2]; return root;