ORM::Date - Date handler class.


ORM documentation  | view source Contained in the ORM distribution.

Index


NAME

Top

ORM::Date - Date handler class.

SYNOPSIS

Top

  $date = ORM::Date->new( [ 2006, 1, 25 ] );
  print $date->mysql_date,"\n";
  $date = $date->diff( [ 0, 0, -2 ] );
  print $date->mysql_date,"\n";

  The output is:
  2006-01-25
  2005-11-25

DESCRIPTION

Top

This class introduces minimal interface to handle database table fields of type 'DATE'. It can be used to store time alogn with date, but ORM uses class ORM::Datetime to handle fields of type DATETIME.

Please also consult ORM::Datetime to be sure you know how these classes are used by ORM.

If you want to use another class to handle 'DATE' fields, please consult:

* ORM::Tutorial (THIRD PARTY CLASSES)
* ORM (_db_type_to_class method).
* ORM::Meta.

CONSTRUCTORS

Top

new( [ $year, $month, $mday, $hour, $min, $sec ] )

Create new ORM::Date object as specified in array reference. $year should be exact four digit value. $month is number in range between 1 and 12.

If some value is out of range then it is treated as in mktime syscall, e.g. [2005,10,15,25,15,00] is the same as [2005,10,16,01,15,00].

new_epoch( $seconds_since_epoch )

Create date object from value of seconds since epoch (as returned by time). ORM::Date->new_epoch( time ) is the same as ORM::Date->current.

new_mysql( $datetime_string )

Create date object from MySQL DATE or DATETIME string.

OBJECT PROPERTIES

Top

epoch

Return seconds since epoch for the date object.

sec

Return 'seconds' part of the date.

min

Return 'minutes' part of the date.

hour

Return 'hours' part of the date.

mday

Return day of month of the date.

wday

Return day of week of the date. Value is as returned by localtime in list context.

yday

Return day of year part of the date.

month

Return month of the date.

year

Return year of the date.

mysql_date

Return date in MySQL format (YYYY-MM-DD).

mysql_time

Return time part of the date in MySQL format (HH:MM:SS).

mysql_datetime

Return date and time in MySQL format (YYYY-MM-DD HH:MM:SS).

datetime_str

Return date string as returned by localtime in scalar context.

OBJECT METHODS

Top

set_epoch( $epoch )

Change object by resetting its epoch time to $epoch value.

copy()

Return copy of the object.

diff( [ $year, $month, $mday, $hour, $min, $sec ] )

Return date object with changes applied as specified in argument. Out of range values for resulting object are handled as in mktime syscall.

date

Return object itself.

datetime

Return ORM::datetime object containing the same date.

OVERLOADED OPERATORS

Top

Class ORM::Date overloads following operators:

'>', '<', '>=', '<=', '==', '!=', '<=>', 'cmp'

SEE ALSO

Top

ORM::Datetime

ORM::Meta::ORM::Date

ORM::Meta::ORM::Datetime

AUTHOR

Top

Alexey V. Akimov

COPYRIGHT AND LICENSE

Top


ORM documentation  | view source Contained in the ORM distribution.