dummy_foundation/lib/XML/XQL/Date.pm
author William Roberts <williamr@symbian.org>
Wed, 03 Jun 2009 18:33:51 +0100
changeset 3 8b87ea768cb8
parent 0 02cd6b52f378
permissions -rw-r--r--
Add a utility to convert raptor timestamps back into localtime. Lots of change to the find_public_apis.pl script, trying to get more insight Add filename globbing to the sbs_findstr.pl script, so you can scan *compile*
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     1
############################################################################
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     2
# Copyright (c) 1998 Enno Derksen
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     3
# All rights reserved.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     4
# This program is free software; you can redistribute it and/or modify it
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     5
# under the same terms as Perl itself. 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     6
############################################################################
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     7
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     8
package XML::XQL::Date;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
     9
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    10
use vars qw(@ISA);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    11
@ISA = qw( XML::XQL::PrimitiveType );
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    12
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    13
use strict;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    14
use Carp;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    15
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    16
BEGIN
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    17
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    18
    # Date::Manip relies on setting of $TZ. 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    19
    unless (defined $ENV{TZ})
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    20
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    21
	$ENV{TZ} = "EST5EDT";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    22
	warn "XML::XQL::Date - setting timezone \$ENV{TZ} to EST5EDT (east coast USA.) Set your TZ environment variable to avoid this message.";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    23
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    24
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    25
use Date::Manip;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    26
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    27
BEGIN {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    28
    # add date() implementation to XQL engine.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    29
    XML::XQL::defineFunction ("date", \&XML::XQL::Date::date, 1, 1, 1);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    30
};
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    31
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    32
use overload 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    33
    'fallback' => 1,		# use default operators, if not specified
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    34
    '<=>' => \&compare,		# also takes care of <, <=, ==, != etc.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    35
    'cmp' => \&compare,		# also takes care of le, lt, eq, ne, etc.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    36
    '""'  => \&yyyymmddhhmmss;	# conversion to string uses yyyymmddhhmmss
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    37
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    38
sub new
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    39
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    40
    my $class = shift;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    41
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    42
    my (%args);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    43
    if (@_ < 2)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    44
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    45
	my $str = @_ ? $_[0] : "";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    46
	%args = (String => $str);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    47
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    48
    else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    49
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    50
	%args = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    51
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    52
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    53
    my $self = bless \%args, $class;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    54
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    55
    if (@_ < 2)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    56
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    57
	my $date = $self->createInternal (@_ ? $_[0] : "now");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    58
	$date = "" unless isValidDate ($date);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    59
	$self->{Internal} = $date;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    60
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    61
    $self;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    62
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    63
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    64
sub createInternal
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    65
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    66
    my ($self, $str) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    67
    Date::Manip::ParseDate ($str);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    68
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    69
# From Date::Manip:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    70
#
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    71
# 2 digit years fall into the 100 year period given by [ CURR-N,
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    72
# CURR+(99-N) ] where N is 0-99.  Default behavior is 89, but other useful
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    73
# numbers might be 0 (forced to be this year or later) and 99 (forced to be
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    74
# this year or earlier).  It can also be set to "c" (current century) or
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    75
# "cNN" (i.e.  c18 forces the year to bet 1800-1899).  Also accepts the
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    76
# form cNNNN to give the 100 year period NNNN to NNNN+99.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    77
#$Date::Manip::YYtoYYYY=89;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    78
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    79
# Use this to force the current date to be set to this:
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    80
#$Date::Manip::ForceDate="";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    81
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    82
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    83
sub isValidDate		# static method
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    84
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    85
    my ($date) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    86
    return 0 unless defined $date;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    87
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    88
    my $year = substr ($date, 0, 4) || 0;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    89
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    90
    $year > 1500;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    91
#?? arbitrary limit - years < 100 cause problems in Date::Manip
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    92
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    93
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    94
sub ymdhms
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    95
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    96
    my $self = shift;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    97
    if (@_)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    98
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
    99
	my ($y, $mon, $d, $h, $m, $s) = @;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   100
