Version 0 of Formatting Functions For Time/Date

Updated 2018-01-09 21:38:29 by CecilWesterhof

Created by CecilWesterhof.

I created some procs to easily get some date/time formats.

The first is because I miss the %F format in clock.

# Clock format which recognises %F
proc clockFrmt {time format} {
    clock format ${time} -format [string map {%F {%Y-%m-%d}} ${format}]
}

But I find it also handy as a shorter form for clock with format. ;-)

Then I created the following three procs.

proc getDateStr {{thisTime -1}} {
    set thisTime [convertDefaultTime ${thisTime}]
    clockFrmt ${thisTime} "%F"
}

proc getDateTimeStr {{thisTime -1}} {
    set thisTime [convertDefaultTime ${thisTime}]
    clockFrmt ${thisTime} "%FT%T"
}

proc getTimeStr {{thisTime -1}} {
    set thisTime [convertDefaultTime ${thisTime}]
    clockFrmt ${thisTime} "%T"
}

An example usage:

proc showMessage {message {onlyTime False} {display True}} {
    if {${display}} {
        if {${onlyTime}} {
            set moment [getTimeStr]
        } else {
            set moment [getDateTimeStr]
        }
        puts [format "%s: %s" ${moment} ${message}]
    }
}

As always: comments, tips and questions are appreciated.