Date Validation using XOJO.Core.Date

I am trying to validate a date entry with the following code:

[code]Using Xojo.Core
dim mm As Integer = Val(pcMM.Text)
dim dd As Integer = Val(pcDD.Text)
dim yy As Integer = Val(pcYY.Text)

dim wDate as new Date(yy, mm, dd, TimeZone.Current)

if (wDate.Month <> mm) or (wDate.Day <> dd) or (wDate.Year <> yy) then
return false
else
return true
end
[/code]

When trying to validate February 31, 2019 it comes back invalid on Mac OS, but valid on Windows.
Using the debugger, I see the value of wDate.Month and wDate.Day are 3 and 31 respectively on the Mac. On Windows, the values are 2 and 31.

The only way I can validate on Windows is to change my code to insert the following lines just before doing the validity comparison.

dim TextDate As Text = wDate.ToText wDate = wDate.FromText(TextDate)

This is easy enough, but seems silly. What am I missing?

It looks like there are some differences between macOS and Windows/Linux for some Xojo.Core.Date feedback://showreport?report_id=50899, I’m not saying this is the issue here, just something I found related to Xojo.Core.Date and difference between mac and windows.

Edit: feedback://showreport?report_id=46855 also different between mac and windows

This looks very related. Guess I should have checked Feedback before posting.

Seems on Windows, the Date object stores whatever you give it but doesn’t try to make sense of it until you manipulate it in some way. Maybe we need a feedback case to correct the documentation. :slight_smile: