1Rose::DB::Object::MakeMUestehrodCso:n:tTriimbeu(t3e)d PeRrolseD:o:cDuBm:e:nOtbajteicotn::MakeMethods::Time(3)
2
3
4

NAME

6       Rose::DB::Object::MakeMethods::Time - Create time-related methods for
7       Rose::DB::Object-derived objects.
8

SYNOPSIS

10           package MyDBObject;
11
12           use base 'Rose::DB::Object';
13
14           use Rose::DB::Object::MakeMethods::Time
15           (
16             interval =>
17             [
18               t1 => { scale => 6 },
19               t2 => { default => '3 days 6 minutes 5 seconds' },
20             ],
21
22             time =>
23             [
24               start => { scale => 5 },
25               end   => { default => '12:34:56' },
26             ],
27           );
28
29           ...
30
31           $o->t1('5 minutes 0.003 seconds');
32
33           $dt_dur = $o->t1; # DateTime::Duration object
34
35           print $o->t1->minutes;    # 5
36           print $o->t1->nanosecond; # 3000000
37
38           $o->start('12:34:56.12345');
39
40           print $o->start->nanosecond; # 123450000
41           print $o->start->as_string;  # 12:34:56.12345
42
43           $o->end('6pm');
44
45           $tc = $o->end; # Time::Clock object
46
47           print $o->end->hour; # 18
48           print $o->end->ampm; # PM
49
50           print $o->end->format('%I:%M %p'); # 6:00 PM
51           $o->end->add(hours => 1);
52           print $o->end->format('%I:%M %p'); # 7:00 PM
53

DESCRIPTION

55       "Rose::DB::Object::MakeMethods::Time" creates methods that deal with
56       times, and inherits from Rose::Object::MakeMethods.  See the
57       Rose::Object::MakeMethods documentation to learn about the interface.
58       The method types provided by this module are described below.
59
60       All method types defined by this module are designed to work with
61       objects that are subclasses of (or otherwise conform to the interface
62       of) Rose::DB::Object.  In particular, the object is expected to have a
63       db method that returns a Rose::DB-derived object.  See the
64       Rose::DB::Object documentation for more details.
65

METHODS TYPES

