• Bug in widget::calendar

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Wed Nov 5 12:39:43 2025
    From Newsgroup: comp.lang.tcl

    I have a Tcl/Tk 9 application which has a form with a widget::dateentry.
    When I have a date of 12/11/2025 (with format %d/%m/%Y) and click it
    the widget::calendar pops up as expected showing November 2025.
    If I then click the small right arrow (advance one month) it correctly
    shows me December 2025.
    If I then click the small right arrow a second time I get this error:

    unable to convert input string: invalid month
    unable to convert input string: invalid month
    while executing
    "clock scan "[incr month]/1/$year 1 day ago""
    (procedure "::widget::calendar::Snit_methodnumberofdays" line 8)
    invoked from within
    "$self numberofdays $data(month) $data(year)"
    (procedure "::widget::calendar::Snit_methodadjust" line 44)
    invoked from within
    ".mf.mpw.lpw.iw#9.titlebar.date.__drop.calendar adjust 0 1 0"
    ("uplevel" body line 1)
    invoked from within
    "uplevel 1 [linsert $args 0 $self]"
    invoked from within
    "::snit::RT.CallInstance ::widget::calendar::Snit_inst10 adjust 0 1 0"
    (command bound to event)

    I am using tklib-0.9.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Wed Nov 5 15:18:47 2025
    From Newsgroup: comp.lang.tcl

    * Mark Summerfield <m.n.summerfield@gmail.com>
    | I have a Tcl/Tk 9 application which has a form with a widget::dateentry.
    | When I have a date of 12/11/2025 (with format %d/%m/%Y) and click it
    | the widget::calendar pops up as expected showing November 2025.
    | If I then click the small right arrow (advance one month) it correctly
    | shows me December 2025.
    | If I then click the small right arrow a second time I get this error:

    | unable to convert input string: invalid month
    | unable to convert input string: invalid month
    | while executing
    | "clock scan "[incr month]/1/$year 1 day ago""
    | (procedure "::widget::calendar::Snit_methodnumberofdays" line 8)
    | invoked from within
    | "$self numberofdays $data(month) $data(year)"
    | (procedure "::widget::calendar::Snit_methodadjust" line 44)
    | invoked from within
    | ".mf.mpw.lpw.iw#9.titlebar.date.__drop.calendar adjust 0 1 0"
    | ("uplevel" body line 1)
    | invoked from within
    | "uplevel 1 [linsert $args 0 $self]"
    | invoked from within
    | "::snit::RT.CallInstance ::widget::calendar::Snit_inst10 adjust 0 1 0"
    | (command bound to event)

    | I am using tklib-0.9.

    Can't reproduce here with tk 8.6.17 and tklib-0.9 (trunk 2025-10-22).

    % package require widget::dateentry
    0.98
    % pack [widget::dateentry .d -dateformat %d/%m/%Y]

    I can click the arrows (big and small) any number of times in any
    direction, no error.

    I'd add some printout in tklib/widget/calendar.tcl, method numberofdays,
    to see the variables when entering the function.

    method numberofdays {month year} {
    puts stderr "method numberofdays: 1/ month {$month} year {$year}"
    if {$month == 12} {set month 0; incr year}
    puts stderr "method numberofdays: 2/ month {$month} year {$year}"
    clock format [clock scan "[incr month]/1/$year 1 day ago"] -format %d
    }

    HTH
    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Emiliano@emil.g@example.invalid to comp.lang.tcl on Wed Nov 5 12:22:25 2025
    From Newsgroup: comp.lang.tcl

    On Wed, 5 Nov 2025 12:39:43 -0000 (UTC)
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:

    I have a Tcl/Tk 9 application which has a form with a widget::dateentry.
    When I have a date of 12/11/2025 (with format %d/%m/%Y) and click it
    the widget::calendar pops up as expected showing November 2025.
    If I then click the small right arrow (advance one month) it correctly
    shows me December 2025.
    If I then click the small right arrow a second time I get this error:

    unable to convert input string: invalid month
    unable to convert input string: invalid month
    while executing
    "clock scan "[incr month]/1/$year 1 day ago""
    (procedure "::widget::calendar::Snit_methodnumberofdays" line 8)
    invoked from within
    "$self numberofdays $data(month) $data(year)"
    (procedure "::widget::calendar::Snit_methodadjust" line 44)
    invoked from within
    ".mf.mpw.lpw.iw#9.titlebar.date.__drop.calendar adjust 0 1 0"
    ("uplevel" body line 1)
    invoked from within
    "uplevel 1 [linsert $args 0 $self]"
    invoked from within
    "::snit::RT.CallInstance ::widget::calendar::Snit_inst10 adjust 0 1 0"
    (command bound to event)

    I am using tklib-0.9.

    The problem is the validating nature (by default) of the [clock scan]
    command in Tcl 9.

    See tklib's ticket https://core.tcl-lang.org/tklib/tktview/c800a75eb5
    --
    Emiliano
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Wed Nov 5 17:08:08 2025
    From Newsgroup: comp.lang.tcl

    * Emiliano <emil.g@example.invalid>
    | > unable to convert input string: invalid month
    | > unable to convert input string: invalid month
    | > while executing
    | > "clock scan "[incr month]/1/$year 1 day ago""
    | > (procedure "::widget::calendar::Snit_methodnumberofdays" line 8)
    | > invoked from within
    | > "$self numberofdays $data(month) $data(year)"
    | > (procedure "::widget::calendar::Snit_methodadjust" line 44)
    | > invoked from within
    | > ".mf.mpw.lpw.iw#9.titlebar.date.__drop.calendar adjust 0 1 0"
    | > ("uplevel" body line 1)
    | > invoked from within
    | > "uplevel 1 [linsert $args 0 $self]"
    | > invoked from within
    | > "::snit::RT.CallInstance ::widget::calendar::Snit_inst10 adjust 0 1 0"
    | > (command bound to event)
    | >
    | > I am using tklib-0.9.

    | The problem is the validating nature (by default) of the [clock scan]
    | command in Tcl 9.

    | See tklib's ticket https://core.tcl-lang.org/tklib/tktview/c800a75eb5

    Out of curiosity: what is the incoming month which triggers the error?

    The proposed patch makes sense only if the incoming month would be > 12
    (if it is 12, the code is effectively the same as before). And in that
    case IMHO the caller should be fixed to not pass an invalid month.

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Wed Nov 5 17:53:56 2025
    From Newsgroup: comp.lang.tcl

    On Wed, 5 Nov 2025 12:22:25 -0300, Emiliano wrote:

    On Wed, 5 Nov 2025 12:39:43 -0000 (UTC)
    Mark Summerfield <m.n.summerfield@gmail.com> wrote:

    I have a Tcl/Tk 9 application which has a form with a widget::dateentry.
    When I have a date of 12/11/2025 (with format %d/%m/%Y) and click it
    the widget::calendar pops up as expected showing November 2025.
    If I then click the small right arrow (advance one month) it correctly
    shows me December 2025.
    If I then click the small right arrow a second time I get this error:

    unable to convert input string: invalid month
    unable to convert input string: invalid month
    while executing
    "clock scan "[incr month]/1/$year 1 day ago""
    (procedure "::widget::calendar::Snit_methodnumberofdays" line 8)
    invoked from within
    "$self numberofdays $data(month) $data(year)"
    (procedure "::widget::calendar::Snit_methodadjust" line 44)
    invoked from within
    ".mf.mpw.lpw.iw#9.titlebar.date.__drop.calendar adjust 0 1 0"
    ("uplevel" body line 1)
    invoked from within
    "uplevel 1 [linsert $args 0 $self]"
    invoked from within
    "::snit::RT.CallInstance ::widget::calendar::Snit_inst10 adjust 0 1 0"
    (command bound to event)

    I am using tklib-0.9.

    The problem is the validating nature (by default) of the [clock scan]
    command in Tcl 9.

    See tklib's ticket https://core.tcl-lang.org/tklib/tktview/c800a75eb5

    Thank you. I tried your patch and that bug no longer occurs.
    --- Synchronet 3.21a-Linux NewsLink 1.2