Recently in thread1551-1244574 a challenge was issued for code to determine the correct ISO week for any date. I thought about it for a while, then decided to see how easy that would be using FoxPro.
Since it is a worldwide standard, I figured that many of you need to be in compliance within your FoxPro code. I don't see me ever needing to determine ISO weeks, but I am sure many of you need a simple UDF like this in your arsenal of handy functions.
This link (http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm) has extensive information about ISO weeks. I did hundreds of tests using the 15 possible calendars as my benchmark. As of this time the following code seems to be error-free and working as it should.
There are three functions here. ISOWEEK() determines which ISO week (1 to 53) that a specific date falls in. ISOWK1() returns the actual starting date of an ISO year, always the Monday before the first Thursday of the common year. And ISOWKSTART() returns the actual date that the ISO week begins with, always the Monday beginning the ISO week of the date in question.
Note particularly that ISOWK1() does NOT return the starting date of an ISO year containing a specific date. Dates in any specific common year will fall into 1, 2, or 3 different ISO years. Most common years have dates that fall into 2 different ISO years. A few years have dates that all fall into only one ISO year, and a few have dates in 3 different ISO years.
These functions use American dates, however with minor changes they should work properly for any date configuration.
All three functions default to the current date that your computer is set to when no date is passed to the function. They will only work correctly if nothing is passed or a CORRECT date is passed. There is no error checking, so if you pass anything other than a date, you will get weird results.
FUNCTION ISOWEEK PARAMETERS qDate PRIVATE ALL LIKE z*