From 7500ef53598f2ee2c128bd9b93d5c94b1aa7b6e9 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Sun, 7 Dec 2008 15:55:55 +0100 Subject: refactored/cleanup datetime/timezone stuff --- src/core/libs/lib-ui.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/core/libs/lib-ui.sh') diff --git a/src/core/libs/lib-ui.sh b/src/core/libs/lib-ui.sh index 1ca87d5..9191998 100644 --- a/src/core/libs/lib-ui.sh +++ b/src/core/libs/lib-ui.sh @@ -137,6 +137,28 @@ ask_checklist () +ask_datetime () +{ + if [ "$var_UI_TYPE" = dia ] + then + # display and ask to set date/time + dialog --calendar "Set the date.\nUse to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || return 1 + local _date="$(cat $ANSWER)" # form like: 07/12/2008 + dialog --timebox "Set the time.\nUse to navigate and up/down to change values." 0 0 2> $ANSWER || return 1 + local _time="$(cat $ANSWER)" # form like: 15:26:46 + echo "date: $_date time: $_time" >$LOG + + # DD/MM/YYYY hh:mm:ss -> MMDDhhmmYYYY.ss (date default format, set like date $ANSWER_DATETIME) Not enabled because there is no use for it i think. + # ANSWER_DATETIME=$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\2\1\4\5\3\6#g') + # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss ( date string format, set like date -s $ANSWER_DATETIME) + ANSWER_DATETIME="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')" + elif [ "$var_UI_TYPE" = cli ] + ask_string "Enter date [YYYY-MM-DD hh:mm:ss]" + ANSWER_DATETIME=$ANSWER_STRING + fi +} + + # TODO: we should have a wrapper around this function that keeps trying until the user entered a valid numeric?, maybe a wrapper that wraps all functions # ask for a number. # $1 question @@ -191,6 +213,12 @@ ask_string () } +ask_timezone () # TODO: how to do this in dia? +{ + ANSWER_TIMEZONE=`tzselect` +} + + # ask a yes/no question. # $1 question # $2 default answer yes/no (optional) -- cgit v1.2.3-54-g00ecf