IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9758


Ignore:
Timestamp:
Oct 26, 2006, 4:15:45 PM (20 years ago)
Author:
jhoblitt
Message:

fix time tests that were dependent on MULTI times being broken
fix MULTI time
no longer require the 'Z' and the end of ISO8601 times
implement NULL time support

Location:
trunk/PS-IPP-Metadata-Config
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Metadata-Config/Changes

    r9757 r9758  
    330.09
    44    - fix a bug in Build.PL where a rebuilt grammar was not installed
     5    - fix time tests that were dependent on MULTI times being broken
     6    - fix MULTI time
     7    - no longer require the 'Z' and the end of ISO8601 times
     8    - implement NULL time support
    59
    6100.08 Wed Oct 11 16:09:26 HST 2006
  • trunk/PS-IPP-Metadata-Config/config_grammar.txt

    r9495 r9758  
    11# Copyright (c) 2005  Joshua Hoblitt
    22#
    3 # $Id: config_grammar.txt,v 1.6 2006-10-12 02:08:51 jhoblitt Exp $
     3# $Id: config_grammar.txt,v 1.7 2006-10-27 02:15:45 jhoblitt Exp $
    44
    55{
     
    146146            $return->{comment} = $item{'comment(?)'}[0]
    147147                if $item{'comment(?)'}[0];
     148
     149            if ( defined $thisparser->{local}{name}{ $item{name} } ) {
     150                $return->{multi}++
     151                    if $thisparser->{local}{name}{ $item{name} } =~ /MULTI/;
     152            } else {
     153                $thisparser->{local}{name}{ $item{name} }++;
     154            }
    148155        }
    149156
     
    362369    iso8601
    363370    | utc_epoch
     371    | NULL
    364372
    365373UT1:
    366374    iso8601
    367375    | epoch
     376    | NULL
    368377
    369378TAI:
    370379    iso8601
    371380    | epoch
     381    | NULL
    372382
    373383TT:
    374384    iso8601
    375385    | epoch
     386    | NULL
    376387
    377388iso8601:
    378389    # based on code from DateTime::Format::ISO8601
    379     / \d{4} -?? \d\d -?? \d\d T?? \d\d :?? \d\d :?? \d\d (?:[\.,] (\d+))? Z/x
     390    / \d{4} -?? \d\d -?? \d\d T?? \d\d :?? \d\d :?? \d\d (?:[\.,] (\d+))? Z?/x
    380391        { DateTime::Format::ISO8601->parse_datetime( $item[1] ) }
    381392
     
    394405            nsec    => $2,
    395406        }}
     407NULL:
     408    /NULL/
     409    { $return = "NULL" }
    396410
    397411eofile:
  • trunk/PS-IPP-Metadata-Config/lib/PS/IPP/Metadata/Config.pm

    r9496 r9758  
    11# Copyright (c) 2005  Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.26 2006-10-12 02:09:10 jhoblitt Exp $
     3# $Id: Config.pm,v 1.27 2006-10-27 02:15:45 jhoblitt Exp $
    44
    55package PS::IPP::Metadata::Config;
     
    4949    # multi-symbols
    5050    $self->_merge_duplicates( $tree ) or return undef;
     51
     52    # translate NULL values into perl undefs (Parse::RecDescent can't return
     53    # undefs, args)
     54    $self->_fix_nulls( $tree ) or return undef;
    5155
    5256    #print Dumper($tree);
     
    106110}
    107111
     112sub _fix_nulls {
     113    my ( $self, $tree ) = @_;
     114
     115    # Iteratate through the parse tree looking for values of NULL and
     116    # translating them into Perl undefs
     117    for (my $i = 0; $i < @{$tree}; $i++) {
     118        my $elem = $tree->[$i];
     119
     120        # recurse through nested metadata
     121        if ( $elem->{class} eq "metadata" ) {
     122            $self->_fix_nulls( $elem->{value} );
     123        }
     124
     125        # force stringification of $elem->{value} -- specifically because you
     126        # can't compare a DateTime object to a string value
     127        if ("$elem->{value}" eq "NULL") {
     128            $elem->{value} = undef;
     129        }
     130    }
     131
     132    return 1;
     133}
     134
    1081351;
    109136
  • trunk/PS-IPP-Metadata-Config/t/05_time.t

    r8940 r9758  
    33# Copyright (C) 2005  Joshua Hoblitt
    44#
    5 # $Id: 05_time.t,v 1.3 2006-09-25 21:49:42 jhoblitt Exp $
     5# $Id: 05_time.t,v 1.4 2006-10-27 02:15:45 jhoblitt Exp $
    66
    77use strict;
     
    1212#$::RD_TRACE = 1;
    1313
    14 use Test::More tests => 10;
     14use Test::More tests => 17;
    1515use PS::IPP::Metadata::Config;
    1616
     
    1919{
    2020my $example =<<END;
     21mytime  MULTI
     22mytime  UTC     NULL
     23mytime  UT1     NULL
     24mytime  TAI     NULL
     25mytime  TT      NULL
     26END
     27
     28    my $config = $config_parser->parse( $example );
     29    ok( defined( $config ), "NULL times parsed");
     30
     31    my $tree = [
     32        {
     33            name    => 'mytime',
     34            class   => 'time',
     35            type    => 'UTC',
     36            value   => undef,
     37        },
     38        {
     39            name    => 'mytime',
     40            class   => 'time',
     41            type    => 'UT1',
     42            value   => undef,
     43        },
     44        {
     45            name    => 'mytime',
     46            class   => 'time',
     47            type    => 'TAI',
     48            value   => undef,
     49        },
     50        {
     51            name    => 'mytime',
     52            class   => 'time',
     53            type    => 'TT',
     54            value   => undef,
     55        },
     56    ];
     57
     58    is_deeply( $config, $tree, "NULL times structure" );
     59}
     60
     61{
     62my $example =<<END;
     63mytime  MULTI
     64mytime  UTC     NULL    # comment
     65mytime  UT1     NULL    # comment
     66mytime  TAI     NULL    # comment
     67mytime  TT      NULL    # comment
     68END
     69
     70    my $config = $config_parser->parse( $example );
     71    ok( defined( $config ), "NULL times with comments parsed");
     72
     73    my $tree = [
     74        {
     75            name    => 'mytime',
     76            class   => 'time',
     77            type    => 'UTC',
     78            value   => undef,
     79            comment => 'comment',
     80        },
     81        {
     82            name    => 'mytime',
     83            class   => 'time',
     84            type    => 'UT1',
     85            value   => undef,
     86            comment => 'comment',
     87        },
     88        {
     89            name    => 'mytime',
     90            class   => 'time',
     91            type    => 'TAI',
     92            value   => undef,
     93            comment => 'comment',
     94        },
     95        {
     96            name    => 'mytime',
     97            class   => 'time',
     98            type    => 'TT',
     99            value   => undef,
     100            comment => 'comment',
     101        },
     102    ];
     103
     104    is_deeply( $config, $tree, "NULL times with comments structure" );
     105}
     106
     107{
     108my $example =<<END;
     109recently    MULTI
     110recently    UTC     2005-03-18T16:05:00
     111recently    UT1     2005-03-18T16:05:00
     112recently    TAI     2005-03-18T16:05:00
     113recently    TT      2005-03-18T16:05:00
     114END
     115
     116    my $config = $config_parser->parse( $example );
     117    ok( defined( $config ), "basic ISO8601 parsed");
     118
     119    my $tree = [
     120        {
     121            name    => 'recently',
     122            class   => 'time',
     123            type    => 'UTC',
     124            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     125        },
     126        {
     127            name    => 'recently',
     128            class   => 'time',
     129            type    => 'UT1',
     130            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     131        },
     132        {
     133            name    => 'recently',
     134            class   => 'time',
     135            type    => 'TAI',
     136            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     137        },
     138        {
     139            name    => 'recently',
     140            class   => 'time',
     141            type    => 'TT',
     142            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     143        },
     144    ];
     145
     146    is_deeply( $config, $tree, "basic ISO8601 structure" );
     147}
     148
     149{
     150my $example =<<END;
     151recently    MULTI
    21152recently    UTC     2005-03-18T16:05:00Z
    22153recently    UT1     2005-03-18T16:05:00Z
     
    24155recently    TT      2005-03-18T16:05:00Z
    25156END
    26     my $config = $config_parser->parse( $example );
    27     ok( defined( $config ), "basic IS8601");
    28 }
    29 
    30 {
    31 my $example =<<END;
     157
     158    my $config = $config_parser->parse( $example );
     159    ok( defined( $config ), "basic ISO8601 w/Z parsed");
     160
     161    my $tree = [
     162        {
     163            name    => 'recently',
     164            class   => 'time',
     165            type    => 'UTC',
     166            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     167        },
     168        {
     169            name    => 'recently',
     170            class   => 'time',
     171            type    => 'UT1',
     172            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     173        },
     174        {
     175            name    => 'recently',
     176            class   => 'time',
     177            type    => 'TAI',
     178            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     179        },
     180        {
     181            name    => 'recently',
     182            class   => 'time',
     183            type    => 'TT',
     184            value   => DateTime::Format::ISO8601->parse_datetime("2005-03-18T16:05:00Z"),
     185        },
     186    ];
     187
     188    is_deeply( $config, $tree, "basic ISO8601 w/Z structure" );
     189}
     190
     191{
     192my $example =<<END;
     193recently    MULTI
    32194recently    UTC     2005-03-18T16:05:00.000001Z
    33195recently    UT1     2005-03-18T16:05:00.000001Z
     
    36198END
    37199    my $config = $config_parser->parse( $example );
    38     ok( defined( $config ), "basic IS8601 with fractional seconds");
    39 }
    40 
    41 {
    42 my $example =<<END;
     200    ok( defined( $config ), "basic IS8601 with fractional seconds parsed");
     201}
     202
     203{
     204my $example =<<END;
     205recently    MULTI
    43206recently    UTC     2005-03-18T16:05:00Z    # foo
    44207recently    UT1     2005-03-18T16:05:00Z    # bar
     
    47210END
    48211    my $config = $config_parser->parse( $example );
    49     ok( defined( $config ), "ISO8601 with comments");
    50 }
    51 
    52 {
    53 my $example =<<END;
     212    ok( defined( $config ), "ISO8601 with comments parsed");
     213}
     214
     215{
     216my $example =<<END;
     217recently    MULTI
    54218recently    UTC     2005-03-18T16:05:00.000001Z    # foo
    55219recently    UT1     2005-03-18T16:05:00.000001Z    # bar
     
    58222END
    59223    my $config = $config_parser->parse( $example );
    60     ok( defined( $config ), "ISO8601 with comments and fractional seconds");
    61 }
    62 
    63 {
    64 my $example =<<END;
     224    ok( defined( $config ), "ISO8601 with comments and fractional seconds parsed");
     225}
     226
     227diag("epoch time format maybe deprecated");
     228
     229{
     230my $example =<<END;
     231recently    MULTI
    65232recently    UTC     123456, 5000, 1
    66233recently    UT1     123456, 5000
     
    69236END
    70237    my $config = $config_parser->parse( $example );
    71     ok( defined( $config ), "basic epoch time");
    72 }
    73 
    74 {
    75 my $example =<<END;
     238    ok( defined( $config ), "basic epoch time parsed");
     239}
     240
     241{
     242my $example =<<END;
     243recently    MULTI
    76244recently    UTC     123456, 5000, 1         # foo
    77245recently    UT1     123456, 5000            # bar
     
    80248END
    81249    my $config = $config_parser->parse( $example );
    82     ok( defined( $config ), "epoch time with comments");
    83 }
    84 
    85 {
    86 my $example =<<END;
    87 broken      UTC     2005-03-18T16:05:00
    88 END
    89     my $config = $config_parser->parse( $example );
    90     ok( !defined( $config ), "bad format");
    91 }
    92 
    93 {
    94 my $example =<<END;
    95 broken      UT1     2005-03-18T16:05:00
    96 END
    97     my $config = $config_parser->parse( $example );
    98     ok( !defined( $config ), "bad format");
    99 }
    100 
    101 {
    102 my $example =<<END;
    103 broken      TAI     2005-03-18T16:05:00
    104 END
    105     my $config = $config_parser->parse( $example );
    106     ok( !defined( $config ), "bad format");
    107 }
    108 
    109 {
    110 my $example =<<END;
    111 broken      TT      2005-03-18T16:05:00
    112 END
    113     my $config = $config_parser->parse( $example );
    114     ok( !defined( $config ), "bad format");
    115 }
     250    ok( defined( $config ), "epoch time with comments parsed");
     251}
     252
     253{
     254my $example =<<END;
     255broken      UTC     2005-03-18 16:05:00
     256END
     257    my $config = $config_parser->parse( $example );
     258    ok( !defined( $config ), "bad format");
     259}
     260
     261{
     262my $example =<<END;
     263broken      UT1     2005-03-18 16:05:00
     264END
     265    my $config = $config_parser->parse( $example );
     266    ok( !defined( $config ), "bad format");
     267}
     268
     269{
     270my $example =<<END;
     271broken      TAI     2005-03-18 16:05:00
     272END
     273    my $config = $config_parser->parse( $example );
     274    ok( !defined( $config ), "bad format");
     275}
     276
     277{
     278my $example =<<END;
     279broken      TT      2005-03-18 16:05:00
     280END
     281    my $config = $config_parser->parse( $example );
     282    ok( !defined( $config ), "bad format");
     283}
Note: See TracChangeset for help on using the changeset viewer.