#!/bin/bash

# ------------------------------------------------------------
# RPC Project :
# RPC_date_time_to_datiso convert yymmdd hhmmss to datiso
# P. Robert, LPP, 2014-11-14
# ------------------------------------------------------------

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

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

if test $# != $Narg || test $hh = 1
   then
   echo "$appli : return ISO_date from yymmdd hhmmssc"
   echo "$appli   require $Narg argument(s)"
   echo "    ex: $appli 20010923  090000 "
   echo ""
   if test $hh = 1 ; then exit 0 ; fi
   echo "$appli36 : *** ERROR ! Command aborted." >&2
   exit 1
fi

yymmdd=$1
hhmmss=$2

if test $yymmdd != 0
   then
   yy=`echo $yymmdd | cut -c1-4`
   mm=`echo $yymmdd | cut -c5-6`
   dd=`echo $yymmdd | cut -c7-8`
   else
   date_iso=0
   echo $date_iso
   exit 0
fi

if test  $hhmmss != 0 
   then
   hh=`echo $hhmmss | cut -c1-2`
   mn=`echo $hhmmss | cut -c3-4`
   ss=`echo $hhmmss | cut -c5-6`
   date_iso=$yy"-"$mm"-"$dd"T"$hh":"$mn":"$ss".000Z"
   echo $date_iso
   exit 0
   else
   date_iso=$yy"-"$mm"-"$dd"T00:00:0.000Z"
   echo $date_iso
   exit 0
fi

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