cocoa: changing how date conversion utilities work. Currently following the system calendar. bug #36252

git-svn-id: trunk@62187 -
This commit is contained in:
dmitry 2019-11-04 02:03:45 +00:00
parent 2ddafa3c8b
commit 4f6399d3ef

View File

@ -944,23 +944,50 @@ begin
end;
function DateTimeToNSDate(const aDateTime : TDateTime): NSDate;
var
{var
ti : NSTimeInterval;
d : NSDate;
begin
ti := (aDateTime - EncodeDate(2001, 1, 1)) * SecsPerDay;
d := NSDate.alloc.init;
Result:= d.dateWithTimeIntervalSinceReferenceDate(ti);
ti := ti - double(NSTimeZone.localTimeZone.secondsFromGMT);
Result := NSDate.dateWithTimeIntervalSinceReferenceDate(ti);}
var
cmp : NSDateComponents;
y,m,d: Word;
h,s,z: Word;
begin
cmp := NSDateComponents.alloc.init;
DecodeDate(ADateTime, y,m,d);
cmp.setYear(y);
cmp.setMonth(m);
cmp.setDay(d);
DecodeTime(ADateTime, h, m, s,z);
cmp.setHour(h);
cmp.setMinute(m);
cmp.setSecond(s);
Result := NSCalendar.currentCalendar.dateFromComponents(cmp);
end;
function NSDateToDateTime(const aDateTime: NSDate): TDateTime;
var
cmp : NSDateComponents;
mn : TdateTime;
const
convFlag = NSYearCalendarUnit
or NSMonthCalendarUnit
or NSDayCalendarUnit
or NSHourCalendarUnit
or NSMinuteCalendarUnit
or NSSecondCalendarUnit;
begin
if aDateTime = nil then
begin
Result:= 0.0;
Exit;
end;
Result:= aDateTime.timeIntervalSince1970 / SecsPerDay + EncodeDate(1970, 1, 1);
cmp := NSCalendar.currentCalendar.components_fromDate(convFlag, aDateTime);
TryEncodeDate(cmp.year, cmp.month, cmp.day, Result);
TryEncodeTime(cmp.hour, cmp.minute, cmp.second, 0, mn);
Result := Result + mn;
end;
function ControlTitleToStr(const ATitle: string): String;