Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c26467e1edabc1a96045998891733b911dfd2062
Ticket: 1160695fffffffffffffffffffffffffffffffff
clock scan "next wed" is wrong?
User & Date: kennykb on 2005-04-14 03:44:54
Changes

  1. icomment:
    Logged In: YES 
    user_id=99768
    
    As I started writing a TIP for an enhancement to
    [clock add] to handle the case of "next wednesday"
    by a syntax like [clock add $date 1 Wednesday], I
    realized that such syntax, if localised, would open
    a can of worms in those locales where months and
    weekdays can have the same names (Mandarin Chinese
    has this problem, because both months and weekdays
    are simply known by their numbers.)
    
    But in hacking at the implementation, I realized
    that there is a (slightly awkward) way of
    approaching the problem:
    
      # Find the start of the current date
    
      set date [clock scan 0000 -format %H%m]
    
      # Find the start of Wednesday of the current
      # week, and advance to "next Wednesday"
    
      set wed [clock scan Wednesday \
                    -base $date -format %a]
      if { $wed <= $date } {
          set wed [clock add $wed 1 week]
      }
    
      # Alternatively, find the start of Wednesday
      # of the current week, and retreat to
      # "last Wednesday"
    
      set wed [clock scan Wednesday \
                     -base $date -format %a]
      if { $wed >= $date } {
          set wed [clock add $wed -1 week]
      }
    
    While this is a trifle more verbose than a simple
    [clock scan "next Wednesday"], it has the
    advantage that it will be correctly localised
    automatically (replace Wednesday with a day name
    in the locale specified by the -locale argument to
    [clock scan], and it'll still work), and it
    needs no additional magic in the 8.5 [clock]
    command to make it go.
    
    Is this usage acceptable?
    
    
    
    
  2. login: "kennykb"
  3. mimetype: "text/plain"
  4. username: "kennykb"