@@ -30,6 +30,7 @@ import platform.UIKit.UIControlEventTouchUpInside
3030import platform.UIKit.UIApplication
3131import platform.Foundation.NSBundle
3232import platform.Foundation.NSDate
33+ import platform.Foundation.NSTimeIntervalSince1970
3334
3435actual class DatePickerDialogHandler (
3536 val positive : ((dialogId: Int , date: DateTime ) -> Unit )? ,
@@ -212,35 +213,31 @@ class DatePickerController(
212213 anchor = controlPanel.topAnchor
213214 ).active = true
214215
215- val nsDate = NSDate ()
216- val date = DateTime .nowUnix()
217- val diffDate = date - nsDate.timeIntervalSinceReferenceDate
218-
219- if (startDate != null ) {
220- startDate.unixMillis
221- datePicker.minimumDate = NSDate (startDate.unixMillis - diffDate)
222- }
223-
224- if (endDate != null ) {
225- endDate.unixMillis
226- datePicker.maximumDate = NSDate (endDate.unixMillis - diffDate)
227- }
216+ datePicker.minimumDate = startDate?.toNSDate()
217+ datePicker.maximumDate = endDate?.toNSDate()
228218
229219 if (selectedDate != null ) {
230- datePicker.setDate(NSDate ( selectedDate.unixMillis - diffDate ))
220+ datePicker.setDate(selectedDate.toNSDate( ))
231221 }
232222
233223 doneButton.setEventHandler(UIControlEventTouchUpInside ) {
234224 this .dismissViewControllerAnimated(flag = true , completion = null )
235225 handler.positive?.invoke(
236226 dialogId,
237- DateTime (diffDate + datePicker.date.timeIntervalSinceReferenceDate )
227+ datePicker.date.toKlock( )
238228 )
239229 }
240230 cancelButton.setEventHandler(UIControlEventTouchUpInside ) {
241231 this .dismissViewControllerAnimated(flag = true , completion = null )
242232 handler.negative?.invoke(dialogId)
243233 }
244234 }
235+ }
236+
237+ internal fun DateTime.toNSDate (): NSDate {
238+ return NSDate ((unixMillis / 1000 ) - NSTimeIntervalSince1970 )
239+ }
245240
241+ internal fun NSDate.toKlock (): DateTime {
242+ return DateTime (unixMillis = (this .timeIntervalSinceReferenceDate() + NSTimeIntervalSince1970 ) * 1000 )
246243}
0 commit comments