Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
=item xs_duration_to_seconds Convert the time part of xs:duration format to seconds. This should be fairly quick and robust - only handles the time part of the spec (ignores the rest!). some examples of times correctly understood: PT10H0M0S => 36000 PT10H0M => 36000 PT10H5M => 36300 PT10H0M5S => 36005 PT10H04M16S => 36256 Pstuff0xT10H5M => 36300 See also the full spec for this datatype: http://www.w3.org/TR/xmlschema-2/#duration =cut sub xs_duration_to_seconds { my $self = shift; my $xsd = shift; # strip P..T from the string $xsd =~ s{ ^ P [^T]* T }{}x; my $secs = 0; while( $xsd =~ m{ (\d+) (\D) }gx ) { last unless defined($1) and $2; $secs += 3600 * $1 if $2 eq 'H'; $secs += 60 * $1 if $2 eq 'M'; $secs += 1 * $1 if $2 eq 'S'; } $secs; }
This paste will be private.
From the Design Piracy series on my blog: