From 4afd70fa0f25386e06aea7103e55366e283e7f19 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 2 Mar 2026 14:14:49 +0100 Subject: [PATCH] Bug 41974: Remove C4::Context from Koha::Object --- C4/Context.pm | 7 +------ Koha/Config.pm | 13 ++++++++++++- Koha/Object.pm | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 74ccd9f5597..3834c2a0038 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -778,12 +778,7 @@ sub get_versions { =cut sub tz { - my $self = shift; - if ( !defined $context->{tz} ) { - my $timezone = $context->{config}->timezone; - $context->{tz} = DateTime::TimeZone->new( name => $timezone ); - } - return $context->{tz}; + return Koha::Config->get_instance->timezone_dt; } =head2 IsSuperLibrarian diff --git a/Koha/Config.pm b/Koha/Config.pm index 3b01e760642..71ddbd903a7 100644 --- a/Koha/Config.pm +++ b/Koha/Config.pm @@ -68,7 +68,9 @@ file will be read only the first time. =cut -our %configs; +our %configs = (); + +our $timezone_dt = undef; sub get_instance { my ( $class, $file ) = @_; @@ -214,6 +216,15 @@ sub timezone { return $timezone; } +sub timezone_dt { + my ($self) = @_; + + unless ( defined $timezone_dt ) { + $timezone_dt = DateTime::TimeZone->new( name => $self->timezone ); + } + return $timezone_dt; +} + sub _read_from_dom_node { my ( $class, $node, $config ) = @_; diff --git a/Koha/Object.pm b/Koha/Object.pm index 55c7e489a06..6bcf2b1caba 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -28,6 +28,7 @@ use List::MoreUtils qw( any ); use DateTime::Format::MySQL; use Koha::Database; +use Koha::Config; use Koha::DateTime::Format::RFC3339; use Koha::DateTime::Format::SQL; use Koha::Exceptions::Object; @@ -880,7 +881,7 @@ sub _recursive_fixup { $value = $dtf->format_date($dt); } else { my $dt = Koha::DateTime::Format::RFC3339->parse_datetime($value); - $dt->set_time_zone( C4::Context->tz ); + $dt->set_time_zone( Koha::Config->get_instance->timezone_dt ); $value = $dtf->format_datetime($dt); } } catch { -- 2.43.0