SADI::Data::DateTime - A primitive SADI data type for dates/times


SADI documentation Contained in the SADI distribution.

Index


Code Index:

NAME

Top

SADI::Data::DateTime - A primitive SADI data type for dates/times

SYNOPSIS

Top

 use SADI::Data::DateTime;

 # create a DateTime
 my $data = SADI::Data::DateTime->new (value => '1994-11-05T08:15:30-05:00');
 my $data = SADI::Data::DateTime->new ('1994-11-05T08:15:30-05:00');

DESCRIPTION

Top

An object representing a DateTime, a SADI primitive data type.

The value of this object is stored internally as a string, but upon setting it, the validity is checked. The value should follow the W3C profile of the ISO-8601 specification for specifying dates and times. For example:

    1994-11-05T08:15:30-05:00

corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time, and

    1994-11-05T13:15:30Z

corresponds to the same instant.

AUTHORS

Top

 Edward Kawas (edward.kawas [at] gmail [dot] com)
 Martin Senger (martin.senger [at] gmail [dot] com)

ACCESSIBLE ATTRIBUTES

Top

Details are in SADI::Base. Here just a list of them (additionally to the attributes from the parent classes)

value

A value of this datatype. Must be a string in a particular format. Defaults to time when object is initialized.


SADI documentation Contained in the SADI distribution.
#-----------------------------------------------------------------
# SADI::Data::DateTime
# Author: Edward Kawas <edward.kawas@gmail.com>,
#         Martin Senger <martin.senger@gmail.com>
# For copyright and disclaimer see below.
#
# $Id: DateTime.pm,v 1.4 2010-01-07 21:46:39 ubuntu Exp $
#-----------------------------------------------------------------

package SADI::Data::DateTime;
use base ("SADI::Data::Object");
use strict;

# add versioning to this module
use vars qw /$VERSION/;
$VERSION = sprintf "%d.%02d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;

#-----------------------------------------------------------------
# A list of allowed attribute names. See SADI::Base for details.
#-----------------------------------------------------------------

{
    my %_allowed =
	(
	 value  => {type => SADI::Base->DATETIME},
	 );

    sub _accessible {
	my ($self, $attr) = @_;
	exists $_allowed{$attr} or $self->SUPER::_accessible ($attr);
    }
    sub _attr_prop {
	my ($self, $attr_name, $prop_name) = @_;
	my $attr = $_allowed {$attr_name};
	return ref ($attr) ? $attr->{$prop_name} : $attr if $attr;
	return $self->SUPER::_attr_prop ($attr_name, $prop_name);
    }
}

#-----------------------------------------------------------------
# init
#-----------------------------------------------------------------
sub init {
    my ($self) = shift;
    $self->SUPER::init();
    $self->primitive ('yes');
    $self->value(HTTP::Date::time2isoz (HTTP::Date::str2time (HTTP::Date::parse_date (undef))));
}

1;
__END__