#!/bin/bash

# ------------------------------------------------------------
# RPC Project :
# RPC_datiso_to_date_time convert datiso to yymmdd hhmmss
# P. Robert,ScientiDev, Jan 2021
# ------------------------------------------------------------

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 yymmdd hhmmss from ISO_date "
   echo "$appli   require $Narg argument(s)"
   echo "    ex: $appli 2001-09-23T09:00:00.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

# ------------------------------------------------------------
