I have to design a calendar window that displays dates for each days of a month much like iCal.
So I built a canvas subclass that takes a xojo.core.date as parameter and then calculates a few things to determine the sizes:
[code] dim startdate as new xojo.core.date(CurrentDate.Year, CurrentDate.Month, 1, xojo.core.timezone.Current) // 1st of the month
dim d1 as integer = startdate.germandayofmonth // day of month rotated one left we start the weeks here with Monday. Need this later.
dim enddate as xojo.core.date = startdate + new xojo.Core.DateInterval(0, 1) // First of the next month
enddate = enddate - new xojo.Core.DateInterval(0, 0, 1) // and one day back to get the last day of the current month.
dim d2 as integer = enddate.germandayofmonth
dim dif as xojo.Core.DateInterval = enddate - startdate
dim weeks as integer = dif.Days/7 // how many weeks did we have in the month?
dim rest as integer = dif.days mod 7 // and is there a rest?
if rest > 0 then weeks = weeks + 1 // if so, we need to draw one more week line.[/code]
This all works nicely, except for this month. We have a leap year, so I expected enddate would be 2-29-2016. Its not. Xojo tells me we have no leap year and jumps to the 28th.
Is there any way I can fix this? Thanks a lot!