67       interval
68           Create get/set methods for interval (years, months, days, hours,
69           minutes, seconds) attributes.
70
71           Options
72               "default"
73                   Determines the default value of the attribute.
74
75               "end_of_month_mode"
76                   This mode determines how math is done on duration objects.
77                   If defined, the "end_of_month" setting for each
78                   DateTime::Duration object created by this method will be
79                   set to the specified mode.  Otherwise, the "end_of_month"
80                   parameter will not be passed to the DateTime::Duration
81                   constructor.
82
83                   Valid modes are "wrap", "limit", and "preserve".  See the
84                   documentation for DateTime::Duration for a full
85                   explanation.
86
87               "hash_key"
88                   The key inside the hash-based object to use for the storage
89                   of this attribute.  Defaults to the name of the method.
90
91               "interface"
92                   Choose the interface.  The default is "get_set".
93
94               "scale"
95                   An integer number of places past the decimal point
96                   preserved for fractional seconds.  Defaults to 0.
97
98           Interfaces
99               "get_set"
100                   Creates a get/set method for a interval (years, months,
101                   days, hours, minutes, seconds) attribute.  When setting the
102                   attribute, the value is passed through the parse_interval
103                   method of the object's db attribute.  If that fails, a
104                   fatal error will occur.
105
106                   When saving to the database, the method will pass the
107                   attribute value through the format_interval method of the
108                   object's db attribute before returning it.
109
110                   This method is designed to allow interval values to make a
111                   round trip from and back into the database without ever
112                   being "inflated" into DateTime::Duration objects.  Any use
113                   of the attribute (get or set) outside the context of
114                   loading from or saving to the database will cause the value
115                   to be "inflated" using the  parse_interval method of the
116                   object's db attribute.
117
118               "get"
119                   Creates an accessor method for a interval (years, months,
120                   days, hours, minutes, seconds) attribute.  This method
121                   behaves like the "get_set" method, except that the value
122                   cannot be set.
123
124               "set"
125                   Creates a mutator method for a interval (years, months,
126                   days, hours, minutes, seconds) attribute.  This method
127                   behaves like the "get_set" method, except that a fatal
128                   error will occur if no arguments are passed.
129
130           Example:
131
132               package MyDBObject;
133
134               use base 'Rose::DB::Object';
135
136               use Rose::DB::Object::MakeMethods::Time
137               (
138                 time =>
139                 [
140                   't1' => { scale => 6 },
141                   't2' => { default => '3 days 6 minutes 5 seconds' },
142                 ],
143               );
144
145               ...
146
147               $o->t1('5 minutes 0.003 seconds');
148
149               $dt_dur = $o->t1; # DateTime::Duration object
150
151               print $o->t1->minutes;    # 5
152               print $o->t1->nanosecond; # 3000000
153
154       time
155           Create get/set methods for time (hours, minutes, seconds)
156           attributes.  Fractional seconds up to nanosecond precision are
157           supported.
158
159           Options
160               "default"
161                   Determines the default value of the attribute.
162
163               "hash_key"
164                   The key inside the hash-based object to use for the storage
165                   of this attribute.  Defaults to the name of the method.
166
167               "interface"
168                   Choose the interface.  The default is "get_set".
169
170               "scale"
171                   An integer number of places past the decimal point
172                   preserved for fractional seconds.  Defaults to 0.  The
173                   maximum value is 9.
174
175           Interfaces
176               "get_set"
177                   Creates a get/set method for a time attribute.  When
178                   setting the attribute, the value is passed through the
179                   parse_time method of the object's db attribute.  If that
180                   fails, a fatal error will occur.
181
182                   When saving to the database, the method will pass the
183                   attribute value through the format_time method of the
184                   object's db attribute before returning it.
185
186                   This method is designed to allow time values to make a
187                   round trip from and back into the database without ever
188                   being "inflated" into Time::Clock objects.  Any use of the
189                   attribute (get or set) outside the context of loading from
190                   or saving to the database will cause the value to be
191                   "inflated" using the  parse_time method of the object's db
192                   attribute.
193
194               "get"
195                   Creates an accessor method for a time attribute.  This
196                   method behaves like the "get_set" method, except that the
197                   value cannot be set.
198
199               "set"
200                   Creates a mutator method for a time attribute.  This method
201                   behaves like the "get_set" method, except that a fatal
202                   error will occur if no arguments are passed.
203
204           Example:
205
206               package MyDBObject;
207
208               use base 'Rose::DB::Object';
209
210               use Rose::DB::Object::MakeMethods::Time
211               (
212                 time =>
213                 [
214                   start => { scale => 5 },
215                   end   => { default => '12:34:56' },
216                 ],
217               );
218
219               ...
220
221               $o->start('12:34:56.12345');
222
223               print $o->start->nanosecond; # 123450000
224               print $o->start->as_string;  # 12:34:56.12345
225
226               $o->end('6pm');
227
228               $tc = $o->end; # Time::Clock object
229
230               print $o->end->hour; # 18
231               print $o->end->ampm; # PM
232
233               print $o->end->format('%I:%M %p'); # 6:00 PM
234               $o->end->add(hours => 1);
235               print $o->end->format('%I:%M %p'); # 7:00 PM
236

AUTHOR

238       John C. Siracusa (siracusa@gmail.com)
239

LICENSE

241       Copyright (c) 2010 by John C. Siracusa.  All rights reserved.  This
242       program is free software; you can redistribute it and/or modify it
243       under the same terms as Perl itself.
244
245
246
247perl v5.34.0                      2022-01R-o2s1e::DB::Object::MakeMethods::Time(3)
Impressum