Calculating week number

from Pawel Soltysinski

The only thing I need to update is week number, since in EU there is ISO week number norm, which is not equal to Date.WeekOfYear in Xojo. ISO week date - Wikipedia

if anyone interested, here’s my method for it:

Public Function ISOWeekNumber(extends dt as date) As integer
  // ISO 8601 week number
  // https://en.wikipedia.org/wiki/ISO_week_date
  
  var dow,woy as UInt8
  
  dow=dt.DayOfWeek-1
  if dow=0 then dow=7
  woy=Floor((10+dt.DayOfYear-dow)/7)
  
  if woy=0 then
    var dp as new date (dt.Year-1,12,31)
    dow=dp.DayOfWeek-1
    if dow=0 then dow=7
    woy=Floor((10+dp.DayOfYear-dow)/7)
  elseif woy=53 then
    var dp as new date (dt.Year+1,1,1)
    dow=dp.DayOfWeek
    if dow<6 and dow>1 then woy=1
  end if
  
  Return woy
  
End Function

source nov 2022