/*
This program determines the day of the week for January 1st of a given year.
Approach:
---------
PHP provides built‑in date/time handling through the DateTime class:
- new DateTime("YYYY-MM-DD") : constructs a calendar date
- format("l") : returns the full weekday name (e.g., "Thursday")
This avoids manual calendar arithmetic and uses efficient built‑in routines.
*/
/* Convert a DateTime object's weekday to a readable string */
function weekdayName(DateTime $dt): string {
return $dt->format("l"); // "Monday", "Tuesday", ..., "Sunday"
}
/* Compute weekday of January 1st for a given year */
function jan1Weekday(int $year): string {
$date = new DateTime("$year-01-01"); // January 1st of given year
return weekdayName($date);
}
$year = 2026;
$result = jan1Weekday($year);
echo "January 1st, $year falls on a $result.\n";
/*
run:
January 1st, 2026 falls on a Thursday.
*/