[rt-users] Weird hardcore scrip question regarding POSIX, strftime(), localtime()
Rick Russell
rickr at rice.edu
Mon Jan 30 21:57:07 EST 2006
Hi all. I'm writing a custom scrip that performs some "business time"
calculations on tickets, with the idea of determining SLA compliance.
The business details are boring, but I've got a weird technical problem.
I'm using Jesse Vincent's most excellent Business::Hours module to perform
the calculation that I want. It works fine. When it's done, I've got a time
in UNIX epoch seconds.
Here is where things go weird. I want to convert the UNIX epoch seconds into
a string, along these lines:
MM/DD/YYYY hh:mm:ss AM|PM TZ
No problem, I'll just use the POSIX package and the good old strftime
function. Let's say the UNIX epoch seconds are stored in $MySeconds, then
I've got code like this:
my $TimeString = strftime('%m/%d/%Y %r %Z',localtime($MySeconds));
The problem is, about 5% of the time, this scrip fails, and the RT error log
shows:
[Tue Jan 31 00:10:58 2006] [error]: Scrip 339 Commit failed: Usage:
POSIX::strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1,
isdst = -1) at (eval 33876) line 50.
So, I figure, strftime just got bad data. So I use $RT::Logger->error to
send $MySeconds and localtime($MySeconds) to the error log.
My epoch seconds are good, but the output of localtime($MySeconds) seems to
vary, even when supplied with the same input data. Sometimes posting
localtime($MySeconds) to the error log results in a string posted to the
error log, like
Thu Jan 19 08:00:00 2006
Other times, it results in an ARRAY:
Time::tm=ARRAY(0xde1a0f0)
In the first case, I always get a good string out of strftime. In the second
case, I always get the POSIX::strftime error and the scrip execution fails.
Ideas? I'm thinking that PERL is calling different versions of localtime().
Maybe. How would I find out?
I'm also mystified why this code works literally 95 times out of 100, but
fails every once in awhile.
Rick R.
--
For computer help, call xHELP (x4357 or 713-348-4357)
On the web: http://helpdesk.rice.edu/
--
Rick Russell
Helpdesk Supervisor, Client Services
IT/Academic & Research Computing
Rice University
Voice: 713.348.5267 Fax: 713.348.6099
--
OpenPGP/GnuPG Public Key at ldap://certificate.rice.edu
761D 1C20 6428 580F BD98 F5E5 5C8C 56CA C7CB B669
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rickr.vcf
Type: text/x-vcard
Size: 560 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20060130/e624423e/attachment.vcf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20060130/e624423e/attachment.sig>
More information about the rt-users
mailing list