Well, yes, "date --date= ..." doesn't work in the way I would wish
("logically" think about it):

 
https://www.gnu.org/software/coreutils/manual/html_node/General-date-syntax.html

 parsing any format allowed by date:

 
https://www.gnu.org/software/coreutils/manual/html_node/Date-conversion-specifiers.html

 which made me think of how/why did I start using my "coblesome"
formatting, but there is nothing really that homely about it. Those
formatting options are listed right on:

 date --help

$ date --version 2>&1 | head -n 1
date (GNU coreutils) 8.32

 Based on to...@tuxteam.de's suggestions I worked around a downright
simple hack around those formatting problematics with coreutils date:

s00=$(date +%s)
dt00=$(date +%Y%m%d%H%M%S)

dttm00ISeks="${dt00:0:4}-${dt00:4:2}-${dt00:6:2}T${dt00:8:2}:${dt00:10:2}:${dt00:12:2}+00:00"
ISeks00=$(date -d"${dttm00ISeks}" +%s)

if [[ $s00 -eq $ISeks00 ]]; then
 echo "// __ \$ISeks00: |$ISeks00|, \$dttm00ISeks: |${dttm00ISeks}|
conversion OK!"
else
 echo "// __ \$s00: |$s00|, \$dt00: |${dt00}|"
 echo "// __ \$ISeks00: |$ISeks00|, \$dttm00ISeks: |${dttm00ISeks}|
conversion NOT OK!"
fi

# 63 weeks 5 days 11 hours 0 minutes et 43 seconds later
s02=$(( s00 + 63*7*24*60*60 + 5*24*60*60 + 11*60*60 + 0*60 + 43))

dt02=$(date --date @${s02} +%Y%m%d%H%M%S)
echo "// __ \$s02: |$s02|, \$dt02: |${dt02}|"

dttm02ISeks="${dt02:0:4}-${dt02:4:2}-${dt02:6:2}T${dt02:8:2}:${dt02:10:2}:${dt02:12:2}+00:00"
ISeks02=$(date -d"${dttm02ISeks}" +%s)

if [[ $s02 -eq $ISeks02 ]]; then
 echo "// __ \$ISeks02: |$ISeks02|, \$dttm02ISeks: |${dttm02ISeks}|
conversion OK!"
 _diffs=$(( s02 - s00 ))
 _diffISeks=$(( ISeks02 - ISeks00 ))
 if [[ $_diffs -eq $_diffISeks ]]; then
  echo "// __ differences also OK!"
 else
  echo "// __  differences NOT OK! \$_diffs: |$_diffs|, \$_diffISeks:
|${_diffISeks}|"
 fi
else
 echo "// __ \$s02: |$s02|, \$dt02: |${dt02}|"
 echo "// __ \$ISeks02: |$ISeks02|, \$dttm02ISeks: |${dttm02ISeks}|
conversion NOT OK!"
fi

 thank you,
 lbrtchx

Reply via email to