cmdr
Check-in [1f24482658]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Extended v-type "time" to accept positive integers as seconds in epoch, above iso8601 timestamps. Bumped to version 1.1
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1f24482658327acf187fb05e0673774b8c922e46
User & Date: andreask 2015-07-15 23:31:48
Context
2015-11-03
17:27
history - Added help for the entire ensemble. Version bumped to 0.2. check-in: eed0a736d5 user: andreask tags: trunk
2015-07-15
23:31
Extended v-type "time" to accept positive integers as seconds in epoch, above iso8601 timestamps. Bumped to version 1.1 check-in: 1f24482658 user: andreask tags: trunk
23:30
Fix comment ref to tested v-type check-in: 4251025187 user: andreask tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to doc/cmdr_vt_time.man.

     8      8   [require cmdr::validate::common]
     9      9   [require cmdr::validate::time]
    10     10   [titledesc [vset TITLE_VT_TIME]]
    11     11   [description]
    12     12   [include parts/welcome.inc]
    13     13   
    14     14   [para] This package provides the validation type
    15         -[cmd ::cmdr::validate::time] which accepts timestamps in ISO 8601
    16         -syntax.
           15  +[cmd ::cmdr::validate::time] which accepts timestamps in both ISO 8601
           16  +syntax and as epoch values, i.e. positive integer seconds since the
           17  +beginning of unix time.
    17     18   
    18         -[para] The internal representation is the epoch for the validated
    19         -input.
           19  +[para] The internal, canonical representation is the epoch for the
           20  +validated input.
    20     21   
    21     22   [para] The type has no input completion.
    22     23   
    23     24   [para] The details of the exported standard API can be found in
    24     25   [term [vset TITLE_DEV_VT]]. The chosen default is "now".
    25     26   
    26     27   [para] A single non-standard method is provided:
    27     28   
    28     29   [list_begin definitions][comment {-- begin api definitions --}]
    29     30   [comment {- - -- --- ----- -------- ------------- ---------------------}]
    30     31   [call [cmd ::cmdr::validate::time] [method 2external] [arg epoch]]
    31     32   
    32         -This method converts the epoch of a time to the form %H:%M:%S and
    33         -returns the conversion result as its own.
           33  +This method converts the epoch of a time to the form
           34  +[const %Y-%m-%dT%H:%M:%S] and returns the conversion result as its own.
    34     35   
    35     36   [comment {- - -- --- ----- -------- ------------- ---------------------}]
    36     37   [list_end][comment {-- end api definitions --}]
    37     38   
    38     39   [include parts/feedback.inc]
    39     40   [manpage_end]

Changes to vt_time.tcl.

     1      1   ## -*- tcl -*-
     2      2   # # ## ### ##### ######## ############# #####################
     3      3   ## CMDR - Validate::Time - Supporting validation type - iso times.
     4      4   
     5      5   # @@ Meta Begin
     6         -# Package cmdr::validate::time 1
            6  +# Package cmdr::validate::time 1.1
     7      7   # Meta author   {Andreas Kupries}
     8      8   # Meta location https://core.tcl.tk/akupries/cmdr
     9      9   # Meta platform tcl
    10         -# Meta summary     Standard parameter validation type for times (down to seconds)
    11         -# Meta description Standard parameter validation type for times (down to seconds)
           10  +# Meta summary     Standard parameter validation type for timestamps (down to seconds)
           11  +# Meta description Standard parameter validation type for timestamps (down to seconds)
    12     12   # Meta subject {command line}
    13     13   # Meta require {Tcl 8.5-}
    14     14   # Meta require {cmdr::validate::common 1.2}
    15     15   # Meta require debug
    16     16   # Meta require debug::caller
    17     17   # Meta require try
    18     18   # Meta require clock::iso8601
................................................................................
    50     50   # # ## ### ##### ######## ############# #####################
    51     51   
    52     52   debug define cmdr/validate/time
    53     53   debug level  cmdr/validate/time
    54     54   debug prefix cmdr/validate/time {[debug caller] | }
    55     55   
    56     56   # # ## ### ##### ######## ############# #####################
    57         -## Times as parsed by clock::iso86
           57  +## Times as parsed by clock::iso8601
    58     58   
    59     59   proc ::cmdr::validate::time::2external {x}  {
    60     60       debug.cmdr/validate/time {}
    61         -    return [clock format $x -format {%H:%M:%S}]
           61  +    return [clock format $x -format {%Y-%m-%dT%H:%M:%S}]
    62     62   }
    63     63   
    64     64   proc ::cmdr::validate::time::release  {p x} { return }
    65     65   proc ::cmdr::validate::time::default  {p}  {
    66     66       debug.cmdr/validate/time {}
    67     67       # Today.
    68     68       return [clock seconds]
................................................................................
    71     71       debug.cmdr/validate/time {} 10
    72     72       # No completion.
    73     73       return {}
    74     74   }
    75     75   proc ::cmdr::validate::time::validate {p x} {
    76     76       debug.cmdr/validate/time {}
    77     77       try {
    78         -	# TODO: error code in clock::iso8601.
    79         -	set epoch [clock::iso8601 parse_time $x]
           78  +	if {[string is integer -strict $x] && ($x >= 0)} {
           79  +	    # Integer, direct epoch
           80  +	    set epoch $x
           81  +	} else {
           82  +	    # TODO: error code in clock::iso8601.
           83  +	    set epoch [clock::iso8601 parse_time $x]
           84  +	}
    80     85       } on error {e o} {
    81         -	fail $p TIME "an ISO8601 time" $x
           86  +	fail $p TIME "an ISO8601 time or epoch" $x
    82     87       } 
    83     88       return $epoch
    84     89   }
    85     90   
    86     91   # # ## ### ##### ######## ############# #####################
    87     92   ## Ready
    88         -package provide cmdr::validate::time 1
           93  +package provide cmdr::validate::time 1.1
    89     94   return