Bug 5549 : overdues display should be hours mins aware
[koha.git] / C4 / Context.pm
index 770973f..67d31ee 100644 (file)
@@ -83,18 +83,19 @@ BEGIN {
     $servers = $ENV{'MEMCACHED_SERVERS'};
     if ($servers) {
         # Load required libraries and create the memcached object
-       require Cache::Memcached;
-       $memcached = Cache::Memcached->new({
-                     servers => [ $servers ],
-                     debug   => 0,
-                     compress_threshold => 10_000,
-                     namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha'
-                 });
+        require Cache::Memcached;
+        $memcached = Cache::Memcached->new({
+        servers => [ $servers ],
+        debug   => 0,
+        compress_threshold => 10_000,
+        expire_time => 600,
+        namespace => $ENV{'MEMCACHED_NAMESPACE'} || 'koha'
+    });
         # Verify memcached available (set a variable and test the output)
-       $ismemcached = $memcached->set('ismemcached','1');
+    $ismemcached = $memcached->set('ismemcached','1');
     }
 
-       $VERSION = '3.00.00.036';
+    $VERSION = '3.00.00.036';
 }
 
 use DBI;
@@ -103,6 +104,7 @@ use XML::Simple;
 use C4::Boolean;
 use C4::Debug;
 use POSIX ();
+use DateTime::TimeZone;
 
 =head1 NAME
 
@@ -253,6 +255,31 @@ sub read_config_file {             # Pass argument naming config file to read
     return $koha;                      # Return value: ref-to-hash holding the configuration
 }
 
+=head2 ismemcached
+
+Returns the value of the $ismemcached variable (0/1)
+
+=cut
+
+sub ismemcached {
+    return $ismemcached;
+}
+
+=head2 memcached
+
+If $ismemcached is true, returns the $memcache variable.
+Returns undef otherwise
+
+=cut
+
+sub memcached {
+    if ($ismemcached) {
+      return $memcached;
+    } else {
+      return undef;
+    }
+}
+
 # db_scheme2dbi
 # Translates the full text name of a database into de appropiate dbi name
 # 
@@ -336,15 +363,15 @@ sub new {
     }
     
     if ($ismemcached) {
-      # retreive from memcached
-      $self = $memcached->get('kohaconf');
-      if (not defined $self) {
-       # not in memcached yet
-       $self = read_config_file($conf_fname);
-      }
+        # retreive from memcached
+        $self = $memcached->get('kohaconf');
+        if (not defined $self) {
+            # not in memcached yet
+            $self = read_config_file($conf_fname);
+        }
     } else {
-      # non-memcached env, read from file
-      $self = read_config_file($conf_fname);
+        # non-memcached env, read from file
+        $self = read_config_file($conf_fname);
     }
 
     $self->{"config_file"} = $conf_fname;
@@ -358,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;
@@ -1086,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__