mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-30 20:30:41 +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;
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user