Browse Source

fix function datestr

pull/1/head
10sr 10 years ago
parent
commit
d065cd3271
1 changed files with 9 additions and 9 deletions
  1. +9
    -9
      shrc

+ 9
- 9
shrc View File

@@ -494,25 +494,26 @@ randomstr(){
} }


datestr(){ datestr(){
# datestr yyyyMMdd-hhmmss
if test -z "$1" || test "$1" == "-h"
# datestr YYYYMMDDhhmmss
if test -z "$1" || test "$1" = "-h"
then then
echo "datestr: usage: datestr <yyyyMMddhhmmss>"
echo "datestr: usage: datestr <YYYYMMDDhhmmss>"
return 1 return 1
fi fi


dfmt= # actual format for date command
dfmt="" # actual format for date command
while test -n "$1" while test -n "$1"
do do
fmt="$1" fmt="$1"
shift
while test -n "$fmt" while test -n "$fmt"
do do
case "$fmt" in case "$fmt" in
yyyy*) # year
YYYY*|yyyy*) # year
dfmt="${dfmt}%Y" dfmt="${dfmt}%Y"
fmt="`echo "$fmt" | cut -c 5-`" fmt="`echo "$fmt" | cut -c 5-`"
;; ;;
yy*) # last two digits of year
YY*|yy*) # last two digits of year
dfmt="${dfmt}%y" dfmt="${dfmt}%y"
fmt="`echo "$fmt" | cut -c 3-`" fmt="`echo "$fmt" | cut -c 3-`"
;; ;;
@@ -520,7 +521,7 @@ datestr(){
dfmt="${dfmt}%m" dfmt="${dfmt}%m"
fmt="`echo "$fmt" | cut -c 3-`" fmt="`echo "$fmt" | cut -c 3-`"
;; ;;
dd*) # day of month (01..12)
DD*|dd*) # day of month (01..12)
dfmt="${dfmt}%d" dfmt="${dfmt}%d"
fmt="`echo "$fmt" | cut -c 3-`" fmt="`echo "$fmt" | cut -c 3-`"
;; ;;
@@ -532,7 +533,7 @@ datestr(){
dfmt="${dfmt}%M" dfmt="${dfmt}%M"
fmt="`echo "$fmt" | cut -c 3-`" fmt="`echo "$fmt" | cut -c 3-`"
;; ;;
ss*) # second (00..60)
SS*|ss*) # second (00..60)
dfmt="${dfmt}%S" dfmt="${dfmt}%S"
fmt="`echo "$fmt" | cut -c 3-`" fmt="`echo "$fmt" | cut -c 3-`"
;; ;;
@@ -543,7 +544,6 @@ datestr(){
;; ;;
esac esac
done done
shift
done done
date +"$dfmt" date +"$dfmt"
} }


Loading…
Cancel
Save