DateTime-Helfer: 'goto' heißt das Keyword, nicht 'gofrom'
[kivitendo-erp.git] / SL / Helper / DateTime.pm
1 package DateTime;
2
3 use strict;
4
5 sub now_local {
6   return shift->now(time_zone => $::locale->get_local_time_zone);
7 }
8
9 sub today_local {
10   return shift->now(time_zone => $::locale->get_local_time_zone)->truncate(to => 'day');
11 }
12
13 sub to_kivitendo {
14   my $self   = shift;
15   my %params = (scalar(@_) == 1) && (ref($_[0]) eq 'HASH') ? %{ $_[0] } : @_;
16   return $::locale->format_date_object($self, %params);
17 }
18
19 sub to_lxoffice {
20   # Legacy name.
21   goto &to_kivitendo;
22 }
23
24 sub from_kivitendo {
25   return $::locale->parse_date_to_object(\%::myconfig, $_[1]);
26 }
27
28 sub from_lxoffice {
29   # Legacy name.
30   goto &from_kivitendo;
31 }
32
33 1;
34
35 __END__
36
37 =encoding utf8
38
39 =head1 NAME
40
41 SL::Helpers::DateTime - helper functions for L<DateTime>
42
43 =head1 FUNCTIONS
44
45 =over 4
46
47 =item C<now_local>
48
49 Returns the current time with the time zone set to the local time zone.
50
51 =item C<today_local>
52
53 Returns the current date with the time zone set to the local time zone.
54
55 =item C<to_kivitendo %param>
56
57 Formats the date and time according to the current kivitendo user's
58 date format with L<Locale::format_datetime_object>.
59
60 The legacy name C<to_lxoffice> is still supported.
61
62 =item C<from_kivitendo $string>
63
64 Parses a date string formatted in the current kivitendo user's date
65 format and returns an instance of L<DateTime>.
66
67 Note that only dates can be parsed at the moment, not the time
68 component (as opposed to L<to_kivitendo>).
69
70 The legacy name C<from_lxoffice> is still supported.
71
72 =back
73
74 =head1 AUTHOR
75
76 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
77
78 =cut