cmdr
Check-in [1f24482658]
Not logged in

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 Unified Diffs Ignore Whitespace Patch

Changes to doc/cmdr_vt_time.man.

8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[require cmdr::validate::common]
[require cmdr::validate::time]
[titledesc [vset TITLE_VT_TIME]]
[description]
[include parts/welcome.inc]

[para] This package provides the validation type
[cmd ::cmdr::validate::time] which accepts timestamps in ISO 8601
syntax.


[para] The internal representation is the epoch for the validated
input.

[para] The type has no input completion.

[para] The details of the exported standard API can be found in
[term [vset TITLE_DEV_VT]]. The chosen default is "now".

[para] A single non-standard method is provided:

[list_begin definitions][comment {-- begin api definitions --}]
[comment {- - -- --- ----- -------- ------------- ---------------------}]
[call [cmd ::cmdr::validate::time] [method 2external] [arg epoch]]

This method converts the epoch of a time to the form %H:%M:%S and
returns the conversion result as its own.

[comment {- - -- --- ----- -------- ------------- ---------------------}]
[list_end][comment {-- end api definitions --}]

[include parts/feedback.inc]
[manpage_end]







|
|
>

|
|












|
|






8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[require cmdr::validate::common]
[require cmdr::validate::time]
[titledesc [vset TITLE_VT_TIME]]
[description]
[include parts/welcome.inc]

[para] This package provides the validation type
[cmd ::cmdr::validate::time] which accepts timestamps in both ISO 8601
syntax and as epoch values, i.e. positive integer seconds since the
beginning of unix time.

[para] The internal, canonical representation is the epoch for the
validated input.

[para] The type has no input completion.

[para] The details of the exported standard API can be found in
[term [vset TITLE_DEV_VT]]. The chosen default is "now".

[para] A single non-standard method is provided:

[list_begin definitions][comment {-- begin api definitions --}]
[comment {- - -- --- ----- -------- ------------- ---------------------}]
[call [cmd ::cmdr::validate::time] [method 2external] [arg epoch]]

This method converts the epoch of a time to the form
[const %Y-%m-%dT%H:%M:%S] and returns the conversion result as its own.

[comment {- - -- --- ----- -------- ------------- ---------------------}]
[list_end][comment {-- end api definitions --}]

[include parts/feedback.inc]
[manpage_end]

Changes to vt_time.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
..
71
72
73
74
75
76
77




78
79

80
81
82
83
84
85
86
87
88
89
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## CMDR - Validate::Time - Supporting validation type - iso times.

# @@ Meta Begin
# Package cmdr::validate::time 1
# Meta author   {Andreas Kupries}
# Meta location https://core.tcl.tk/akupries/cmdr
# Meta platform tcl
# Meta summary     Standard parameter validation type for times (down to seconds)
# Meta description Standard parameter validation type for times (down to seconds)
# Meta subject {command line}
# Meta require {Tcl 8.5-}
# Meta require {cmdr::validate::common 1.2}
# Meta require debug
# Meta require debug::caller
# Meta require try
# Meta require clock::iso8601
................................................................................
# # ## ### ##### ######## ############# #####################

debug define cmdr/validate/time
debug level  cmdr/validate/time
debug prefix cmdr/validate/time {[debug caller] | }

# # ## ### ##### ######## ############# #####################
## Times as parsed by clock::iso86

proc ::cmdr::validate::time::2external {x}  {
    debug.cmdr/validate/time {}
    return [clock format $x -format {%H:%M:%S}]
}

proc ::cmdr::validate::time::release  {p x} { return }
proc ::cmdr::validate::time::default  {p}  {
    debug.cmdr/validate/time {}
    # Today.
    return [clock seconds]
................................................................................
    debug.cmdr/validate/time {} 10
    # No completion.
    return {}
}
proc ::cmdr::validate::time::validate {p x} {
    debug.cmdr/validate/time {}
    try {




	# TODO: error code in clock::iso8601.
	set epoch [clock::iso8601 parse_time $x]

    } on error {e o} {
	fail $p TIME "an ISO8601 time" $x
    } 
    return $epoch
}

# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::time 1
return





|



|
|







 







|



|







 







>
>
>
>
|
|
>

|






|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
..
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## CMDR - Validate::Time - Supporting validation type - iso times.

# @@ Meta Begin
# Package cmdr::validate::time 1.1
# Meta author   {Andreas Kupries}
# Meta location https://core.tcl.tk/akupries/cmdr
# Meta platform tcl
# Meta summary     Standard parameter validation type for timestamps (down to seconds)
# Meta description Standard parameter validation type for timestamps (down to seconds)
# Meta subject {command line}
# Meta require {Tcl 8.5-}
# Meta require {cmdr::validate::common 1.2}
# Meta require debug
# Meta require debug::caller
# Meta require try
# Meta require clock::iso8601
................................................................................
# # ## ### ##### ######## ############# #####################

debug define cmdr/validate/time
debug level  cmdr/validate/time
debug prefix cmdr/validate/time {[debug caller] | }

# # ## ### ##### ######## ############# #####################
## Times as parsed by clock::iso8601

proc ::cmdr::validate::time::2external {x}  {
    debug.cmdr/validate/time {}
    return [clock format $x -format {%Y-%m-%dT%H:%M:%S}]
}

proc ::cmdr::validate::time::release  {p x} { return }
proc ::cmdr::validate::time::default  {p}  {
    debug.cmdr/validate/time {}
    # Today.
    return [clock seconds]
................................................................................
    debug.cmdr/validate/time {} 10
    # No completion.
    return {}
}
proc ::cmdr::validate::time::validate {p x} {
    debug.cmdr/validate/time {}
    try {
	if {[string is integer -strict $x] && ($x >= 0)} {
	    # Integer, direct epoch
	    set epoch $x
	} else {
	    # TODO: error code in clock::iso8601.
	    set epoch [clock::iso8601 parse_time $x]
	}
    } on error {e o} {
	fail $p TIME "an ISO8601 time or epoch" $x
    } 
    return $epoch
}

# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::time 1.1
return