O% GNUawk
tem mktime
e strftime
:
$ gawk '{gsub(/[-T:]/," "); print strftime("%Y-%m-%dT%H:%M:%S\n", mktime($0)+60)}'
$ gawk '
function timeadd(t, s){
gsub(/[-T:]/," ", t); return strftime("%Y-%m-%dT%H:%M:%S", mktime(t)+s)
}
BEGIN{
print ARGV[1]
print ARGV[2]
print timeadd(ARGV[1], 60)
print timeadd(ARGV[2], 60 * 10)
}
' 2018-10-14T13:26:00.000 2018-10-14T13:27:50.000
2018-10-14T13:26:00.000
2018-10-14T13:27:50.000
2018-10-14T13:27:00
2018-10-14T13:37:50
Uma versão de timeadd
que também lida com milissegundos:
$ cat timeadd.awk
function timeadd(t, s){
gsub(/[-T:]/," ", t)
t = mktime(t) + s + substr(t, index(t, "."))
s = substr(sprintf("%.3f", t - int(t)), 2)
return strftime("%Y-%m-%dT%H:%M:%S" s, t)
}
{ print timeadd($1, $2); }
$ gawk -f /tmp/timeadd.awk
2018-10-19T13:26:58.815 4.237
2018-10-19T13:27:03.052
2018-10-19T13:26:58.122 -3.822
2018-10-19T13:26:54.300