Commit 68caf23a authored by Dave Morriss's avatar Dave Morriss

Some tidying of 'parse_8601_duration'

Some of the oddities discussed in the show have been cleaned up, the
timestamps changed to ISO8601 at Ken's request (!).

Another example added to 8601_duration_test.dat
parent 46098df7
......@@ -6,6 +6,7 @@ PT1M
P1Y2M3DT10H30M
P0.5Y
P0.5YT0.5M
PT0.5S
P0Y1347M
P0YT
P0Y2H
......
......@@ -5,7 +5,7 @@
#
# USAGE: ./parse_8601_duration [duration_expression...]
#
# DESCRIPTION: Parses an ISO_801 time duration to extract the relevant
# DESCRIPTION: Parses an ISO_8601 time duration to extract the relevant
# fields. Note that it is fairly simplistic and does not
# validate the duration expression very rigorously. For example
# 'P0YT' is invalid yet is accepted by the parser. However,
......@@ -22,8 +22,8 @@
# open to question). This script does not allow this.
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
# VERSION: 1.0
# CREATED: 04/07/2013 17:20:09
# REVISION: 06/07/2013 12:51:47
# CREATED: 2013-07-04 17:20:09
# REVISION: 2013-07-06 22:48:47
#
#===============================================================================
......@@ -43,7 +43,7 @@ my %iso_duration;
# Regular expressions for an integer and a decimal fraction
#
my $int = qr{\d+};
my $frac = qr{[0-9]+(?:\.[0-9]+)?};
my $frac = qr{\d+(?:\.\d+)?};
#
# Regular expression for the ISO 8601 duration. Uses Perl's extensions where
......@@ -82,7 +82,7 @@ while ( $duration = shift ) {
#
# Force all undefined fields to be zero
#
@fields = map { ( defined($_) ? $_ : 0 ) } @fields;
@fields = map { defined($_) ? $_ : 0 } @fields;
#
# Build a duration hash (just to show how to do it in a cool Perly way)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment