[nzlug] Time Calculator
N Dempsey
NevilleD.AuckLug at sgr-a.net
Fri Jan 12 13:33:11 NZDT 2007
Hi Marvin,
You can pretty much do the following calculation in your choice of
language (including C, perl and gawk). I used python to demonstrate,
the code finds the date/time 1 million seconds from the given date/time.
$ cat ./timecalc.py
#!/usr/bin/env python
from time import *
for inc in 1,10,100,1000,10000,100000,1000000:
d="Fri Jan 12 13:02:51 2007"
t=mktime(strptime(d))+inc
print ctime(t)
$ ./timecalc.py
Fri Jan 12 13:02:52 2007
Fri Jan 12 13:03:01 2007
Fri Jan 12 13:04:31 2007
Fri Jan 12 13:19:31 2007
Fri Jan 12 15:49:31 2007
Sat Jan 13 16:49:31 2007
Wed Jan 24 02:49:31 2007
# works completely...
Gawk now has some date/time functions, so you could use gawk to do your
time calculations in shell, and "eval" to import the results.
You can do "similar" things in bash, but it is a "problematic. eg.
$ cat ./timecalc.sh
date "+y=%Y m=%m d=%d H=%H M=%M S=%S"
# only works for +/- a month or so... unless you code in a case statement.
for inc in 1 10 100 1000 10000 100000 1000000; do
#eval $(date "+y=%Y m=%m d=%d H=%H M=%M S=%S")
eval "m=01 d=12 H=13 M=02 S=51 y=2007"
((S+=inc)); ((M+=S/60)); ((S=S%60)); ((H+=M/60)); ((M=M%60));
((d-=1)); ((m-=1))
((d+=H/60)); ((H=H%24)); ((m+=d/30)); ((d=d%30)); ((y+=m/12)); ((m=m%12));
((d+=1)); ((m+=1))
echo "Year: $y, Month: $m, Day: $d, Hour: $H, Minute: $M, Second: $S"
done
# OR alternately... (only works for +/- the next time unit)
for inc in 1 10 100 1000 10000 100000 1000000; do
env TZ=NZST-0:0:$inc date
done
nevilled at alfa:/root0/home/nevilled $ ./timecalc.sh
y=2007 m=01 d=12 H=13 M=24 S=55
Year: 2007, Month: 1, Day: 12, Hour: 13, Minute: 2, Second: 52
Year: 2007, Month: 1, Day: 12, Hour: 13, Minute: 3, Second: 1
Year: 2007, Month: 1, Day: 12, Hour: 13, Minute: 4, Second: 31
Year: 2007, Month: 1, Day: 12, Hour: 13, Minute: 19, Second: 31
Year: 2007, Month: 1, Day: 12, Hour: 15, Minute: 49, Second: 31
Year: 2007, Month: 1, Day: 12, Hour: 16, Minute: 49, Second: 31
Year: 2007, Month: 1, Day: 16, Hour: 2, Minute: 49, Second: 31
Fri Jan 12 00:24:56 NZST 2007
Fri Jan 12 00:25:06 NZST 2007
Fri Jan 12 00:25:55 NZST 2007
Fri Jan 12 00:25:55 NZST 2007
Fri Jan 12 00:25:55 NZST 2007
Fri Jan 12 00:25:55 NZST 2007
Fri Jan 12 00:25:55 NZST 2007
GLuck.
N
On Fri, 2007-01-12 at 00:03 +0800, Marvin Pascual wrote:
> Hello all,
>
> Anyone here knows if there's such tool as a "time calculator" that can
> do at least the basic calculations for HH:MM:SS:MS?
>
> Thank you.
>
> Marvin
>
> _______________________________________________
> NZLUG mailing list NZLUG at linux.net.nz
> http://www.linux.net.nz/cgi-bin/mailman/listinfo/nzlug
More information about the NZLUG
mailing list