aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/DBIx/Class
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-04-25 10:53:39 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-05-02 22:09:30 +0100
commit1edb407cddcd26fda53066c8cc92e8e04ad003b9 (patch)
tree8bff0c223a9e5b3517dd1dcdd4235bbd27614fda /perllib/DBIx/Class
parent54cad1e4d2474fba55485731ca9e2fd1779c524a (diff)
Refactor datetime inflation.
Diffstat (limited to 'perllib/DBIx/Class')
-rw-r--r--perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm b/perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm
new file mode 100644
index 000000000..f2089d5a3
--- /dev/null
+++ b/perllib/DBIx/Class/FixMyStreet/InflateColumn/DateTime.pm
@@ -0,0 +1,36 @@
+package DBIx::Class::FixMyStreet::InflateColumn::DateTime;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class::InflateColumn::DateTime/;
+use FixMyStreet;
+use namespace::clean;
+
+sub _post_inflate_datetime {
+ my $self = shift;
+ my $dt = $self->next::method(@_);
+ FixMyStreet->set_time_zone($dt);
+ return $dt;
+}
+
+sub _pre_deflate_datetime {
+ my $self = shift;
+ my $dt = $self->next::method(@_);
+ $dt->set_time_zone(FixMyStreet->local_time_zone);
+ return $dt;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+DBIx::Class::FixMyStreet::InflateColumn::DateTime
+
+=head1 DESCRIPTION
+
+This acts the same as DBIx::Class::InflateColumn::DateTime, as if a
+'local' timezone object was attached to every datetime column, plus
+alters the timezone upon inflation to the configured timezone if it
+has been set, and uses a singleton to prevent needless disc access.