My Environment:
ZX24a v2.6.1
Zbasic IDE v1.4.5
Compiler version: v2.6.4
I'm having a problem setting the date on the last day of certain months. The PutDate() command fails to set the date correctly on August the 31st of every year. It also fails on Feb 29th and Dec 31st in leap years.
PutDate(2008,2,29) Sets the date to 2008/3/1
PutDate(2008,8,31) Sets the date to 2008/9/1
PutDate(2008,12,31) Sets the date to 2009/1/1
PutDate(2009,8,31) Sets the date to 2009/9/1
PutDate(2010,8,31) Sets the date to 2010/9/1
PutDate(2011,8,31) Sets the date to 2011/9/1
PutDate(2012,2,29) Sets the date to 2012/3/1
PutDate(2012,8,31) Sets the date to 2012/9/1
PutDate(2012,12,31) Sets the date to 2013/1/1
Also...
The sub GetDate(Y,M,D,DayNumber) returns unexpceted results.
Note that August 31st is missing.
GetDate(Y,M,D,3893) returns 2009/8/29
GetDate(Y,M,D,3894) returns 2009/8/30
GetDate(Y,M,D,3895) returns 2009/9/1
GetDate(Y,M,D,3896) returns 2009/9/2
And...
Note that DayNumbers 3346 and 3347 BOTH return the same date.
GetDate(Y,M,D,3345) returns 2008/2/28
GetDate(Y,M,D,3346) returns 2008/3/1
GetDate(Y,M,D,3347) returns 2008/3/1
GetDate(Y,M,D,3348) returns 2008/3/2
I don't have a second ZX24a available so I can't determine if this is a chip problem or a ZBasic anomaly. Has anyone else noticed this problem?
Don
Problem With PutDate() and GetDate()
Re: Problem With PutDate() and GetDate()
The problems you mentioned have been confirmed and exist in all ZX devices. We believe that we have resolved the problems and we should have an update available soon.Don_Auld wrote:I'm having a problem setting the date on the last day of certain months.
The September problem exists both for converting a date to a day number and vice versa. The other problems only occur when converting from a day number to a date.
Last edited by dkinzer on 03 November 2008, 10:29 AM, edited 1 time in total.
- Don Kinzer
Re: Problem With PutDate() and GetDate()
Although we have not yet run the entire testsuite, you can try the release candidate for the ZX-24a containing the changes, available at:dkinzer wrote:We believe that we have resolved the problems and we should have an update available soon.
http://www.zbasic.net/download/zvm/2.6/zx24a_2-6-2.zvm
The test code below checks for proper conversion both directions for all supported dates; 1999-01-01 (day number 0) to 2178-06-06 (day number 65535).
Code: Select all
Dim daysInMonth as ByteVectorData({ 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 })
Sub Main()
Dim year as UnsignedInteger, dayNum as UnsignedInteger
Dim month as Byte, day as Byte, count as Byte
dayNum = 0
count = 0
' check all years in the supported day number range
For year = 1999 to 2178
' update the progress indicator
Debug.Print "*";
count = count + 1
If (count >= 75) Then
Debug.Print
count = 0
End If
' check each month of the year
For month = 1 to 12
' determine the last day of the current month
Dim lastDay as Byte
If (month <> 2) Then
lastDay = daysInMonth(month)
ElseIf ((year Mod 4) <> 0) Or (((year Mod 100) = 0) And ((year Mod 400) <> 0)) Then
lastDay = 28
Else
lastDay = 29
End If
' check each day of the month
For day = 1 to lastDay
' see if the year/month/day is converted to the correct day number
Call PutDate(year, month, day)
If (Register.RTCDay <> dayNum) Then
Debug.Print
Debug.Print year; "-";
Debug.Print Right("0" & CStr(month), 2); "-";
Debug.Print Right("0" & CStr(day), 2); " --> day #"; Register.RTCDay;
Debug.Print " s/b "; dayNum
End If
' see if the day number is converted back correctly
Dim y as UnsignedInteger, m as Byte, d as Byte
Call GetDate(y, m, d)
If ((y <> year) Or (m <> month) Or (d <> day)) Then
Debug.Print
Debug.Print "day #"; dayNum; " --> ";
Debug.Print y; "-";
Debug.Print Right("0" & CStr(m), 2); "-";
Debug.Print Right("0" & CStr(d), 2);
Debug.Print " s/b ";
Debug.Print year; "-";
Debug.Print Right("0" & CStr(month), 2); "-";
Debug.Print Right("0" & CStr(day), 2)
End If
' move to the next day number, check for wrap around
dayNum = dayNum + 1
If (dayNum = 0) Then
Exit For
End If
Next day
' check for day number wrap around
If (dayNum = 0) Then
Exit For
End If
Next month
Next year
Debug.Print
Debug.Print "Done"
End Sub
- Don Kinzer