Bug 5549 : Add a timezone object to C4::Context
authorColin Campbell <colin.campbell@ptfs-europe.com>
Tue, 24 May 2011 14:00:33 +0000 (15:00 +0100)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 19 Mar 2012 23:08:20 +0000 (12:08 +1300)
Will be required by rolling loans to get correct times
NB the setting of the TZ in mysql has not been changed as
this appears to rely on $ENV{TZ} being undefined

C4/Context.pm

index 0417c45..67d31ee 100644 (file)
@@ -104,6 +104,7 @@ use XML::Simple;
 use C4::Boolean;
 use C4::Debug;
 use POSIX ();
+use DateTime::TimeZone;
 
 =head1 NAME
 
@@ -384,6 +385,7 @@ sub new {
     $self->{"userenv"} = undef;        # User env
     $self->{"activeuser"} = undef;        # current active user
     $self->{"shelves"} = undef;
+    $self->{tz} = undef; # local timezone object
 
     bless $self, $class;
     return $self;
@@ -1112,6 +1114,24 @@ sub get_versions {
 }
 
 
+=head2 tz
+
+  C4::Context->tz
+
+  Returns a DateTime::TimeZone object for the system timezone
+
+=cut
+
+sub tz {
+    my $self = shift;
+    if (!defined $context->{tz}) {
+        $context->{tz} = DateTime::TimeZone->new(name => 'local');
+    }
+    return $context->{tz};
+}
+
+
+
 1;
 __END__