|
Persistent::DataType::DateTime - A Date and Time Class |
Persistent::DataType::DateTime - A Date and Time Class
use Persistent::DataType::DateTime; use English;
eval { ### in case an exception is thrown ###
### allocate a date ###
my $date = new Persistent::DataType::DateTime(localtime);
### get/set value of date ###
$value = $date->value($year, $month, $day,
$hours, $minutes, $seconds);
### get/set year of the date ###
$year = $date->year($new_year);
### get/set month of the date ###
$month = $date->month($new_month);
### get/set day of the date ###
$day = $date->day($new_day);
### get/set hours of the date ###
$hours = $date->hours($new_hours);
### get/set minutes of the date ###
$minutes = $date->minutes($new_minutes);
### get/set seconds of the date ###
$seconds = $date->seconds($new_seconds);
### returns 'cmp' for dates ###
my $cmp_op = $date->get_compare_op();
};
if ($EVAL_ERROR) { ### catch those exceptions! ###
print "An error occurred: $EVAL_ERROR\n";
}
This is a date and time class used by the Persistent framework of classes to implement the attributes of objects. This class provides methods for accessing a date in a variety of formats.
This class is usually not invoked directly, at least not when used with the Persistent framework of classes. However, the constructor arguments of this class are usually of interest when defining the attributes of a Persistent object since the add_attribute method of the Persistent classes instantiates this class directly. Also, the arguments to the value method are of interest when dealing with the accessor methods of the Persistent classes since the accessor methods pass their arguments to the value method and return the string value from the value method.
This class is part of the Persistent base package which is available from:
http://www.bigsnow.org/persistent ftp://ftp.bigsnow.org/pub/persistent
Before we get started describing the methods in detail, it should be noted that all error handling in this class is done with exceptions. So you should wrap an eval block around all of your code. Please see the the Persistent manpage documentation for more information on exception handling in Perl.
use Persistent::DataType::DateTime;
eval {
$date = new Persistent::DataType::DateTime($datestring);
$date = new Persistent::DataType::DateTime('now');
$date = new Persistent::DataType::DateTime('');
$date = new Persistent::DataType::DateTime(undef);
$date = new Persistent::DataType::DateTime($year, $month, $day,
$hour, $min, $sec);
$date = new Persistent::DataType::DateTime(localtime);
};
croak "Exception caught: $@" if $@;
Initializes a DateTime object. This method throws Perl execeptions so use it with an eval block.
This constructor accepts several forms of arguments:
YYYY-MM-DD hh:mm:ss
or
YYYY/MM/DD hh:mm:ss
This is also the format that is returned by the value method of this object.
Another valid format to pass is the following:
DD-Mon-YYYY
where Mon is the three letter abbreviation for the month. The case of the letters is not sensitive (i.e. jan or Jan or JAN is alright).
$year = 0 .. 9999 ### 4 digit year ### $month = 1 .. 12 $day = 1 .. 31 $hours = 0 .. 23 $minutes = 0 .. 59 $seconds = 0 .. 59
eval {
$date_string = $date->value($datestring);
$date_string = $date->value('now');
$date_string = $date->value('');
$date_string = $date->value(undef);
$date_string = $date->value($year, $month, $day,
$hour, $min, $sec);
$date_string = $date->value(localtime);
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the value of the DateTime object. This method throws Perl execeptions so use it with an eval block.
The arguments are as described above in Constructor -- Create a New DateTime Object.
$cmp_op = $date->get_compare_op();
Returns the comparison operator for the DateTime class which is 'cmp'. This method does not throw execeptions.
Parameters:
eval {
### set the year ###
$date->year($new_year);
### get the year ###
$year = $date->year();
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the year of the DateTime object. This method throws Perl execeptions so use it with an eval block.
Parameters:
eval {
### set the month ###
$date->month($new_month);
### get the month ###
$month = $date->month();
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the month of the DateTime object. This method throws Perl execeptions so use it with an eval block.
Parameters:
eval {
### set the day ###
$date->day($new_day);
### get the day ###
$day = $date->day();
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the day of the DateTime object. This method throws Perl execeptions so use it with an eval block.
Parameters:
eval {
### set the hours ###
$date->hours($new_hours);
### get the hours ###
$hours = $date->hours();
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the hours of the DateTime object. This method throws Perl execeptions so use it with an eval block.
Parameters:
eval {
### set the minutes ###
$date->minutes($new_minutes);
### get the minutes ###
$minutes = $date->minutes();
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the minutes of the DateTime object. This method throws Perl execeptions so use it with an eval block.
Parameters:
eval {
### set the seconds ###
$date->seconds($new_seconds);
### get the seconds ###
$seconds = $date->seconds();
};
croak "Exception caught: $@" if $@;
Returns (and optionally sets) the seconds of the DateTime object. This method throws Perl execeptions so use it with an eval block.
Parameters:
the Persistent manpage, the Persistent::DataType::Char manpage, the Persistent::DataType::Number manpage, the Persistent::DataType::String manpage, the Persistent::DataType::VarChar manpage
This software is definitely a work in progress. So if you find any bugs please email them to me with a subject of 'Persistent Bug' at:
winters@bigsnow.org
And you know, include the regular stuff, OS, Perl version, snippet of code, etc.
David Winters <winters@bigsnow.org>
Copyright (c) 1998-2000 David Winters. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Persistent::DataType::DateTime - A Date and Time Class |