-
Notifications
You must be signed in to change notification settings - Fork 34
/
CalendarUtils.php
71 lines (61 loc) · 1.61 KB
/
CalendarUtils.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
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*
*/
namespace humhub\modules\tasks;
use DateTime;
/**
* Description of CalendarUtils
*
* @author luke
*/
class CalendarUtils
{
public const DATE_FORMAT = 'Y-m-d';
/**
*
* @param DateTime $date1
* @param DateTime $date2
* @param type $endDateMomentAfter
* @return bool
*/
public static function isFullDaySpan(DateTime $date1, DateTime $date2, $endDateMomentAfter = false)
{
$dateInterval = $date1->diff($date2, true);
if ($endDateMomentAfter) {
if ($dateInterval->days > 0 && $dateInterval->h == 0 && $dateInterval->i == 0 && $dateInterval->s == 0) {
return true;
}
} else {
if ($dateInterval->h == 23 && $dateInterval->i == 59) {
return true;
}
}
return false;
}
/**
* Helper function to get the start_datetime query filter.
* @param string $date
* @param $field
* @param string $eq
* @return array
*/
public static function getStartCriteria($date, $field, $eq = '>=')
{
return [$eq, $field, date(static::DATE_FORMAT, strtotime($date))];
}
/**
* Helper function to get the end_datetime query filter.
* @param string $date
* @param $field
* @param string $eq
* @return array
*/
public static function getEndCriteria($date, $field, $eq = '<=')
{
return [$eq, $field, date(static::DATE_FORMAT, strtotime($date))];
}
}