[Jifty-commit] r1720 - jifty/trunk/lib/Jifty/Filter

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Aug 1 14:31:01 EDT 2006


Author: nelhage
Date: Tue Aug  1 14:31:01 2006
New Revision: 1720

Added:
   jifty/trunk/lib/Jifty/Filter/
   jifty/trunk/lib/Jifty/Filter/DateTime.pm

Log:
Adding Jifty::Filter::DateTime, a JDBI filter that promotes DateTime
objects to Jifty::DateTime objects on read, setting the time zone
appropriately.

Added: jifty/trunk/lib/Jifty/Filter/DateTime.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/lib/Jifty/Filter/DateTime.pm	Tue Aug  1 14:31:01 2006
@@ -0,0 +1,46 @@
+use warnings;
+use strict;
+
+=head1 NAME
+
+Jifty::Filter::DateTime -- A Jifty::DBI filter to work with
+                          Jifty::DateTime objects
+
+=head1 DESCRIPTION
+
+Jifty::Filter::DateTime promotes DateTime objects to Jifty::DateTime
+objects on load. This has the side effect of setting their time zone
+based on the record's current user's preferred time zone, when
+available.
+
+=cut
+
+package Jifty::Filter::DateTime;
+use base qw(Jifty::DBI::Filter);
+
+sub decode {
+    my $self = shift;
+    my $value_ref = $self->value_ref;
+
+    return unless ref($$value_ref) && $$value_ref->isa('DateTime');
+
+    # XXX There has to be a better way to do this
+    my %args;
+    for (qw(year month day hour minute second nanosecond)) {
+        $args{$_} = $$value_ref->$_;
+    }
+
+    my $dt = Jifty::DateTime->new(%args);
+    $dt->set_formatter($$value_ref->formatter);
+
+    $$value_ref = $dt;
+}
+
+=head1 SEE ALSO
+
+L<Jifty::DBI::Filter::Date>, L<Jifty::DBI::Filter::DateTime>,
+L<Jifty::DateTime>
+
+=cut
+
+1;


More information about the Jifty-commit mailing list