From cad439ef9ef417497e2970110b62ed467719c6c4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 12 Jan 2011 11:29:50 +0100 Subject: [PATCH] Hilfsfunktionen in DateTime Conflicts: SL/Locale.pm --- SL/Dispatcher.pm | 2 ++ SL/Helper/DateTime.pm | 57 +++++++++++++++++++++++++++++++++++++++++++ SL/Locale.pm | 6 +++++ scripts/console | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 SL/Helper/DateTime.pm diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 4a3f131d3..da7ffef64 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -9,11 +9,13 @@ BEGIN { } use CGI qw( -no_xhtml); +use DateTime; use English qw(-no_match_vars); use SL::Auth; use SL::LXDebug; use SL::Locale; use SL::Common; +use SL::Helper::DateTime; use Form; use List::Util qw(first); use File::Basename; diff --git a/SL/Helper/DateTime.pm b/SL/Helper/DateTime.pm new file mode 100644 index 000000000..fa035ebfe --- /dev/null +++ b/SL/Helper/DateTime.pm @@ -0,0 +1,57 @@ +package DateTime; + +sub now_local { + return shift->now(time_zone => $::locale->get_local_time_zone); +} + +sub today_local { + return shift->now(time_zone => $::locale->get_local_time_zone)->truncate(to => 'day'); +} + +sub to_lxoffice { + return $::locale->format_date(\%::myconfig, $_[0]); +} + +sub from_lxoffice { + return $::locale->parse_date_to_object(\%::myconfig, $_[1]); +} + +1; + +__END__ + +=encoding utf8 + +=head1 NAME + +SL::Helpers::DateTime - helper functions for L + +=head1 FUNCTIONS + +=over 4 + +=item C + +Returns the current time with the time zone set to the local time zone. + +=item C + +Returns the current date with the time zone set to the local time zone. + +=item C + +Formats the date according to the current Lx-Office user's date +format. + +=item C + +Parses a date string formatted in the current Lx-Office user's date +format and returns an instance of L. + +=back + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut diff --git a/SL/Locale.pm b/SL/Locale.pm index e9967396c..c45a1a1f1 100644 --- a/SL/Locale.pm +++ b/SL/Locale.pm @@ -497,4 +497,10 @@ sub restore_numberformat { $myconfig->{numberformat} = $self->{saved_numberformat} if $self->{saved_numberformat}; } +sub get_local_time_zone { + my $self = shift; + $self->{local_time_zone} ||= DateTime::TimeZone->new(name => 'local'); + return $self->{local_time_zone}; +} + 1; diff --git a/scripts/console b/scripts/console index e3129a0d4..42c193ac1 100755 --- a/scripts/console +++ b/scripts/console @@ -39,8 +39,10 @@ package Devel::REPL; use utf8; use CGI qw( -no_xhtml); +use DateTime; use SL::Auth; use SL::Form; +use SL::Helper::DateTime; use SL::Locale; use SL::LXDebug; use Data::Dumper; -- 2.20.1