Day of week

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Day of week

Post 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 ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Day of week

Post 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.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post 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 ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

it's 8/3/19 20:41 622kb
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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.
Attachments
TestDayOfWeek.zip
(793 Bytes) Downloaded 330 times
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

test completed ok

Starting
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................
Test completed
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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
Attachments
TestDayOfWeek.zip
(830 Bytes) Downloaded 344 times
- Don Kinzer
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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.
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post 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 ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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.
Attachments
TestDayOfWeek.zip
(835 Bytes) Downloaded 325 times
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post 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
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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).
- Don Kinzer
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post by FFMan »

ok - that was the cause of the difference between the DOW on the platforms.

thanks Don all good now
Post Reply