Clock command

Leap
Leap in Tcl

Using the clock command approach may be considered a "cheat" for this exercise.

set timestamp [clock scan "$year-02-28" -format {%Y-%m-%d}]
set next_day [clock add $timestamp 1 day]
set day [clock format $next_day -format {%d}]
expr {$day == 29}

By adding a day to February 28th for the year, you can see if the new day is the 29th or the 1st. If it is the 29th, then the year is a leap year.

Reference: clock manual page

Note

Under the hood, Tcl does have an internal helper function to test for leap years.

11th Dec 2024 · Found it useful?