without
lCalendar.timeZone := NSTimeZone.timeZoneWithAbbreviation('GMT');
without
lCalendar.timeZone := NSTimeZone.timeZoneWithAbbreviation('GMT');
On Island i get
2022-07-06 09:36:25.038775-0400 ConsoleApplication38[57853:7486236] 621355968000000000
2022-07-06 09:36:25.038815-0400 ConsoleApplication38[57853:7486236] 01/01/1970 00:00:00
On Toffee, with your fix, I get
2022-07-06 09:37:05.816520-0400 ConsoleApplication39[57941:7487421] 621355968000000000
2022-07-06 09:37:05.817509-0400 ConsoleApplication39[57941:7487421] dateTime 1970-01-01 04:00:00 +0000
and without it I get
2022-07-06 09:53:11.125340-0400 ConsoleApplication39[58912:7500971] dateTime 1970-01-01 08:00:00 +0000
it seems the proper fix would be not to drop the NSTimeZone.localTimeZone.secondsFromGMTForDate(dt)
, but to *add it rather than subtract it?
if I do that, I get
2022-07-06 09:56:08.538188-0400 ConsoleApplication39[59113:7503629] 621356112000000000
2022-07-06 09:56:08.541981-0400 ConsoleApplication39[59113:7503629] dateTime 1970-01-01 00:00:00 +0000
which matches Island.
Thatâs not the .ctor you are using here though. youâre using the .ctor you fixed yesterday, the one that takes ticks.
That said, this doesnât make sense with how NSDate works. just
var d := NSDate.dateWithTimeIntervalSince1970(Double(lTicks - RemObjects.Elements.RTL.DateTime.TicksTill1970) / TimeSpan.TicksPerSecond);
should be correct, as an NSDate has no time zone. so Iâm wondering if that is actually correct, and just a display issue and Log($"dateTime {dateTime}")
adds the 4:00:00 to adjust for my local time zone as displayâŚ
Hmm, no, its new DateTime(1970,1,1).Ticks
thats wrong. Your/our fix from yesterday broke that one
I was wondering about the display problems, I think NSLog converts it to local.
I was using https://tickstodatetime.azurewebsites.net/ as well.
var l1970 := new DateTime(1970,1,1);
Log($"l1970 {l1970}");
var lTicks := l1970.Ticks;
Log($"lTicks {lTicks}");
var lNewTicks := Int64(((l1970 as NSDate).timeIntervalSince1970) * TimeSpan.TicksPerSecond) + RemObjects.Elements.RTL.DateTime.TicksTill1970;
Log($"lNewTicks {lNewTicks}");
var lOldTicks := Int64(((l1970 as NSDate).timeIntervalSince1970 + NSTimeZone.localTimeZone.secondsFromGMTForDate(l1970)) * TimeSpan.TicksPerSecond) + RemObjects.Elements.RTL.DateTime.TicksTill1970;
Log($"lOldTicks {lOldTicks}");
2022-07-06 10:09:07.055483-0400 ConsoleApplication39[59930:7515505] l1970 1970-01-01 04:00:00 +0000
2022-07-06 10:09:07.055495-0400 ConsoleApplication39[59930:7515505] lTicks 621356112000000000
2022-07-06 10:09:07.055506-0400 ConsoleApplication39[59930:7515505] lNewTicks 621356112000000000
2022-07-06 10:09:07.055515-0400 ConsoleApplication39[59930:7515505] lOldTicks 621355968000000000
yeah, the old one was correct.
Your fix to constructor DateTime(aTicks: Int64);
was correct, the fix to property Ticks
was wrong.
with the Ticks one reverted, I get
2022-07-06 10:11:15.577827-0400 ConsoleApplication39[60097:7518019] 621355968000000000
2022-07-06 10:11:15.583356-0400 ConsoleApplication39[60097:7518019] dateTime 1970-01-01 00:00:00 +0000
on Toffee, matching (formatting aside) Island.
For all platforms but Island, i have also added two new helper properties
DateTime(System.DateTime.Now).IsUTC False
DateTime(System.DateTime.Now).OffsetToUTC 4
DateTime(System.DateTime.UtcNow).IsUTC True
DateTime(System.DateTime.UtcNow).OffsetToUTC 0
On Toffee these will always be true/zero, as every NSDate is UTC â an NSDate represents a fixed point in time agnostic of time zones.
On Cooper a Calendar has a specific time zone associated, so thatâs clean and simple.
On Echoes, a DateTime is either Local, UTC, or âunknownâ, but doesnât have a concrete timezone associated. So that flag (and ToUniversalTime) is used to determine the values.
On Island, DateTime has no concepts at all of a time zone, so some discussion is needed if that means (a) they ar wall UTC like on Cocoa or (b) they are all âunknownâ and itâs up to the user to keep track of what dates are Utc and which ones arenât⌠The presence of aTimeZone
parameters on many APIs would suggest the intent was/is the latter.
Dates are messy, huh?
Will you been doing a new zip distro build with all the changes ?
I merged them all, right now, so any build started after this will contain the fixes.
DateTimeTests.zip (2.2 MB)
It seems like it was one step forward and then a couple of steps back so I created a solution with some datetime tests.
Could you look at that ? i think the log output from both should be the same but they arenât. Since Im coding against the rtl, using darwin or toffee it shouldnât matter should it ?
It shoudlnât, if there werenât any bugs, no.
Iâll have a look. This with the latest Elements RTL build last night, yes?
Yes it is
Toffee:
~> Process ToffeeConsoleApplication started testing, took 0.223.
2022-07-07 09:07:02.414364-0400 ToffeeConsoleApplication[18246:8298739] 637927816224121360
Test Succeeded: Test Succeeded. (method UtcTicks))
2022-07-07 09:07:02.414498-0400 ToffeeConsoleApplication[18246:8298739] 637927816224144800
2022-07-07 09:07:02.435783-0400 ToffeeConsoleApplication[18246:8298739] 2022-07-07 09:07:02 +0000
Test Succeeded: Test Succeeded. (method TicksToDateTime))
2022-07-07 09:07:02.436334-0400 ToffeeConsoleApplication[18246:8298739] 1657184822.435901
Test Succeeded: Test Succeeded. (method Diff))
2022-07-07 09:07:02.436509-0400 ToffeeConsoleApplication[18246:8298739] 16571848224364760
Test Succeeded: Test Succeeded. (method TicksDiff))
2022-07-07 09:07:02.436784-0400 ToffeeConsoleApplication[18246:8298739] 621355968000000000
Test Succeeded: Test Succeeded. (method TicksSince1970))
2022-07-07 09:07:02.437112-0400 ToffeeConsoleApplication[18246:8298739] 1970-01-01 00:00:00 +0000
Test Succeeded: Test Succeeded. (method Ticks1970ToDateTime))
2022-07-07 09:07:02.437222-0400 ToffeeConsoleApplication[18246:8298739] 1
Test Succeeded: Test Succeeded. (method IsUtc))
~> Process ToffeeConsoleApplication terminated with exit code 0. Ran for 19.107
Island
~> Process IslandConsoleApplication started, took 0.828.
Tests.DateTimeTests started
2022-07-07 09:08:22.704841-0400 IslandConsoleApplication[18330:8300141] 637927961020007047
UtcTicks finished. State: Succeeded.
2022-07-07 09:08:22.704948-0400 IslandConsoleApplication[18330:8300141] 637927961020007049
2022-07-07 09:08:22.705573-0400 IslandConsoleApplication[18330:8300141] 07/07/2022 01:08:22
TicksToDateTime finished. State: Succeeded.
2022-07-07 09:08:22.705635-0400 IslandConsoleApplication[18330:8300141] 16571993020007
Diff finished. State: Succeeded.
2022-07-07 09:08:22.705652-0400 IslandConsoleApplication[18330:8300141] 16571993020007056
TicksDiff finished. State: Succeeded.
2022-07-07 09:08:22.706076-0400 IslandConsoleApplication[18330:8300141] 621355968000000000
TicksSince1970 finished. State: Succeeded.
2022-07-07 09:08:22.706268-0400 IslandConsoleApplication[18330:8300141] 01/01/1970 00:00:00
Ticks1970ToDateTime finished. State: Succeeded.
Tests.DateTimeTests finished. State: Succeeded.
======================================
6 succeeded, 0 failed, 0 skipped, 0 untested
~> Process IslandConsoleApplication terminated with exit code 0. Ran for 1.744
I;'m not sure why Island doesnt emit proper messages (Toffee does) but all tests succeed, on both platforms. What problem am I looking for?
Oh wait, none of your âtestâ actually have any asserts? how is this code supposed to test anything, if it doesnât have any checks?
method Ticks1970ToDateTime;
begin
var dateTime := new DateTime(new DateTime(1970,1,1).Ticks);
Log($'{dateTime}');
end;
Yes sorry, I couldnt think of a good way to assert anything. I was just running both and eyeballing the results
Well, Iâll need to know what I should look for, if you want me to fix anything
Whatever Im logging should be the same
Well, no.
UtcNow changes between runs
thew tests that donât use UtcNow do look the same for meâŚ
2022-07-07 10:02:47.297882-0400 IslandConsoleApplication[22154:8350324] 621355968000000000
2022-07-07 10:02:47.297914-0400 IslandConsoleApplication[22154:8350324] 01/01/1970 00:00:00
vs
2022-07-07 10:02:51.941739-0400 ToffeeConsoleApplication[22159:8350393] 621355968000000000
Test Succeeded: Test Succeeded. (method TicksSince1970))
2022-07-07 10:02:51.941833-0400 ToffeeConsoleApplication[22159:8350393] 1970-01-01 00:00:00 +0000
FTR., it turns out only the Test Succeeded messages are not showing properly for Island. test failures come thru and show inline, fine. Iâll investigate why, though I consider this largely a cosmetic issue.