-
Notifications
You must be signed in to change notification settings - Fork 14
/
CalendarUtils.php
78 lines (63 loc) · 1.82 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
72
73
74
75
76
77
78
<?php
namespace humhub\modules\external_calendar;
use Yii;
use DateTime;
use DateTimeZone;
/**
* Description of CalendarUtils
*
* @author David Born ([staxDB](https://github.com/staxDB))
*/
class CalendarUtils
{
/**
*
* @param DateTime $date1
* @param DateTime $date2
* @param bool|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;
}
public static function checkAllDay($dtstart, $dtend)
{
$start = self::formatDateTimeToAppTime($dtstart);
$end = self::formatDateTimeToAppTime($dtend);
if (self::isFullDaySpan($start, $end, true)) {
return 1;
} else {
return 0;
}
}
public static function formatDateTimeToAppTime($string)
{
$timezone = new DateTimeZone(Yii::$app->timeZone);
$datetime = new DateTime($string);
$datetime->setTimezone($timezone);
return $datetime;
}
public static function formatDateTimeToUTC($string)
{
$timezone = new DateTimeZone('UTC');
$datetime = new DateTime($string);
$datetime->setTimezone($timezone);
return $datetime;
}
public static function formatDateTimeToString($string)
{
$datetime = self::formatDateTimeToAppTime($string);
return $datetime->format('Y-m-d H:i:s');
}
}