blib/lib/DBIx/QuickORM/Type/DateTime.pm

filter: Statementstmt 100% 120 / 120 Branchbran 100% 46 / 46 Conditioncond 89.1% 33 / 37 MC/DCmcdc 80.9% 17 / 21 Subroutinesub 100% 28 / 28 Podpod 100% 6 / 6 totaltotal 96.9% 250 / 258 CC 38 SCAR 14.7
CC
38
Cov
98%
_parse
9.0
_kind
7.0
canonical_key_value
6.0
CRAP 4.4
« blib/lib/DBIx/QuickORM/Dialect/DuckDB.pm ↑ Summary blib/lib/DBIx/QuickORM/Value.pm »
1 package DBIx::QuickORM::Type::DateTime;
2 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 50 our $VERSION = '0.000031';
6  
7 50 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use DateTime();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 50 ▶use DateTime::Format::ISO8601();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 50 ▶use DateTime::Format::MySQL();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 ▶use DateTime::Format::Pg();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 50 ▶use Hash::Util::FieldHash qw/fieldhash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 50 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 50 ▶use DBIx::QuickORM::Type::DateTime::Lazy();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 50 ▶use Role::Tiny::With qw/with/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 50 with 'DBIx::QuickORM::Role::Type';
19  
20 =pod
21  
22 =encoding UTF-8
23  
24 =head1 NAME
25  
26 DBIx::QuickORM::Type::DateTime - Date and timestamp fields as DateTime objects.
27  
28 =head1 DESCRIPTION
29  
30 Inflates date, timestamp (or datetime), and timestamp with time zone fields
31 into L<DateTime> objects, each wrapped in a
32 L<DBIx::QuickORM::Type::DateTime::Lazy> that builds the DateTime only when it
33 is used. Call DateTime methods on its C<datetime> (a copy to change) or
34 C<datetime_ref> (read only).
35  
36 Dates and timestamps without a zone are floating wall clocks, kept as
37 stored. They inflate to floating DateTimes, unless the stored text carries an
38 offset (SQLite text such as C<2024-02-03T04:05:06Z>, read by
39 L<DateTime::Format::ISO8601>), which keeps that zone. A DateTime is written
40 as its own wall clock, whatever its zone: nothing converts them. A wall clock
41 the ORM's zone skips (a daylight saving gap) still works.X<banned-words-ok>
42  
43 A timestamp with time zone keeps its offset both ways. PostgreSQL and DuckDB
44 store the instant, so it comes back in another offset, as the same instant. A
45 floating DateTime written to one is taken to be in the ORM's C<time_zone>.
46  
47 On MySQL and MariaDB, C<TIMESTAMP> is the timestamp with time zone: the
48 server stores the instant and reads and writes it in the session zone, the
49 ORM's C<time_zone>. A DateTime is converted to that zone when written, and a
50 value comes back in it. C<DATETIME> is the one without a zone.
51  
52 A MySQL or MariaDB C<TIMESTAMP> in the hour a daylight saving zone repeats
53 (clocks set back) is ambiguous: the session zone cannot say which of the two
54 instants it is, so it may read back an hour off. For exact instants keep the
55 ORM's C<time_zone> at its default, C<UTC>, and convert for display with
56 C<< $value->datetime->set_time_zone($zone) >>.
57  
58 L<DateTime::Format::MySQL> 0.08 silently ignores an offset after fractional
59 seconds: C<'2024-02-03 15:05:06.12-07:00'> reads as 15:05:06.12 with no zone.
60 Pass such a value (a primary key given as text, say) as a DateTime, or without
61 the fraction. This is reported upstream.
62  
63 C<time> and C<interval> fields are left alone: a MySQL C<TIME> is a duration,
64 not a time of day.
65  
66 Only a DateTime (a lazy value counts) is deflated. A plain string is sent as
67 given, so it must already be in a form the database accepts.
68  
69 Values are parsed and formatted by the Format classes the dialect names (see
70 C<datetime_format> in L<DBIx::QuickORM::Dialect>): L<DateTime::Format::Pg> on
71 PostgreSQL and DuckDB, L<DateTime::Format::MySQL> on MySQL and MariaDB.
72  
73 Text the dialect's parser cannot read goes to L<DateTime::Format::ISO8601>,
74 then to the ORM's C<datetime_parsers> in order. The first DateTime wins. Text
75 none of them reads croaks when the DateTime is built.
76  
77 On SQLite, values are parsed by L<DateTime::Format::Pg> and written by this
78 type as C<YYYY-MM-DD HH:MM:SS.fraction+HH:MM>. The fraction appears only when
79 there is one, and the offset only for a timestamp with time zone. SQLite's
80 date functions need the colon in the offset. SQLite stores whatever is sent,
81 and its C<CURRENT_TIMESTAMP> is in UTC whatever the ORM's zone.
82  
83 =head1 SYNOPSIS
84  
85 use DateTime;
86  
87 my $ann = $orm->insert(
88 users => {
89 name => 'Ann',
90 created => DateTime->new(
91 year => 2024,
92 month => 2,
93 day => 3,
94 ),
95 },
96 );
97  
98 my $when = $ann->field('created'); # date and timestamp fields are typed by default
99 my $year = $when->datetime_ref->year; # 2024
100 my $next = $when->datetime->add(days => 1); # a copy, so $when is unchanged
101 $ann->update({created => $next});
102  
103 =head1 PUBLIC METHODS
104  
105 =over 4
106  
107 =item @types = $type->base_types
108  
109 C<date>, C<datetime>, C<timestamp>, C<timestamptz>, C<timestamp without time
110 zone>, and C<timestamp with time zone>.
111  
112 =item $bool = $type->is_inflated($value)
113  
114 True for a DateTime, including a lazy value. A lazy value is not parsed to
115 answer.
116  
117 =item $bool = $type->inflated_is_immutable_for_cache
118  
119 True: nothing changes a lazy value, and its C<datetime> is a copy.
120  
121 =back
122  
123 =cut
124  
125 267 ▶sub base_types { ('date', 'datetime', 'timestamp', 'timestamptz', 'timestamp without time zone', 'timestamp with time zone') }
Subroutine base_types: called CC=1 SCAR=0.0
Pod documented
126 94 ▶sub is_inflated { blessed($_[1]) && ($_[1]->isa('DateTime') || $_[1]->isa('DBIx::QuickORM::Type::DateTime::Lazy')) ? 1 : 0 }
Subroutine is_inflated: called CC=4 SCAR=14.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[1]) && ($_[1]->isa('DateTime') || $_[1]->isa('DBIx::QuickORM::Type::DateTime::Lazy')) ? : 10 84 94
Condition66%4/6
builtin::blessed($_[1]) and $_[1]->isa("DateTime") || $_[1]->isa("DBIx::QuickORM::Type::DateTime::Lazy")
!ll&&!rl&&r
84010
$_[1]->isa("DateTime") or $_[1]->isa("DBIx::QuickORM::Type::DateTime::Lazy")
l!l&&r!l&&!r
820
MC/DC33%1/3
builtin::blessed($_[1]) and $_[1]->isa("DateTime") || $_[1]->isa("DBIx::QuickORM::Type::DateTime::Lazy")
builtin::blessed($_[1]) $_[1]->isa("DateTime") $_[1]->isa("DBIx::QuickORM::Type::DateTime::Lazy")
Truth table75%3/4
A and B or C
A= builtin::blessed($_[1])B= $_[1]->isa("DateTime")C= $_[1]->isa("DBIx::QuickORM::Type::DateTime::Lazy")
ABCresult
0XX0
1000
11X1
1011
127 19 ▶sub inflated_is_immutable_for_cache { 1 }
Subroutine inflated_is_immutable_for_cache: called CC=1 SCAR=0.0
Pod documented
128  
129 =pod
130  
131 =over 4
132  
133 =item $lazy = $type->inflate($raw, \%field, $conn)
134  
135 A L<DBIx::QuickORM::Type::DateTime::Lazy> over the raw string.
136  
137 =back
138  
139 =cut
140  
141 25 ▶sub inflate {
Subroutine inflate: called CC=1 SCAR=0.0
Pod documented
142 25 my $class = shift;
143 25 my ($raw, $field, $conn) = @_;
144  
145 25 my ($parser, undef, $kind) = $class->_facts($field, $conn);
146 25 my $extra = $conn->datetime_parsers;
147 25 my $zone = $class->_zone($kind, $conn);
148  
149 return DBIx::QuickORM::Type::DateTime::Lazy->new(
150 23 ▶ sub { $class->_parse($parser, $extra, $kind, $raw, $zone, $field) },
Subroutine __ANON__: called CC=1 SCAR=0.0
151 25 $kind,
152 );
153 }
154  
155 =pod
156  
157 =over 4
158  
159 =item $raw = $type->deflate($datetime, \%field, $conn)
160  
161 The DateTime formatted for the field. A date keeps only its date.
162  
163 Croaks for anything but a DateTime.
164  
165 =back
166  
167 =cut
168  
169 32 ▶sub deflate {
Subroutine deflate: called CC=3 SCAR=11.0
Pod documented
170 32 my $class = shift;
171 32 my ($value, $field, $conn) = @_;
172 32 $value = $class->_unwrap($value);
173 32 ▶ croak "Expected a DateTime object" . $class->_for_field($field) . ", got '$value'" unless blessed($value) && $value->isa('DateTime');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) and $value->isa("DateTime") 2 30 32
Condition66%2/3
builtin::blessed($value) and $value->isa("DateTime")
!ll&&!rl&&r
2030
MC/DC50%1/2
builtin::blessed($value) and $value->isa("DateTime")
builtin::blessed($value) $value->isa("DateTime")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("DateTime")
ABresult
0X0
100
111
174 30 my (undef, $formatter, $kind) = $class->_facts($field, $conn);
175 30 return $class->_format($formatter, $kind, $value, $class->_zone($kind, $conn));
176 }
177  
178 =pod
179  
180 =over 4
181  
182 =item $key = $type->canonical_key_value($value, \%field, $conn)
183  
184 The key form of a value given as database text or as a DateTime (a lazy
185 value counts). Database text is parsed as C<inflate> parses it.
186  
187 =over 4
188  
189 =item *
190  
191 A timestamp with time zone gives its UTC instant: C<YYYY-MM-DDTHH:MM:SS.nnnnnnnnnZ>.
192  
193 =item *
194  
195 A timestamp without one gives its wall clock as it is, the same without the
196 C<Z>.
197  
198 =item *
199  
200 A date gives C<YYYY-MM-DD>.
201  
202 =back
203  
204 A date or timestamp given as a DateTime with a zone gives its own wall clock,
205 as C<deflate> writes it.
206  
207 The fraction always has nine digits, the nanoseconds a DateTime holds.
208  
209 A DateTime finer than the column stores is not the key of the stored, rounded
210 value. Nor is one whose fraction has a leading zero on DuckDB: DBD::DuckDB
211 prints 500 microseconds as C<.500>, which reads back as another instant.
212  
213 =back
214  
215 =cut
216  
217 65 ▶sub canonical_key_value {
Subroutine canonical_key_value: called CC=6 SCAR=17.9
Pod documented
218 65 my $class = shift;
219 65 my ($value, $field, $conn) = @_;
220  
221 65 my ($parser, undef, $kind) = $class->_facts($field, $conn);
222 65 my $zone = $class->_zone($kind, $conn);
223  
224 65 my $dt = $class->_unwrap($value);
225 65 ▶ $dt = $class->_parse($parser, $conn->datetime_parsers, $kind, $value, $zone, $field) unless $class->is_inflated($dt);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->is_inflated($dt) 58 7 65
226 65 ▶ if (defined $zone) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $zone) 16 49 65
227 16 $dt = $dt->clone;
228 16 ▶ $dt->set_time_zone($zone) if $dt->time_zone->is_floating;
Branch: 1 branch
BranchTrueFalseTotal
if $dt->time_zone->is_floating 1 15 16
229 16 $dt->set_time_zone('UTC');
230 }
231 65 ▶ return $dt->ymd if $kind eq 'date';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "date" 21 44 65
232 44 ▶ return $dt->ymd . 'T' . $dt->hms . sprintf('.%09d', $dt->nanosecond) . (defined($zone) ? 'Z' : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $zone ? : 16 28 44
233 }
234  
235 =head1 PRIVATE METHODS
236  
237 =over 4
238  
239 =item $value = $type->_unwrap($value)
240  
241 A lazy value's DateTime (its C<datetime_ref>), or any other value as given.
242  
243 =back
244  
245 =cut
246  
247 97 ▶sub _unwrap {
Subroutine _unwrap: called CC=3 SCAR=11.0
248 97 my $class = shift;
249 97 my ($value) = @_;
250 97 ▶ return blessed($value) && $value->isa('DBIx::QuickORM::Type::DateTime::Lazy') ? $value->datetime_ref : $value;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($value) && $value->isa('DBIx::QuickORM::Type::DateTime::Lazy') ? : 5 92 97
Condition100%3/3
builtin::blessed($value) and $value->isa("DBIx::QuickORM::Type::DateTime::Lazy")
!ll&&!rl&&r
60325
MC/DC100%2/2
builtin::blessed($value) and $value->isa("DBIx::QuickORM::Type::DateTime::Lazy")
builtin::blessed($value) $value->isa("DBIx::QuickORM::Type::DateTime::Lazy")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("DBIx::QuickORM::Type::DateTime::Lazy")
ABresult
0X0
100
111
251 }
252  
253 =pod
254  
255 =over 4
256  
257 =item ($parser, $formatter, $kind) = $type->_facts(\%field, $conn)
258  
259 The dialect's C<datetime_format> parser and formatter, and the field's
260 C<_kind>. Worked out on the first use for a field and dialect, then cached
261 per field record.
262  
263 =back
264  
265 =cut
266  
267 # Keyed by field record: [$dialect, $parser, $formatter, $kind].
268 50 fieldhash my %FACTS;
269  
270 120 ▶sub _facts {
Subroutine _facts: called CC=3 SCAR=11.0
271 120 my $class = shift;
272 120 my ($field, $conn) = @_;
273  
274 120 my $dialect = $conn->dialect;
275 120 my $facts = $FACTS{$field};
276 120 ▶ return @{$facts}[1 .. 3] if $facts && $facts->[0] == $dialect;
Branch: 1 branch
BranchTrueFalseTotal
if $facts and $facts->[0] == $dialect 91 29 120
Condition100%3/3
$facts and $facts->[0] == $dialect
!ll&&!rl&&r
191091
MC/DC100%2/2
$facts and $facts->[0] == $dialect
$facts $facts->[0] == $dialect
Truth table100%3/3
A and B
A= $factsB= $facts->[0] == $dialect
ABresult
0X0
100
111
277  
278 29 my ($parser, $formatter, $instants) = $dialect->datetime_format;
279 29 $FACTS{$field} = [$dialect, $parser, $formatter, $class->_kind($field, $instants)];
280 29 return @{$FACTS{$field}}[1 .. 3];
281 }
282  
283 =pod
284  
285 =over 4
286  
287 =item $kind = $type->_kind(\%field, \%instants)
288  
289  
290 C<date>, C<timestamptz>, or C<timestamp>. A base type in C<%instants> (the
291 dialect's, from C<datetime_format>) is a C<timestamptz>.
292  
293 =back
294  
295 =cut
296  
297 37 ▶sub _kind {
Subroutine _kind: called CC=7 SCAR=19.5
298 37 my $class = shift;
299 37 my ($field, $instants) = @_;
300 37 ▶ my $type = $field->{type} // '';
Condition100%2/2
$field->{"type"} // ""
l!l
352
MC/DC100%1/1
$field->{"type"} // ""
$field->{"type"}
Truth table100%2/2
A
A= $field->{"type"}
Aresult
11
00
301 37 ▶ return 'date' if $type eq 'date';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "date" 10 27 37
302 27 ▶ return 'timestamptz' if $type eq 'timestamptz' || $type =~ m/with time zone$/ || ($instants && $instants->{$type});
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "timestamptz" or $type =~ /with time zone$/ or $instants and $instants->{$type} 7 20 27
Condition100%9/9
$type eq "timestamptz" or $type =~ /with time zone$/ or $instants and $instants->{$type}
l!l&&r!l&&!r
6120
$type eq "timestamptz" or $type =~ /with time zone$/
l!l&&r!l&&!r
5121
$instants and $instants->{$type}
!ll&&!rl&&r
1911
MC/DC100%4/4
$type eq "timestamptz" or $type =~ /with time zone$/ or $instants and $instants->{$type}
$type eq "timestamptz" $type =~ /with time zone$/ $instants $instants->{$type}
Truth table100%5/5
A or B or C and D
A= $type eq "timestamptz"B= $type =~ /with time zone$/C= $instantsD= $instants->{$type}
ABCDresult
1XXX1
01XX1
00111
000X0
00100
303 20 return 'timestamp';
304 }
305  
306 =pod
307  
308 =over 4
309  
310 =item $zone = $type->_zone($kind, $conn)
311  
312 The zone a value of this kind is put in when it has none: the ORM's
313 C<time_zone> for a timestamp with time zone. Undef for a date or timestamp,
314 which stay floating, their wall clock as given.
315  
316 =back
317  
318 =cut
319  
320 120 ▶sub _zone {
Subroutine _zone: called CC=2 SCAR=6.9
321 120 my $class = shift;
322 120 my ($kind, $conn) = @_;
323 120 ▶ return $kind eq 'timestamptz' ? $conn->time_zone : undef;
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'timestamptz' ? : 29 91 120
324 }
325  
326 =pod
327  
328 =over 4
329  
330 =item $dt = $type->_parse($parser, \@parsers, $kind, $raw, $zone, \%field)
331  
332 The DateTime for a raw value. One without a zone of its own is put in
333 C<$zone>, keeping its wall clock. An undef C<$zone> leaves it floating.
334  
335 Tries the dialect's C<$parser>, then L<DateTime::Format::ISO8601>, then each
336 of C<@parsers> (the ORM's C<datetime_parsers>). A parser fails by returning
337 undef or dying. The first DateTime wins, and the caller's C<$@> is left
338 alone. Croaks when one returns anything else, and when none reads the text,
339 naming the field when C<%field> has its C<table> and C<name>.
340  
341 C<parse_datetime> stands in for any method the dialect's parser lacks
342 (L<DateTime::Format::MySQL> has no C<parse_timestamptz>).
343  
344 =back
345  
346 =cut
347  
348 87 ▶sub _parse {
Subroutine _parse: called CC=9 SCAR=22.0
349 87 my $class = shift;
350 87 my ($parser, $extra, $kind, $raw, $zone, $field) = @_;
351  
352 87 local $@;
353 87 ▶ my $method = $parser->can("parse_$kind") ? "parse_$kind" : 'parse_datetime';
Branch: 1 branch
BranchTrueFalseTotal
$parser->can("parse_$kind") ? : 86 1 87
354 my @tries = (
355 87 ▶ sub { $parser->$method($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
356 12 ▶ sub { DateTime::Format::ISO8601->parse_datetime($_[0]) },
Subroutine __ANON__: called CC=1 SCAR=0.0
357 map {
358 87 my $p = $_;
359 2 ▶ ref($p) eq 'CODE' ? $p : sub { $p->parse_datetime($_[0]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
360 14 ▶ } @$extra,
Branch: 1 branch
BranchTrueFalseTotal
ref $p eq 'CODE' ? : 12 2 14
361 );
362  
363 87 for my $try (@tries) {
364 # Failing is how a parser says the text is not its format. The next one gets it.
365 109 ▶ my $dt = eval { $try->($raw) } // next;
Condition100%2/2
eval { do { &$try($raw) } } // (next)
l!l
8524
MC/DC100%1/1
eval { do { &$try($raw) } } // (next)
eval { do { &$try($raw) } }
Truth table100%2/2
A
A= eval { do { &$try($raw) } }
Aresult
11
00
366 85 ▶ croak "A datetime parser returned '$dt' for '$raw'" . $class->_for_field($field) . ", not a DateTime" unless blessed($dt) && $dt->isa('DateTime');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($dt) and $dt->isa("DateTime") 1 84 85
Condition66%2/3
builtin::blessed($dt) and $dt->isa("DateTime")
!ll&&!rl&&r
1084
MC/DC50%1/2
builtin::blessed($dt) and $dt->isa("DateTime")
builtin::blessed($dt) $dt->isa("DateTime")
Truth table66%2/3
A and B
A= builtin::blessed($dt)B= $dt->isa("DateTime")
ABresult
0X0
100
111
367 84 ▶ $dt->set_time_zone($zone) if defined($zone) && $dt->time_zone->is_floating;
Branch: 1 branch
BranchTrueFalseTotal
if defined $zone and $dt->time_zone->is_floating 2 82 84
Condition100%3/3
defined $zone and $dt->time_zone->is_floating
!ll&&!rl&&r
63192
MC/DC100%2/2
defined $zone and $dt->time_zone->is_floating
defined $zone $dt->time_zone->is_floating
Truth table100%3/3
A and B
A= defined $zoneB= $dt->time_zone->is_floating
ABresult
0X0
100
111
368 84 return $dt;
369 }
370  
371 2 croak "Cannot parse '$raw' as a $kind" . $class->_for_field($field) . ": add a parser that reads it to the ORM's datetime_parsers, or leave the field untyped with types => {\$table => {\$field => undef}}";
372 }
373  
374 =pod
375  
376 =over 4
377  
378 =item $raw = $type->_format($formatter, $kind, $dt, $zone)
379  
380 The database form of a DateTime, its wall clock as it is. A floating one is
381 put in C<$zone> first, when C<$zone> is defined.
382  
383 C<format_datetime> stands in for a method the formatter lacks. It writes no
384 offset, so a C<timestamptz> is then converted to C<$zone>, the session's zone
385 (L<DateTime::Format::MySQL> has no C<format_timestamptz>). An undef
386 C<$formatter> means C<_format_own>.
387  
388 =back
389  
390 =cut
391  
392 36 ▶sub _format {
Subroutine _format: called CC=6 SCAR=17.9
393 36 my $class = shift;
394 36 my ($formatter, $kind, $dt, $zone) = @_;
395  
396 36 $dt = $dt->clone;
397 36 ▶ $dt->set_time_zone($zone) if defined($zone) && $dt->time_zone->is_floating;
Branch: 1 branch
BranchTrueFalseTotal
if defined $zone and $dt->time_zone->is_floating 1 35 36
Condition100%3/3
defined $zone and $dt->time_zone->is_floating
!ll&&!rl&&r
21141
MC/DC100%2/2
defined $zone and $dt->time_zone->is_floating
defined $zone $dt->time_zone->is_floating
Truth table100%3/3
A and B
A= defined $zoneB= $dt->time_zone->is_floating
ABresult
0X0
100
111
398 36 ▶ return $class->_format_own($kind, $dt) unless $formatter;
Branch: 1 branch
BranchTrueFalseTotal
unless $formatter 31 5 36
399  
400 5 my $method = "format_$kind";
401 5 ▶ return $formatter->$method($dt) if $formatter->can($method);
Branch: 1 branch
BranchTrueFalseTotal
if $formatter->can($method) 3 2 5
402 2 ▶ $dt->set_time_zone($zone) if $kind eq 'timestamptz';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "timestamptz" 1 1 2
403 2 return $formatter->format_datetime($dt);
404 }
405  
406 =pod
407  
408 =over 4
409  
410 =item $raw = $type->_format_own($kind, $dt)
411  
412 This type's own form of a DateTime already in its zone, used for SQLite.
413  
414 =back
415  
416 =cut
417  
418 31 ▶sub _format_own {
Subroutine _format_own: called CC=4 SCAR=13.9
419 31 my $class = shift;
420 31 my ($kind, $dt) = @_;
421 31 ▶ return $dt->ymd if $kind eq 'date';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "date" 9 22 31
422  
423 22 my $out = $dt->ymd . ' ' . $dt->hms;
424 22 ▶ $out .= sprintf('.%09d', $dt->nanosecond) =~ s/0+$//r if $dt->nanosecond;
Branch: 1 branch
BranchTrueFalseTotal
if $dt->nanosecond 17 5 22
425 22 ▶ $out .= DateTime::TimeZone->offset_as_string($dt->offset, ':') if $kind eq 'timestamptz';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "timestamptz" 11 11 22
426 22 return $out;
427 }
428  
429 50 1;
430  
431 __END__
« blib/lib/DBIx/QuickORM/Dialect/DuckDB.pm ↑ Summary blib/lib/DBIx/QuickORM/Value.pm »