DateUtils.pm
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# --
# Kernel/System/DateUtils.pm - date/time utils
#
# Copyright (C) 2014-2018 - SeTIC - UFSC - http://setic.ufsc.br/
# Version 2015-08-01 - Adjustments for OTRS 4
# Version 2018-01-05 - Adjustments for OTRS 6
#
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
#
package Kernel::System::DateUtils;
use strict;
use warnings;
use Data::Dumper;
require DateTime;
use Time::Piece;
our @ObjectDependencies = ();
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {%Param};
bless( $Self, $Type );
return $Self;
}
=item NewTimestamp()
Creates a new date from the parameters
$ocurrenceObject->NewTimestamp(
Year => int,
Month => int,
Day => int,
Hour => int,
Minute => int,
Second => int
);
=cut
sub NewTimestamp {
my ( $Self, %Param ) = @_;
my $date = DateTime->new(
year => $Param{Year},
month => $Param{Month},
day => $Param{Day},
hour => $Param{Hour},
minute => $Param{Minute},
second => $Param{Second}
);
return $date;
}
=item AddDays()
Adds a number of days to a timestamp
$ocurrenceObject->AddDays(
Timestamp => DateTime,
Days => int
);
=cut
sub AddDays {
my ( $Self, %Param ) = @_;
my $timestamp = $Param{Timestamp};
$timestamp->add( days => $Param{Days} );
}
=item GetDateFromParams()
Create a DateTime based on parameter values
$ocurrenceObject->GetDateFromParams(
Prefix => string,
ParamObject => ParamObject
);
=cut
sub GetDateFromParams {
my ( $Self, %Param ) = @_;
my $Prefix = $Param{"Prefix"};
my $ParamObject = $Param{"ParamObject"};
return $Self->NewTimestamp(
Year => $ParamObject->GetParam(Param => $Prefix . "Year"),
Month => $ParamObject->GetParam(Param => $Prefix . "Month"),
Day => $ParamObject->GetParam(Param => $Prefix . "Day"),
Hour => $ParamObject->GetParam(Param => $Prefix . "Hour"),
Minute => $ParamObject->GetParam(Param => $Prefix . "Minute"),
Second => 0
);
}
sub SQLDate {
my ( $Self, %Param ) = @_;
my $timestamp = $Param{"Timestamp"};
return $timestamp->strftime("%y-%m-%d %H:%M:%S");
}
sub BrazilianDate {
my ( $Self, %Param ) = @_;
my $timestamp = $Param{"Timestamp"};
return $timestamp->strftime("%d/%m/%y %H:%M:%S");
}
sub FromSQL {
my ( $Self, %Param ) = @_;
my $timestamp = $Param{"StringDate"};
return Time::Piece->strptime($timestamp, "%Y-%m-%d %H:%M:%S");
}
1;