Skip Menu |

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

Report information
The Basics
Id: 123203
Status: new
Priority: 0/
Queue: DateTime-Format-Duration

People
Owner: Nobody in particular
Requestors: haukex [...] zero-g.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.04
Fixed in: (no value)



Subject: parse_duration with patterns=~/%\d+N/ does not work correctly
Hi, parse_duration unfortunately does not respect the documented right-padding of nanoseconds. The attached test script shows the failures in round-tripping for various %\d+N values except %9N. A related bug appears to be that format_duration does not work as documented: "123456789 nanoseconds formatted with ... %12N would return 123456789000", it actually currently returns "123456789" (also seen in the attached file). Thanks, Regards, -- Hauke D
Subject: dt-fmt-dur.pl
#!/usr/bin/env perl use warnings; use strict; use DateTime::Duration; use DateTime::Format::Duration; for my $i (1..12) { my $pat = "%${i}N"; my $fmt = DateTime::Format::Duration->new(pattern=>$pat); my $dur1 = DateTime::Duration->new(nanoseconds=>123456789); my $str1 = $fmt->format_duration($dur1); my $dur2 = $fmt->parse_duration($str1); my $str2 = $fmt->format_duration($dur2); printf "%4s: ns=%9d -fmt-> %12s -parse-> ns=%9d -fmt-> %12s\n", $pat, $dur1->nanoseconds, $str1, $dur2->nanoseconds, $str2; } __END__ # Expected Output: %1N: ns=123456789 -fmt-> 1 -parse-> ns=100000000 -fmt-> 1 %2N: ns=123456789 -fmt-> 12 -parse-> ns=120000000 -fmt-> 12 %3N: ns=123456789 -fmt-> 123 -parse-> ns=123000000 -fmt-> 123 %4N: ns=123456789 -fmt-> 1234 -parse-> ns=123400000 -fmt-> 1234 %5N: ns=123456789 -fmt-> 12345 -parse-> ns=123450000 -fmt-> 12345 %6N: ns=123456789 -fmt-> 123456 -parse-> ns=123456000 -fmt-> 123456 %7N: ns=123456789 -fmt-> 1234567 -parse-> ns=123456700 -fmt-> 1234567 %8N: ns=123456789 -fmt-> 12345678 -parse-> ns=123456780 -fmt-> 12345678 %9N: ns=123456789 -fmt-> 123456789 -parse-> ns=123456789 -fmt-> 123456789 %10N: ns=123456789 -fmt-> 1234567890 -parse-> ns=123456789 -fmt-> 1234567890 %11N: ns=123456789 -fmt-> 12345678900 -parse-> ns=123456789 -fmt-> 12345678900 %12N: ns=123456789 -fmt-> 123456789000 -parse-> ns=123456789 -fmt-> 123456789000 # Actual Output: %1N: ns=123456789 -fmt-> 1 -parse-> ns= 1 -fmt-> 0 %2N: ns=123456789 -fmt-> 12 -parse-> ns= 12 -fmt-> 00 %3N: ns=123456789 -fmt-> 123 -parse-> ns= 123 -fmt-> 000 %4N: ns=123456789 -fmt-> 1234 -parse-> ns= 1234 -fmt-> 0000 %5N: ns=123456789 -fmt-> 12345 -parse-> ns= 12345 -fmt-> 00001 %6N: ns=123456789 -fmt-> 123456 -parse-> ns= 123456 -fmt-> 000123 %7N: ns=123456789 -fmt-> 1234567 -parse-> ns= 1234567 -fmt-> 0012345 %8N: ns=123456789 -fmt-> 12345678 -parse-> ns= 12345678 -fmt-> 01234567 %9N: ns=123456789 -fmt-> 123456789 -parse-> ns=123456789 -fmt-> 123456789 %10N: ns=123456789 -fmt-> 123456789 -parse-> ns= 0 -fmt-> 000000000 %11N: ns=123456789 -fmt-> 123456789 -parse-> ns= 0 -fmt-> 000000000 %12N: ns=123456789 -fmt-> 123456789 -parse-> ns= 0 -fmt-> 000000000