Page 1 of 2
Day of week
Posted: 08 March 2019, 4:23 AM
by FFMan
I must be doing something wrong, day of week for today returns as 7 when it's a friday. Using uk format notation for dates dd/mm/yyyy
Code: Select all
'test date
dim inYY as integer,byMonth as byte,byDay as byte
Call GetDate(inYY,byMonth,byDay)
debug.print byday;"/";byMonth;"/";inYY
'Check to see if we can rest tubes
byDOW=GetDayofWeek()
debug.print "DOW=";byDow
debug output:-
Process
8/3/2019
DOW=7
this is after i've set the clock via ntp
any ideas what i've done ?
Re: Day of week
Posted: 08 March 2019, 13:33 PM
by dkinzer
FFMan wrote:I must be doing something wrong, day of week for today returns as 7 when it's a friday.
No, it's a heretofore undiscovered bug in GetDayOfWeek().
There is an updated version of the ZBasic Library, v4.3.5, that corrects the problem. You can download just that part or get a whole new installer that contains that update plus an update to the compiler.
ZBasic Library v4.3.5:
http://www.zbasic.net/download/zlib/4.3/zlib_4-3-5.zip
Latest Installer:
http://www.zbasic.net/download/installe ... 4-3-22.exe
This won't fix the problem if you're using a VM-based device. I haven't checked yet but I suspect that the same problem exists there.
Posted: 12 March 2019, 12:33 PM
by FFMan
I seem to be getting this issue on the esp8266.
Running the same code on 328n gives dow=3 and on the esp8266 i get day of week=4 for 12/3/19
did the fix apply to both platforms ?
Posted: 12 March 2019, 14:26 PM
by dkinzer
FFMan wrote:I seem to be getting this issue on the esp8266. did the fix apply to both platforms ?
Yes. What is the timestamp on the file zlib/esp8266/lib/libesp8266.a in the ZBasic installation directory?
I'll try it here when I get some time.
Posted: 12 March 2019, 15:20 PM
by FFMan
it's 8/3/19 20:41 622kb
Posted: 13 March 2019, 7:47 AM
by dkinzer
I created a test program (attached) that iterates through all of the day numbers from 0 to &Hffff and calculates the DayOfWeek for each, comparing the result to the expected. No discrepancies are reported here when I build and run that app. Please try this on your end and report the result. If that works as expected then it is probably an issue with conversion between month/day/year and day number.
Posted: 13 March 2019, 12:17 PM
by FFMan
test completed ok
Starting
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................
Test completed
Posted: 13 March 2019, 16:10 PM
by dkinzer
I modified the test program (attached) to set the date to 12 March 2019, query the day of the week and display the result. I get the expected result:
Code: Select all
Starting
2019/3/12, DOW is 3 day number is 7375
Posted: 14 March 2019, 10:40 AM
by dkinzer
If the updated test program produces the correct result, I would encourage you to create a simple test program that demonstrates the problem that you observed. That way I can home in on the the underlying issue.
Posted: 14 March 2019, 12:49 PM
by FFMan
it doesn't compile:-
testDayOfWeek.bas:22: Error: function "GetDayNumber" requires at least 2 parameters, 0 provided
on the debug.print statement.
device is set to esp8266
have i gone wrong somewhere ?
Posted: 14 March 2019, 13:15 PM
by dkinzer
FFMan wrote:have i gone wrong somewhere ?
No, 'twas me. I forgot to update the archive before attaching it. A new version is attached.
The GetDayNumber() needs to be replaced with Register.RTCDay.
Posted: 14 March 2019, 15:48 PM
by FFMan
ok i get
Starting!
2019/3/12, DOW is 3 day number is 7375
which i same as you. i need to back to my examples and see if i can verify the issue and create a test case
I'll do that tomorrow
Posted: 15 March 2019, 13:45 PM
by FFMan
i'm still working through this but i can see why i get the discrepancy, it's due to the date being set for a different year, so the DOW is different.
The code in esp8266 client udp NTP example adjusts the epoch bu deducting 3629059200
Code i took from another example from zbasic.net contained this code and comment:-
Private Const DeltaZBasicNTP as UnsignedLong = 3124137600 ' seconds btw 1900/1/1 and 1999/1/1
I need to delve into this a bit more, but is it possible the offset used in the clientudp example is incorrect maybe as it only debug.print the time, whereas the other example I know sets the date correctly.
Will keep on it tomorrow
Posted: 15 March 2019, 17:38 PM
by dkinzer
FFMan wrote:is it possible the offset used in the clientudp example is incorrect maybe as it only debug.print the time, whereas the other example I know sets the date correctly.
Notwithstanding the comment in the UDP code, the 3,629,059,200 second adjustment shifts the year to 2015 (which was, not coincidentally I suspect, when the code was written).
The correct seconds offset between 01 Jan 1900 and 01 Jan 1999 is 3,124,137,600 (i.e. 36,159 days).
Posted: 16 March 2019, 0:27 AM
by FFMan
ok - that was the cause of the difference between the DOW on the platforms.
thanks Don all good now