← Index
NYTProf Performance Profile   « line view »
For /usr/local/libexec/sympa/task_manager-debug.pl
  Run on Tue Jun 1 22:32:51 2021
Reported on Tue Jun 1 22:35:07 2021

Filename/usr/local/libexec/sympa/Sympa/Tools/Time.pm
StatementsExecuted 0 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
0000s0sSympa::Tools::Time::::BEGIN@30Sympa::Tools::Time::BEGIN@30
0000s0sSympa::Tools::Time::::BEGIN@31Sympa::Tools::Time::BEGIN@31
0000s0sSympa::Tools::Time::::BEGIN@32Sympa::Tools::Time::BEGIN@32
0000s0sSympa::Tools::Time::::BEGIN@33Sympa::Tools::Time::BEGIN@33
0000s0sSympa::Tools::Time::::BEGIN@34Sympa::Tools::Time::BEGIN@34
0000s0sSympa::Tools::Time::::BEGIN@36Sympa::Tools::Time::BEGIN@36
0000s0sSympa::Tools::Time::::date_convSympa::Tools::Time::date_conv
0000s0sSympa::Tools::Time::::duration_convSympa::Tools::Time::duration_conv
0000s0sSympa::Tools::Time::::epoch_convSympa::Tools::Time::epoch_conv
0000s0sSympa::Tools::Time::::get_midnight_timeSympa::Tools::Time::get_midnight_time
0000s0sSympa::Tools::Time::::gettimeofdaySympa::Tools::Time::gettimeofday
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# -*- indent-tabs-mode: nil; -*-
2# vim:ft=perl:et:sw=4
3# $Id$
4
5# Sympa - SYsteme de Multi-Postage Automatique
6#
7# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
8# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
9# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
10# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
11# Copyright 2018 The Sympa Community. See the AUTHORS.md file at the
12# top-level directory of this distribution and at
13# <https://github.com/sympa-community/sympa.git>.
14#
15# This program is free software; you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation; either version 2 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28package Sympa::Tools::Time;
29
30use strict;
31use warnings;
32use POSIX qw();
33use Time::Local qw();
34use Time::HiRes qw();
35
36use constant has_gettimeofday => defined eval { Time::HiRes::gettimeofday() };
37
38## convert an epoch date into a readable date scalar
39# DEPRECATED: No longer used.
40#sub adate($epoch);
41
42# Note: This is used only once.
43sub get_midnight_time {
44 my $epoch = $_[0];
45 my @date = localtime($epoch);
46 return $epoch - $date[0] - $date[1] * 60 - $date[2] * 3600;
47}
48
49sub epoch_conv {
50 my $arg = $_[0]; # argument date to convert
51
52 my $result;
53
54 # decomposition of the argument date
55 my $date;
56 my $duration;
57 my $op;
58
59 if ($arg =~ /^(.+)(\+|\-)(.+)$/) {
60 $date = $1;
61 $duration = $3;
62 $op = $2;
63 } else {
64 $date = $arg;
65 $duration = '';
66 $op = '+';
67 }
68
69 #conversion
70 $date = date_conv($date);
71 $duration = duration_conv($duration, $date);
72
73 if ($op eq '+') { $result = $date + $duration; }
74 else { $result = $date - $duration; }
75
76 return $result;
77}
78
79sub date_conv {
80 my $arg = shift;
81
82 if ($arg eq 'execution_date') { # execution date
83 return time;
84 }
85
86 if ($arg =~ /^\d+$/) { # already an epoch date
87 return $arg;
88 }
89
90 if ($arg =~ /^(\d\d\d\dy)(\d+m)?(\d+d)?(\d+h)?(\d+min)?(\d+sec)?$/) {
91 # absolute date
92
93 my @date = ($6, $5, $4, $3, $2, $1);
94 foreach my $part (@date) {
95 $part =~ s/[a-z]+$// if $part;
96 $part ||= 0;
97 $part += 0;
98 }
99 $date[3] = 1 if $date[3] == 0;
100 $date[4]-- if $date[4] != 0;
101 $date[5] -= 1900;
102
103 return Time::Local::timelocal(@date);
104 }
105
106 return time;
107}
108
109sub duration_conv {
110
111 my $arg = $_[0];
112 my $start_date = $_[1];
113
114 return 0 unless $arg;
115
116 my @date =
117 ($arg =~ /(\d+y)?(\d+m)?(\d+w)?(\d+d)?(\d+h)?(\d+min)?(\d+sec)?$/i);
118 foreach my $part (@date) {
119 $part =~ s/[a-z]+$// if $part; ## Remove trailing units
120 $part ||= 0;
121 }
122
123 my $duration =
124 $date[6] +
125 60 * ($date[5] +
126 60 * ($date[4] + 24 * ($date[3] + 7 * $date[2] + 365 * $date[0]))
127 );
128
129 # specific processing for the months because their duration varies
130 my @months = (
131 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
132 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
133 );
134 my $start = (defined $start_date) ? (localtime($start_date))[4] : 0;
135 for (my $i = 0; $i < $date[1]; $i++) {
136 $duration += $months[$start + $i] * 60 * 60 * 24;
137 }
138
139 return $duration;
140}
141
142sub gettimeofday {
143 return (@_ = Time::HiRes::gettimeofday()) if has_gettimeofday();
144
145 my $orig_locale = POSIX::setlocale(POSIX::LC_NUMERIC());
146 POSIX::setlocale(POSIX::LC_NUMERIC(), 'C');
147
148 my ($second, $subsecond) =
149 split /[.]/, sprintf('%.6f', Time::HiRes::time());
150 $subsecond ||= '0' x 6;
151 $subsecond += 0;
152
153 POSIX::setlocale(POSIX::LC_NUMERIC(), $orig_locale);
154 return ($second, $subsecond);
155}
156
1571;
158__END__