Skip Menu |

This queue is for tickets about the Time-Format CPAN distribution.

Report information
The Basics
Id: 87484
Status: resolved
Priority: 0/
Queue: Time-Format

People
Owner: eric.roode.cpan [...] gmail.com
Requestors: thierryv [...] mac.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.12
Fixed in: 1.13



Subject: Time::Format %time dies on below e-03 time value
Hello, A critical application of mine crashed with that error (perl v5.14.3, Time::Format v1.11 and above) Unrecognized time value: "2.14576721191406e-06" at ./loadCPSN.pl line 505 Actually, my code is counting the time in milliseconds elapsed between two critical events. After some code enhancements on my side, that elapsed time went below the milliseconds. And it made my whole application crashed when invoking $time{'mm:ss.mmm', $stat_perf} with a time value below 0.001. Here is the offending code: # Note: getISOTimemmm() is called several times in my application. On all calls after the first one, it displays the current timestamp and a millisecond diff from the previous call. # ---------------------------------------------------------- # use Time::Format; '2006-06-16T17:52:47.820' ISO 8601 sub getISOTimemmm { our $time_start; # Scope is global but DO NOT declare it elsewhere. Bugs with "Month '57' out of range 0..11 at (eval 5) line 279" my $Timemmm = $time{'yyyy-mm-ddThh:mm:ss.mmm'}; if (defined($time_start) && ($time_start > 0)) { my $stat_perf = gettimeofday - $time_start; $Timemmm = $Timemmm . " - " . $time{'mm:ss.mmm', $stat_perf} } else { $time_start = gettimeofday; # Performance timestamp. } $Timemmm; } Here is my workaround: # ---------------------------------------------------------- sub getISOTimemmm { our $time_start; my $Timemmm = $time{'yyyy-mm-ddThh:mm:ss.mmm'}; if (defined($time_start)) { eval { my $stat_perf = gettimeofday - $time_start; if ($stat_perf < 0.001 ) { $stat_perf = 0 } # makes the whole perl process crash if $stat_perf is below e-03. $Timemmm = $Timemmm . " - " . $time{'mm:ss.mmm', $stat_perf}; }; } else { $time_start = gettimeofday; # Performance timestamp. } $Timemmm; } I would strongly recommend that a "likelihood" check be implemented in %time so that the script doesn't whoosh out of memory, unexpectedly, for time values below 0.001 Thanks for the great code otherwise. Thierry
Time::Format now explicitly recognizes this numeric format.