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