-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSMTime.php
executable file
·181 lines (138 loc) · 6.68 KB
/
SMTime.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/*------------------------------------------------------------------------------------------
File: SMTime.php
Summary: Stores a start and end time for an Sitemason® Item
Version: 6.0
For version 6.0, the constructor receives a custom data model from SMItem, since we have
separated the start and end timestamps (and SM4 data shoves them into the same block)
Since SMTime is used to contain any timestamp, the "timestamp" property doubles as the
start timestamp (where applicable, like in SMItems).
Copyright (C) 2013 Sitemason, Inc. All Rights Reserved.
------------------------------------------------------------------------------------------*/
class SMTime extends SMObject {
private $timestamp;
private $cleanTimestamp;
private $endTimestamp;
private $isAllDay;
private $timezone;
private $repeatFrequency;
private $repeatCount;
private $repeatInterval;
private $repeatByDay;
private $repeatByWeekNumber;
private $repeatByMonth;
private $repeatByMonthDay;
private $repeatByYearDay;
private $repeatUntilTimestamp;
// The data is a special array originating in SMTime's constructor
function __construct(array $data) {
$this->apiData = $data;
$this->id = $data['id'];
$this->setTimestamp($data['start_time'] ? $data['start_time'] : $data['startTime']);
$this->setEndTimestamp($data['end_time'] ? $data['end_time'] : $data['endTime']);
$this->setTimezone($data['timezone'] ? $data['timezone'] : $data['timeZone']);
if ($data['isAllDay']) {
$this->isAllDay = true;
}
else {
$this->isAllDay = false;
}
$this->setRepeatFrequency($data['repeat_freq'] ? $data['repeat_freq'] : $data['repeatFrequency']);
$this->setRepeatCount($data['repeat_count'] ? $data['repeat_count'] : $data['repeatCount']);
$this->setRepeatInterval($data['repeat_interval'] ? $data['repeat_interval'] : $data['repeatInterval']);
$this->setRepeatByDay($data['repeat_byday'] ? $data['repeat_byday'] : $data['repeatByDay']);
$this->setRepeatByWeekNumber($data['repeat_byweekno'] ? $data['repeat_byweekno'] : $data['repeatByWeekNumber']);
$this->setRepeatByMonth($data['repeat_bymonth'] ? $data['repeat_bymonth'] : $data['repeatByMonth']);
$this->setRepeatByMonthDay($data['repeat_bymonthday'] ? $data['repeat_bymonthday'] : $data['repeatByMonthDay']);
$this->setRepeatByYearDay($data['repeat_byyearday'] ? $data['repeat_byyearday'] : $data['repeatByYearDay']);
$this->setRepeatUntilTimestamp($data['repeat_until'] ? $data['repeat_until'] : $data['repeatUntilTimestamp']);
}
//!
//! Basic get/set methods
//!------------------------------
public function getTimestamp() { return $this->timestamp; }
public function setTimestamp($timestamp) { $this->setStartTimestamp($timestamp); }
public function getStartTimestamp() { return $this->getTimestamp(); }
public function setStartTimestamp($timestamp) { $this->timestamp = $timestamp; }
public function getCleanTimestamp() {
$time = new DateTime($this->timestamp);
return $time;
}
public function getEndTimestamp() { return $this->endTimestamp; }
public function setEndTimestamp($endTimestamp) { $this->endTimestamp = $endTimestamp; }
public function getTimezone() { return $this->timezone; }
public function setTimezone($timezone) { $this->timezone = $timezone; }
public function isAllDay() { return $this->isAllDay; }
public function getRepeatFrequency() { return $this->repeatFrequency; }
public function setRepeatFrequency($repeatFrequency) { $this->repeatFrequency = $repeatFrequency; }
public function getRepeatCount() { return $this->repeatCount; }
public function setRepeatCount($repeatCount) { $this->repeatCount = $repeatCount; }
public function getRepeatInterval() { return $this->repeatInterval; }
public function setRepeatInterval($repeatInterval) { $this->repeatInterval = $repeatInterval; }
public function getRepeatByDay() { return $this->repeatByDay; }
public function setRepeatByDay($repeatByDay) { $this->repeatByDay = $repeatByDay; }
public function getRepeatByWeekNumber() { return $this->repeatByWeekNumber; }
public function setRepeatByWeekNumber($repeatByWeekNumber) { $this->repeatByWeekNumber = $repeatByWeekNumber; }
public function getRepeatByMonth() { return $this->repeatByMonth; }
public function setRepeatByMonth($repeatByMonth) { $this->repeatByMonth = $repeatByMonth; }
public function getRepeatByMonthDay() { return $this->repeatByMonthDay; }
public function setRepeatByMonthDay($repeatByMonthDay) { $this->repeatByMonthDay = $repeatByMonthDay; }
public function getRepeatByYearDay() { return $this->repeatByYearDay; }
public function setRepeatByYearDay($repeatByYearDay) { $this->repeatByYearDay = $repeatByYearDay; }
public function getRepeatUntilTimestamp() { return $this->repeatUntilTimestamp; }
public function setRepeatUntilTimestamp($repeatUntilTimestamp) { $this->repeatUntilTimestamp = $repeatUntilTimestamp; }
//!
//! PHP DateTime-related methods
//!------------------------------
/**
Returns a PHP DateTime object for this SMTime's start timestamp
*/
public function getStartDateTime() {
$startDateTime = new DateTime($this->getStartTimestamp());
return $startDateTime;
}
public function getEndDateTime() {
$endDateTime = new DateTime($this->getEndTimestamp());
return $endDateTime;
}
public function getRepeatUntilDateTime() {
$repeatUntilDateTime = new DateTime($this->getRepeatUntilTimestamp());
return $repeatUntilDateTime;
}
//!
//! Other methods
//!------------------------------
/**
Convenience method for people trying to get a start date (without time)
*/
public function getStartDate() {
$startTimestamp = new DateTime($this->getTimestamp());
return $startTimestamp->format('Y-m-d');
}
/* REMOVED 20140306: doesn't appear to be used. DO NOT PUBLISH.
public function setStartDate($startDateString) {
$startDate = new DateTime($startDateString);
}
*/
/**
Create some JSON to attempt to sensibly describe the properties of this object
Flag "returnDescription" to return the results instead of appending to the smConsoleOutput string.
*/
public function describe() {
global $smConsoleOutput;
$description = array(
'startTimestamp' => $this->getTimestamp(),
'endTimestamp' => $this->getEndTimestamp(),
'isAllDay' => $this->isAllDay(),
'timezone' => $this->getTimezone()
);
// filter
#$src = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c");
#$repl = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b");
#foreach ($description as $key => $value) {
# $description[$key] = str_replace($src, $repl, $value);
#}
return $description;
}
}
?>