DBIx::XMLServer::DateField - date field type


DBIx-XMLServer documentation Contained in the DBIx-XMLServer distribution.

Index


Code Index:

NAME

Top

DBIx::XMLServer::DateField - date field type

DESCRIPTION

Top

This class implements the built-in date field type of DBIx::XMLServer. The where and value methods are overridden from the base class.

To use this field type, you must have the Date::Manip package installed.

where method

  $sql_expression = $date_field->where($condition);

The condition may consist of one of the comparison operators '=', '<', '>', '>=' or '<=' followed by a date. The date may be in any format understood by the Date::Manip package, such as '1976-02-28' or 'two months ago'.

Alternatively, the condition may be empty, in which case the SQL expression is

  <field> IS NOT NULL .

If the condition is the character '!', then the SQL expression is

  <field> IS NULL .

value method

  $date = $date_field->value(\@results);

The date is returned as 'YYYY-mm-dd', as required by the xsd:date type of XML Schema.

SEE ALSO

Top

DBIx::XMLServer::Field

AUTHOR

Top

Martin Bright <martin@boojum.org.uk>

COPYRIGHT AND LICENCE

Top


DBIx-XMLServer documentation Contained in the DBIx-XMLServer distribution.
# $Id: DateField.pm,v 1.5 2005/10/05 20:39:34 mjb47 Exp $

package DBIx::XMLServer::DateField;
use XML::LibXML;
use Date::Manip qw( Date_Init UnixDate );
our @ISA = ('DBIx::XMLServer::Field');

sub BEGIN { Date_Init("DateFormat = EU"); }

sub where {
  my $self = shift;
  my $cond = shift;
  my $column = $self->select;
  return "$column IS NOT NULL" if $cond eq '';
  return "$column IS NULL" if $cond eq '!';
  my ($comp, $date) = ($cond =~ /([=<>]+)(.*)/);
  defined $comp or die "Unrecognised date condition: $cond\n";
  $comp =~ /^(=|[<>]=?)$/ or die "Unrecognised date comparison: $comp\n";
  my $date1 = UnixDate($date, '%Q') or die "Unrecognised date: $date\n";
  return "$column $comp " . $date1;
}

sub value {
  shift;
  return UnixDate(shift @{shift()}, '%Y-%m-%d');
}

1;

__END__