-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDates.php
53 lines (48 loc) · 1.17 KB
/
Dates.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
<?php
namespace core;
class Dates
{
// Convert $date into $step intervals.
// $step is in 5min intervals
//
// @param int $date unixtimestamp
// @param int $step step * 5min
public static function consolidate($date, $step = null)
{
if ($step === null) $step = 60 * 5 * $step; // 5min intervals
$addl = $date % $step;
return $date - $addl;
}
// Get $entries related from $today in upcoming years
public static function years($today, $entries = 6)
{
$year = strtotime($today);
if ($year === false) {
return false;
}
$out = [date("Y", $year)];
for ($i = 1; $i < $entries; $i++) {
$year = strtotime("+1 year", $year);
if ($year === false) {
return false;
}
$out[] = date("Y", $year);
}
if (! arsort($out)) {
return false;
}
return array_values($out);
}
// Get days between $from-$to (unixtimestamps)
public static function days($from, $to)
{
$datediff = $to - $from;
return round($datediff / (60 * 60 * 24));
}
// Get hours between $from-$to (unixtimestamps)
public static function hours($from, $to)
{
$datediff = $to - $from;
return round($datediff / (60 * 60));
}
}