#?? implement
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   101
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   102
    else
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   103
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   104
#?? test: x skips a character. Format: "YYYYMMDDhh:mm::ss"
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   105
	return () unless length $self->{Internal};
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   106
#	print "ymhds " . $self->{Internal} . "\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   107
	unpack ("A4A2A2A2xA2xA2", $self->{Internal});
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   108
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   109
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   110
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   111
sub yyyymmddhhmmss
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   112
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   113
    my ($self) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   114
    my ($y, $mon, $d, $h, $m, $s) = $self->ymdhms;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   115
    
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   116
    $y ? "$y-$mon-${d}T$h:$m:$s" : "";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   117
    # using Date::Manip::UnixDate is a bit too slow for my liking
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   118
#?? could add support for other formats
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   119
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   120
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   121
sub xql_toString
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   122
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   123
#?? use $_[0]->{String} or 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   124
    $_[0]->yyyymmddhhmmss;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   125
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   126
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   127
sub xql_compare
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   128
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   129
    my ($self, $other) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   130
    my $type = ref ($self);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   131
    if (ref ($other) ne $type)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   132
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   133
	my $str = $other->xql_toString;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   134
	# Allow users to plug in their own Date class
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   135
	$other = eval "new $type (\$str)";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   136
#?? check result?
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   137
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   138
#print "date::compare self=" . $self->{Internal} . " other=" . $other->{Internal}. "\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   139
    $self->{Internal} cmp $other->{Internal};
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   140
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   141
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   142
sub xql_setSourceNode
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   143
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   144
    $_[0]->{SourceNode} = $_[1];
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   145
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   146
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   147
sub xql_sourceNode
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   148
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   149
    $_[0]->{SourceNode};
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   150
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   151
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   152
sub xql_setValue
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   153
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   154
    my ($self, $val) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   155
    $self->{Internal} = $self->createInternal ($val);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   156
    $self->{String} = $val;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   157
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   158
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   159
# The XQL date() function
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   160
sub date	# static method
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   161
{
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   162
    my ($context, $listref, $text) = @_;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   163
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   164
    $text = XML::XQL::toList ($text->solve ($context, $listref));
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   165
    my @result = ();
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   166
    for my $val (@$text)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   167
    {
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   168
	# Using xql_new allows users to plug-in their own Date class
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   169
	my $date = XML::XQL::xql_new ("date", $val->xql_toString);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   170
#	print "date $val " . XML::XQL::d($val) . " " . $date->xql_toString . "\n";
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   171
	push @result, $date;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   172
    }
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   173
    \@result;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   174
}
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   175
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   176
1; # module return code
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   177
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   178
__END__
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   179
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   180
=head1 NAME
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   181
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   182
XML::XQL::Date - Adds an XQL::Node type for representing and comparing dates and times
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   183
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   184
=head1 SYNOPSIS
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   185
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   186
 use XML::XQL;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   187
 use XML::XQL::Date;
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   188
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   189
 my $query = new XML::XQL::Query (Expr => "doc//timestamp[. < date('12/31/1999')]");
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   190
 my @results = $query->solve ($doc);
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   191
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   192
=head1 DESCRIPTION
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   193
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   194
This package uses the L<Date::Manip> package to add an XQL node type 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   195
(called XML::XQL::Date) that can be used to represent dates and times. 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   196
The Date::Manip package can parse almost any date or time format imaginable.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   197
(I tested it with Date::Manip 5.33 and I know for sure that it doesn't work 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   198
with 5.20 or lower.)
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   199
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   200
It also adds the XQL B<date> function which creates an XML::XQL::Date 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   201
object from a string. See L<XML::XQL::Tutorial> for a description of the date()
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   202
function.
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   203
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   204
You can plug in your own Date type, if you don't want to use Date::Manip 
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   205
 for some reason. See L<XML::XQL> and the XML::XQL::Date source file for
02cd6b52f378 adding synch hg to p4 & create dummy foundation structure scripts
tahirm@symbian.org
parents:
diff changeset
   206
more details.