Eve/PgSqlType/TimestampWithTimeZone.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« Eve/PgSqlType/Timestamp.pm ↑ Summary
1 package Eve::PgSqlType::TimestampWithTimeZone;
2  
3 2 ▶use parent qw(Eve::PgSqlType);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 use strict;
6 use warnings;
7  
8 use DateTime::Format::Pg;
9 use DBD::Pg ();
10  
11 =head1 NAME
12  
13 B<Eve::PgSqlType::TimestampWithTimeZone> - a PostgreSQL timestamp
14 with timezone type.
15  
16 =head1 SYNOPSIS
17  
18 my $bigint = Eve::PgSqlType::TimestampWithTimeZone->new();
19 $bigint->serialize(value => $datetime);
20  
21 =head1 DESCRIPTION
22  
23 B<Eve::PgSqlType::TimestampWithTimeZone> is a PostgreSQL timestamp
24 with time zone type adapter class.
25  
26 =head1 METHODS
27  
28 =head2 B<get_type()>
29  
30 =head3 Returns
31  
32 The PG_TIMESTAMPTZ type.
33  
34 =cut
35  
36 sub get_type {
37 return DBD::Pg::PG_TIMESTAMPTZ;
38 }
39  
40 =head2 B<wrap()>
41  
42 Wraps an expression with CAST statement.
43  
44 =head3 Arguments
45  
46 =over 4
47  
48 =item C<expression>
49  
50 =back
51  
52 =head3 Returns
53  
54 CAST (C<expression> AS timestamp with time zone)
55  
56 =cut
57  
58 sub wrap {
59 my ($self, %arg_hash) = @_;
60 Eve::Support::arguments(\%arg_hash, my $expression);
61  
62 return 'CAST ('.$expression.' AS timestamp with time zone)';
63 }
64  
65 =head2 B<serialize()>
66  
67 Formats a B<DateTime> object into the appropriate string timestamp
68 with timezone representation with the B<DateTime::Format::Pg> module.
69  
70 =head3 Arguments
71  
72 =over 4
73  
74 =item C<value>
75  
76 =back
77  
78 =head3 Returns
79  
80 The string like '2011-03-21 20:41:34.123456+03'.
81  
82 =cut
83  
84 sub serialize {
85 my ($self, %arg_hash) = @_;
86 Eve::Support::arguments(\%arg_hash, my $value);
87  
88 if (not defined $value) {
89 return 'NULL';
90 }
91  
92 return DateTime::Format::Pg->format_timestamp_with_time_zone($value);
93 }
94  
95 =head2 B<deserialize()>
96  
97 Parces a timestamp with time zone string representation into the
98 appropriate B<DateTime> object with the B<DateTime::Format::Pg>
99 module.
100  
101 =head3 Arguments
102  
103 =over 4
104  
105 =item C<value>
106  
107 =back
108  
109 =head3 Returns
110  
111 A B<DateTime> object.
112  
113 =cut
114  
115 sub deserialize {
116 my ($self, %arg_hash) = @_;
117 Eve::Support::arguments(\%arg_hash, my $value);
118  
119 my $result;
120 if (defined $value) {
121 $result = DateTime::Format::Pg->parse_timestamp_with_time_zone($value);
122 }
123  
124 return $result;
125 }
126  
127 =head1 SEE ALSO
128  
129 =over 4
130  
131 =item L<DateTime>
132  
133 =item L<DateTime::Format::Pg>
134  
135 =item L<DBD::Pg>
136  
137 =item L<Eve::PgSqlType>
138  
139 =back
140  
141 =head1 LICENSE AND COPYRIGHT
142  
143 Copyright 2012 Igor Zinovyev.
144  
145 This program is free software; you can redistribute it and/or modify it
146 under the terms of either: the GNU General Public License as published
147 by the Free Software Foundation; or the Artistic License.
148  
149 See http://dev.perl.org/licenses/ for more information.
150  
151  
152 =head1 AUTHOR
153  
154 =over 4
155  
156 =item L<Sergey Konoplev|mailto:gray.ru@gmail.com>
157  
158 =back
159  
160 =cut
161  
162 1;
« Eve/PgSqlType/Timestamp.pm ↑ Summary