Rose::DB::Object::MakeMethods::Time(3pm) | User Contributed Perl Documentation | Rose::DB::Object::MakeMethods::Time(3pm) |
Rose::DB::Object::MakeMethods::Time - Create time-related methods for Rose::DB::Object-derived objects.
package MyDBObject; use base 'Rose::DB::Object'; use Rose::DB::Object::MakeMethods::Time ( interval => [ t1 => { scale => 6 }, t2 => { default => '3 days 6 minutes 5 seconds' }, ], time => [ start => { scale => 5 }, end => { default => '12:34:56' }, ], ); ... $o->t1('5 minutes 0.003 seconds'); $dt_dur = $o->t1; # DateTime::Duration object print $o->t1->minutes; # 5 print $o->t1->nanosecond; # 3000000 $o->start('12:34:56.12345'); print $o->start->nanosecond; # 123450000 print $o->start->as_string; # 12:34:56.12345 $o->end('6pm'); $tc = $o->end; # Time::Clock object print $o->end->hour; # 18 print $o->end->ampm; # PM print $o->end->format('%I:%M %p'); # 6:00 PM $o->end->add(hours => 1); print $o->end->format('%I:%M %p'); # 7:00 PM
"Rose::DB::Object::MakeMethods::Time" creates methods that deal with times, and inherits from Rose::Object::MakeMethods. See the Rose::Object::MakeMethods documentation to learn about the interface. The method types provided by this module are described below.
All method types defined by this module are designed to work with objects that are subclasses of (or otherwise conform to the interface of) Rose::DB::Object. In particular, the object is expected to have a db method that returns a Rose::DB-derived object. See the Rose::DB::Object documentation for more details.
Valid modes are "wrap", "limit", and "preserve". See the documentation for DateTime::Duration for a full explanation.
When saving to the database, the method will pass the attribute value through the format_interval method of the object's db attribute before returning it.
This method is designed to allow interval values to make a round trip from and back into the database without ever being "inflated" into DateTime::Duration objects. Any use of the attribute (get or set) outside the context of loading from or saving to the database will cause the value to be "inflated" using the parse_interval method of the object's db attribute.
Example:
package MyDBObject; use base 'Rose::DB::Object'; use Rose::DB::Object::MakeMethods::Time ( time => [ 't1' => { scale => 6 }, 't2' => { default => '3 days 6 minutes 5 seconds' }, ], ); ... $o->t1('5 minutes 0.003 seconds'); $dt_dur = $o->t1; # DateTime::Duration object print $o->t1->minutes; # 5 print $o->t1->nanosecond; # 3000000
When saving to the database, the method will pass the attribute value through the format_time method of the object's db attribute before returning it.
This method is designed to allow time values to make a round trip from and back into the database without ever being "inflated" into Time::Clock objects. Any use of the attribute (get or set) outside the context of loading from or saving to the database will cause the value to be "inflated" using the parse_time method of the object's db attribute.
Example:
package MyDBObject; use base 'Rose::DB::Object'; use Rose::DB::Object::MakeMethods::Time ( time => [ start => { scale => 5 }, end => { default => '12:34:56' }, ], ); ... $o->start('12:34:56.12345'); print $o->start->nanosecond; # 123450000 print $o->start->as_string; # 12:34:56.12345 $o->end('6pm'); $tc = $o->end; # Time::Clock object print $o->end->hour; # 18 print $o->end->ampm; # PM print $o->end->format('%I:%M %p'); # 6:00 PM $o->end->add(hours => 1); print $o->end->format('%I:%M %p'); # 7:00 PM
John C. Siracusa (siracusa@gmail.com)
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2022-10-14 | perl v5.34.0 |