[BusyBox] sugestion: date -d extension
Gyorgy Farkas
gf.mail at freemail.hu
Sat Jun 4 12:54:55 UTC 2005
On Tue May 31 walter harms wrote:
> i drop over the problem with these example
>
> gnudate:
> date -d "2005-01-01 10:00:00" +"%s"
>
and on a regular Linux box the result is (timezone set to CET)
1104570000
> bbdate:
> date -d "2005-01-01 10:00:00" +"%s"
> date: invalid date `2005-01-01 10:00:00'
on BB (TZ is CET-1CEST)
date -d "2005.01.01-10:00:00" +"%s"
1104570000
> or this fancy trick to convert between Epoch and localtime
> (from gnu date examples)
>
> date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
> 2000-01-01 01:00:00 +0100
>
> date -d '1970-01-01 UTC 946684800 seconds' +"%Y-%m-%d %T %z"
> date: invalid date `1970-01-01 UTC 946684800 seconds'
on the above mentioned BB box
date -d "1970.01.01-00:00:`expr 946684800 + 3600`"
+"%Y-%m-%d %T %Z"
2000-01-01 01:00:00 CET
date -d "1970.01.01-00:00:`expr 946684800 + 3600`"
+"%Y-%m-%d %T %z"
2000-01-01 01:00:00 -0100
> by looking at the code i came up with the idea to add a
'hint' to ease
> the conversion since most times ppl are aware what the
input format is
> like. The point is that the gnu date conversion is very
powerfull but
> IMHO overkill for busybox.
IMHO that "fancy trick" to convert between 'seconds since
EPOCH' and 'localtime' is more than a simple string format
conversion.
There can be some Perl and C magic on GNU.
A little simple scripting is required also on BusyBox -
generally speaking
# from a hardwired constant to some sophisticated algorithm
offset_in_seconds=???
seconds=`expr $seconds_since_Epoch - $offset_in_seconds`
date -d "1970.01.01-00:00:$seconds" +"..."
For example at CET/CEST the offset_in_seconds is either
-3600 or -7200
(-7200 from the last Sun of Mar/first Sun of Apr to the
last Sun of Oct ;)
so - I think - a little scripting is really needed.
Cheers,
George.
BB v1.00 on floppyfw-2.99.4, kernel 2.4.30, uClibc-0.9.27 -
at UTC of course
More information about the busybox
mailing list