Calculate the datenumber for the SUNDAY in week 1 of the specified year. The first parameter must specify a year, the output is a date number and is unified with second parameter. Increment the date number with 1 to get the date number of the Monday of week 1 of the year. The predicate day_of_week/2 also works with day-of-week numbers.
The rule for determining week number 1 of a year is: week 1 is the week of the new year which has a thursday that lies in the new year. So it is possible that the days in front of a thursday of week number 1 are in the previous year.
This predicate is located in the file 'datetime.txt', use ensure_loaded/1 to include this file.
see also: age/7 day_number/4 day_of_week/2 datetime module decode_date/4 decode_datetime/7 decode_time/4 encode_date/4 encode_datetime/7 encode_time/2 encode_time/3 encode_time/4 ensure_loaded/1 leap_year/1 length_month/3 monday_of_week/3 monday_of_week/5 next_week/4 num_weeks_in_year/2 prev_week/4 reverse_day_number/4 start_of_week/3
| Example | |
| first_week(1998, DateNum). | succeeds, DateNum = 729386 |
| first_week(1998, DateNum), decode_date(DateNum, Year, Month, Day). | succeeds and the calculated date of the sunday of week 1 of
1998 is 28 December 1997 DateNum = 729386 Year = 1997 Month = 12 Day = 28 |
| first_week(1999, DateNum), decode_date(DateNum, Year, Month, Day). | succeeds and the calculated date of the sunday of week 1 of
1999 is 3 January 1999 DateNum = 729757 Year = 1999 Month = 1 Day = 3 |
| Exceptions | |
| The Year parameter is not an integer | a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect argument |
| The DateNumber parameter is not an integer nor a variable | a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect argument |