mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 12:40:33 +02:00
cocoa: changing how date conversion utilities work. Currently following the system calendar. bug #36252
git-svn-id: trunk@62187 -
This commit is contained in:
parent
2ddafa3c8b
commit
4f6399d3ef
@ -944,23 +944,50 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function DateTimeToNSDate(const aDateTime : TDateTime): NSDate;
|
function DateTimeToNSDate(const aDateTime : TDateTime): NSDate;
|
||||||
var
|
{var
|
||||||
ti : NSTimeInterval;
|
ti : NSTimeInterval;
|
||||||
d : NSDate;
|
|
||||||
begin
|
begin
|
||||||
ti := (aDateTime - EncodeDate(2001, 1, 1)) * SecsPerDay;
|
ti := (aDateTime - EncodeDate(2001, 1, 1)) * SecsPerDay;
|
||||||
d := NSDate.alloc.init;
|
ti := ti - double(NSTimeZone.localTimeZone.secondsFromGMT);
|
||||||
Result:= d.dateWithTimeIntervalSinceReferenceDate(ti);
|
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;
|
end;
|
||||||
|
|
||||||
function NSDateToDateTime(const aDateTime: NSDate): TDateTime;
|
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
|
begin
|
||||||
if aDateTime = nil then
|
if aDateTime = nil then
|
||||||
begin
|
begin
|
||||||
Result:= 0.0;
|
Result:= 0.0;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
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;
|
end;
|
||||||
|
|
||||||
function ControlTitleToStr(const ATitle: string): String;
|
function ControlTitleToStr(const ATitle: string): String;
|
||||||
|
Loading…
Reference in New Issue
Block a user