>>>>> "Phil" == Phil Pennock <[email protected]> writes:
Phil> On 2010-10-08 at 08:07 -0700, Andrew Hume wrote:
>> now i would have just said
>> hour = t/(3600 * 1000); // remember t is in milliseconds
>> // if i wanted hr in 00..23 range: hour = hour%24;
>>
>> bill said
>> xx = t/1000
>> strncpy(hr_str, &(ctime(&xx)[11]), 2);
>> hr_str[2] = 0;
>> hour = atoi(hr_str);
>>
>> ignoring logic errors (we really wanted hour from teh epoch, and not
>> hour of teh day) and time errors (ctime does localtime, not UTC);
>> my question is, where does someone learn this technique?
>> i am gobsmacked.
Phil> In his defence: if you had wanted hour of the day, it's far
Phil> better to use system libraries, which are well debugged, than to
Phil> roll your own date calculations and discover the need to deal
Phil> with things like leap-seconds, etc. And for hour-of-the-day, in
Phil> those cases where that's actually needed, localtime is normally
Phil> what's wanted by non-sysadmins.
This topic is really on time for me, because I had a user come to me
last week asking for 'nawk' on one of our systems. For the life of
me, I could figure out why he cared so much, since we have
/usr/local/bin/awk everywhere (gnu version).
Turned out, one of the engineers had written the following in a csh
(yes, I know...) script they used for firing off jobs on the compute
nodes.
set date=`date|nawk '{print $2}'``date +%d`
Once I explained man pages, it was changed to:
set date=`date +%b%d`
and all was good. Give a user an AWKward to use tool, and everything
looks AWKward.
So sorry for the completely lame pun. It's late.
G'night,
John
_______________________________________________
Tech mailing list
[email protected]
http://lists.lopsa.org/cgi-bin/mailman/listinfo/tech
This list provided by the League of Professional System Administrators
http://lopsa.org/