View Issue Details

IDProjectCategoryView StatusLast Update
0036252LazarusWidgetsetpublic2019-11-04 18:42
ReporterFrank Assigned ToDmitry Boyarintsev  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformMacOSmacOS 
Product Version2.0.7 (SVN) 
Summary0036252: CocoaDatePicker displays incorrect date, returns incorrect date
DescriptionA TCocoaDatePicker defaults to local time zone, an NSDate defaults to GMT, a TDateTime knows nothing of time zone. we must then set default TCocoaDatePicker time zone to GMT... or at least this is my understanding.

Attached is test project & patch
TagsNo tags attached.
Fixed in Revision62187
LazTarget-
WidgetsetCocoa
Attached Files

Activities

Frank

2019-11-03 15:52

reporter  

CocoaWSDatePicker.diff (2,063 bytes)   
Index: cocoawsdatepicker.pas
===================================================================
--- cocoawsdatepicker.pas	(.../svnlazarus-1.9/lcl/interfaces/cocoa/cocoawsdatepicker.pas)	(working copy)
+++ cocoawsdatepicker.pas	(.../svnlazarus-1.9-Cocoa/lcl/interfaces/cocoa/cocoawsdatepicker.pas)	(working copy)
@@ -7,7 +7,7 @@
 
 uses
   CocoaAll,
-  Classes, SysUtils, Controls, Calendar,
+  Classes, SysUtils, Controls, Calendar, DateUtils,
   WSCalendar, CocoaWSCommon, CocoaDatePicker,
   LCLtype, LclProc, LMessages, LCLMessageGlue,
   CocoaUtils, CocoaPrivate;
@@ -61,7 +61,8 @@
     flags:= NSYearMonthDayDatePickerElementFlag;
     Result.setDatePickerElements(flags);
 
-    Result.setTimeZone(NSTimeZone.localTimeZone);
+    Result.setTimeZone(NSTimeZone.timeZoneForSecondsFromGMT(0));
+//    Result.setTimeZone(NSTimeZone.localTimeZone);
 
     Result.setDateValue(DateTimeToNSDate(Now));
 
@@ -99,13 +100,26 @@
 end;
 
 class function  TCocoaWSCustomCalendar.GetDateTime(const ACalendar: TCustomCalendar): TDateTime;
+Var
+  sec: Int64;
+  dt : TDateTime;
 begin
-  Result:= NSDateToDateTime(NSDatePickerCell(ACalendar.Handle).dateValue);
+  sec:= NSDatePickerCell(ACalendar.Handle).timeZone.secondsFromGMT;
+  dt := NSDateToDateTime(NSDatePickerCell(ACalendar.Handle).dateValue);
+  Result:= IncSecond(dt, sec);
+//  Result:= NSDateToDateTime(NSDatePickerCell(ACalendar.Handle).dateValue);
 end;
 
 class procedure TCocoaWSCustomCalendar.SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime);
+Var
+  sec: Int64;
+  dt : TDateTime;
 begin
-  NSDatePickerCell(ACalendar.Handle).setDateValue(DateTimeToNSDate(ADateTime));
+  sec:= NSDatePickerCell(ACalendar.Handle).timeZone.secondsFromGMT;
+  sec:= sec * -1;
+  dt := IncSecond(ADateTime, sec);
+  NSDatePickerCell(ACalendar.Handle).setDateValue(DateTimeToNSDate(dt));
+//  NSDatePickerCell(ACalendar.Handle).setDateValue(DateTimeToNSDate(ADateTime));
 end;
 
 class function TCocoaWSCustomCalendar.HitTest(const ACalendar: TCustomCalendar; const APoint: TPoint): TCalendarPart;
CocoaWSDatePicker.diff (2,063 bytes)   
datetest.zip (113,333 bytes)

Dmitry Boyarintsev

2019-11-04 03:04

developer   ~0119035

please test and close if ok

Frank

2019-11-04 18:42

reporter   ~0119056

tested solution, thanks

Issue History

Date Modified Username Field Change
2019-11-03 15:52 Frank New Issue
2019-11-03 15:52 Frank File Added: CocoaWSDatePicker.diff
2019-11-03 15:52 Frank File Added: datetest.zip
2019-11-04 03:04 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2019-11-04 03:04 Dmitry Boyarintsev Status new => resolved
2019-11-04 03:04 Dmitry Boyarintsev Resolution open => fixed
2019-11-04 03:04 Dmitry Boyarintsev Fixed in Revision => 62187
2019-11-04 03:04 Dmitry Boyarintsev LazTarget => -
2019-11-04 03:04 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2019-11-04 03:04 Dmitry Boyarintsev Note Added: 0119035
2019-11-04 18:42 Frank Status resolved => closed
2019-11-04 18:42 Frank Note Added: 0119056