Source
117
117
case 4: return _('Thursday');
118
118
case 5: return _('Friday');
119
119
case 6: return _('Saturday');
120
120
case 0:
121
121
case 7: return _('Sunday');
122
122
}
123
123
124
124
return _s('[Wrong value for day: "%1$s" ]', $num);
125
125
}
126
126
127
-
// Convert seconds (0..SEC_PER_WEEK) to string representation. For example, 212400 -> 'Tuesday 11:00'
128
-
function dowHrMinToStr($value, $display24Hours = false) {
129
-
$dow = $value - $value % SEC_PER_DAY;
130
-
$hr = $value - $dow;
131
-
$hr -= $hr % SEC_PER_HOUR;
132
-
$min = $value - $dow - $hr;
133
-
$min -= $min % SEC_PER_MIN;
134
-
135
-
$dow /= SEC_PER_DAY;
136
-
$hr /= SEC_PER_HOUR;
137
-
$min /= SEC_PER_MIN;
138
-
139
-
if ($display24Hours && $hr == 0 && $min == 0) {
140
-
$dow--;
141
-
$hr = 24;
142
-
}
143
-
144
-
return sprintf('%s %02d:%02d', getDayOfWeekCaption($dow), $hr, $min);
145
-
}
146
-
147
-
// Convert Day Of Week, Hours and Minutes to seconds representation. For example, 2 11:00 -> 212400. false if error occurred
148
-
function dowHrMinToSec($dow, $hr, $min) {
149
-
if (zbx_empty($dow) || zbx_empty($hr) || zbx_empty($min) || !zbx_ctype_digit($dow) || !zbx_ctype_digit($hr) || !zbx_ctype_digit($min)) {
150
-
return false;
151
-
}
152
-
153
-
if ($dow == 7) {
154
-
$dow = 0;
155
-
}
156
-
157
-
if ($dow < 0 || $dow > 6) {
158
-
return false;
159
-
}
160
-
161
-
if ($hr < 0 || $hr > 24) {
162
-
return false;
163
-
}
164
-
165
-
if ($min < 0 || $min > 59) {
166
-
return false;
167
-
}
168
-
169
-
return $dow * SEC_PER_DAY + $hr * SEC_PER_HOUR + $min * SEC_PER_MIN;
170
-
}
171
-
172
127
/**
173
128
* Convert time to a string representation. Return 'Never' if timestamp is 0.
174
129
*
175
130
* @param $format
176
131
* @param null $time
177
132
* @param string|null $timezone
178
133
*
179
134
* @throws Exception
180
135
*
181
136
* @return string
945
900
$result['second'][] = $array;
946
901
}
947
902
elseif (isset($second[$array[$field]])) {
948
903
$result['second'][] = $array;
949
904
}
950
905
}
951
906
952
907
return $result;
953
908
}
954
909
955
-
function zbx_array_push(&$array, $add) {
956
-
foreach ($array as $key => $value) {
957
-
foreach ($add as $newKey => $newValue) {
958
-
$array[$key][$newKey] = $newValue;
959
-
}
960
-
}
961
-
}
962
-
963
-
/**
964
-
* Find if array has any duplicate values and return an array with info about them.
965
-
* In case of no duplicates, empty array is returned.
966
-
* Example of usage:
967
-
* $result = zbx_arrayFindDuplicates(
968
-
* array('a', 'b', 'c', 'c', 'd', 'd', 'd', 'e')
969
-
* );
970
-
* array(
971
-
* 'd' => 3,
972
-
* 'c' => 2,
973
-
* )
974
-
*
975
-
* @param array $array
976
-
*
977
-
* @return array
978
-
*/
979
-
function zbx_arrayFindDuplicates(array $array) {
980
-
$countValues = array_count_values($array); // counting occurrences of every value in array
981
-
foreach ($countValues as $value => $count) {
982
-
if ($count <= 1) {
983
-
unset($countValues[$value]);
984
-
}
985
-
}
986
-
arsort($countValues); // sorting, so that the most duplicates would be at the top
987
-
988
-
return $countValues;
989
-
}
990
-
991
910
/************* STRING *************/
992
911
function zbx_nl2br($str) {
993
912
$str_res = [];
994
913
foreach (explode("\n", $str) as $str_line) {
995
914
array_push($str_res, $str_line, BR());
996
915
}
997
916
array_pop($str_res);
998
917
999
918
return $str_res;
1000
919
}