By knowing the date, calculate the day number in a certain year and the week number in the year:
M.Y.: if the week number "0" appears, it means that it's the last week of the previous year or the first week of the following year.
By knowing the day number in the year, find the date:
The functions to calculate the day number in a certain year were got from: Meeus Jean, Astronomia con il computer, Hoepli, Milano, 1990.