Scott M. Mcdermott

UNIX Systems & Network Administrator
available for contract or salaried positions

datestr_more_readable

#
# input: %Y%m%d%H%M%S
# output: %m/%d@%H:%M
#

source ~/lib/sh/include
require freturn

make_human_readable_absolute_datestr ()
{
        local +i datestr=$1

        local -i i
        local -i off

        # these could have initial zeros so we have to make
        # them strings
        local +i year month day hour minute second

        local +i label

        declare -a period

        year=${datestr:0:$((i = 4))}
        for label in month day hour minute second; do
                eval $label=${datestr:$((i++)):2}
        done

        period=(month day hour minute second)
        for ((off = 4, i = 0; i < ${#period[@]}; i++, off += 2)); do
                eval ${period\[i\]}=${datestr:$off:2}
        done

        freturn $month/$day@$hour:$minute
}
# vim:syn=sh:ft=sh