-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelpers.php
122 lines (105 loc) · 2.7 KB
/
helpers.php
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
122
<?php
use Carbon\Carbon;
if (! function_exists('timeZoneList')) {
/**
* Get all timezone list for select.
* @return mixed
*/
function timeZoneList()
{
return \Cache::rememberForever('timezones', function () {
$optionsArray = timezone_identifiers_list();
$timezones = [];
foreach ($optionsArray as $key => $timezone) {
$timezones[$timezone] = $timezone;
}
return $timezones;
});
}
}
if (! function_exists('priority')) {
function priority()
{
$priority = [];
for ($a = 0; $a < 10; $a++) {
$priority[$a] = $a;
}
return $priority;
}
}
if (! function_exists('months')) {
function months()
{
$months = [];
for ($m = 1; $m <= 12; $m++) {
$months[$m] = date('F', mktime(0, 0, 0, $m, 1));
}
return $months;
}
}
if (! function_exists('hoursFromSeconds')) {
/**
* Get readable hours from seconds.
*
* @param $seconds
* @return float
*/
function hoursFromSeconds($seconds)
{
$hours = floor($seconds / 3600);
if ($hours < 10) {
$hours = '0'.$hours;
}
$minute = floor(($seconds / 60) % 60);
if ($minute < 10) {
$minute = '0'.$minute;
}
return $hours.':'.$minute;
}
}
if (! function_exists('generateDateRange')) {
/**
* Generate Date range.
*
* @param \Carbon\Carbon $start
* @param \Carbon\Carbon $end
* @param string $interval
*
* @return array
*/
function generateDateRange(Carbon $start, Carbon $end, $interval = '1 day')
{
$interval = \DateInterval::createFromDateString($interval);
$daterange = new \DatePeriod($start->second(0), $interval, $end->second(0));
$dates = [];
foreach ($daterange as $date) {
$dates[] = new Carbon($date);
}
return $dates;
}
}
if (! function_exists('amountStrToFloat')) {
/**
* Get float value from amount string.
* @param $amountString
*
* @return float
*/
function amountStrToFloat($amountString)
{
return floatval(str_replace(',', '', $amountString));
}
}
if (! function_exists('validateDate')) {
/**
* @param $date
* @param string $format
* @return bool
*/
function validateDate($date, $format = 'Y-m-d')
{
$d = DateTime::createFromFormat($format, $date);
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
return $d && $d->format($format) === $date;
}
}