#!/bin/bash

# ------------------------------------------------------------
# RPC Project :
# RPC_decode_datiso : return 2001 09 23 09 17 03 frome ISO date
#                         as 2001-09-23T09:17:03.000Z
# syntax : RPC_decode_datiso datiso
#      ex: RPC_nday_of_month 2001-09-23T09:17:03.000Z
# P. Robert, LPP, 2013-02-14
# ------------------------------------------------------------

appli=`basename $0`
appli36=`echo "$appli                                 " | cut -c1-36`
Narg=1

if( (test $# = 1 ) && (test $1 = -h ) ) ; then hh=1 ; else hh=0 ; fi

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : return elements of an ISO date"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   datiso"
   echo "    ex: $appli 2001-09-23T09:17:03.000Z"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo "$appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

datiso=$1

# check input date validity
# -------------------------

TT=`echo $datiso | cut -c11 `

if test "$TT" != T
   then 
        echo "$datiso is not a correct ISO date" >&2
        echo "$appli36 : *** ERROR ! Command aborted." >&2
        echo "0000 00 00 00 00 00"
        exit 2
fi


yy=`echo $datiso | cut -c1-4   `
mm=`echo $datiso | cut -c6-7   `
dd=`echo $datiso | cut -c9-10  `
ih=`echo $datiso | cut -c12-13 `
im=`echo $datiso | cut -c15-16 `
is=`echo $datiso | cut -c18-19 `

echo $yy $mm $dd $ih $im $is
exit 0
# ------------------------------------------------------------
