Hi all,

I'm puzzling over the following which may just be a misunderstanding of the 
format string or something far more fundamental :-). I'm attempting to parse 
datetimes of the following format:

ddddddddhhmmss.nnnnnnnnn:000

For example, 11d 1h 34min 45sec 960000000ns is 00000011013445.960000000:000

I had thought to use the following pattern: '%8e%H%M%S.%N:000' but it doesn't 
seem to want to play nice. In the example program attached I compare a 
handrolled version that calls DFD->normalise manually (unnecessary with this 
example and yes - I know all about base()) and the DFD->parse_duration version.

Just for completeness I also strip off the leading zeros and try again with 
'%e%H%M%S.%N:000' and that doesn't seem to parse at all.

Can anyone explain why parse_duration() gives me 11 days, 8044 minutes plus 
change? (that's around 5.5 extra days) ?


Output:

Processing string [00000011013445.960000000:000]

Result using D::F::D and pattern [%8e%H%M%S.%N:000]:
$VAR1 = bless( {
                 'seconds' => 5,
                 'minutes' => 8044,
                 'end_of_month' => 'wrap',
                 'nanoseconds' => 960000000,
                 'days' => 11,
                 'months' => 0
               }, 'DateTime::Duration' );

Hand rolled result:
$VAR1 = bless( {
                 'seconds' => 45,
                 'minutes' => 94,
                 'end_of_month' => 'wrap',
                 'nanoseconds' => 960000000,
                 'days' => 11,
                 'months' => 0
               }, 'DateTime::Duration' );

Processing string [11013445.960000000:000]

Result using D::F::D and pattern [%e%H%M%S.%N:000]:
$VAR1 = bless( {
                 'seconds' => 0,
                 'minutes' => 0,
                 'end_of_month' => 'wrap',
                 'nanoseconds' => 0,
                 'days' => 0,
                 'months' => 0
               }, 'DateTime::Duration' );

Hand rolled result:
$VAR1 = bless( {
                 'seconds' => 45,
                 'minutes' => 94,
                 'end_of_month' => 'wrap',
                 'nanoseconds' => 960000000,
                 'days' => 11,
                 'months' => 0
               }, 'DateTime::Duration' );

Cheers,

Andrew

Attachment: test.pl
Description: test.pl

Reply via email to