#!/bin/bash

# ------------------------------------------------------------
# RPC Project :
# RPC_decode_datim : return 2001 09 23 09 17 03 frome date
#                         given as 20010923_091703
# syntax : RPC_decode_datim datim
#      ex: RPC_decode_datim 20010923_091703
# P. Robert, LPP, 2014-11-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 a date_time variable"
   echo "$appli   require $Narg argument(s), ex:"
   echo "$appli   datim"
   echo "    ex: $appli 20010923_091703"
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo "$appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

datim=$1

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

US=`echo $datim | cut -c9 `

if test "$US" != _
   then 
        echo "$datim is not a correct DATIM date"
        echo "$appli36 : *** ERROR ! Command aborted." >&2
        exit 2
fi


yy=`echo $datim | cut -c1-4   `
mm=`echo $datim | cut -c5-6   `
dd=`echo $datim | cut -c7-8  `
ih=`echo $datim | cut -c10-11 `
im=`echo $datim | cut -c12-13 `
is=`echo $datim | cut -c14-15 `

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