* Get push time from the request body. * @param {Object} request A request object * @returns {Number|undefined} The push time if it exists in the request
(body = {})
| 181 | * @returns {Number|undefined} The push time if it exists in the request |
| 182 | */ |
| 183 | static getPushTime(body = {}) { |
| 184 | var hasPushTime = Object.prototype.hasOwnProperty.call(body, 'push_time'); |
| 185 | if (!hasPushTime) { |
| 186 | return; |
| 187 | } |
| 188 | var pushTimeParam = body['push_time']; |
| 189 | var date; |
| 190 | var isLocalTime = true; |
| 191 | |
| 192 | if (typeof pushTimeParam === 'number') { |
| 193 | date = new Date(pushTimeParam * 1000); |
| 194 | } else if (typeof pushTimeParam === 'string') { |
| 195 | isLocalTime = !PushController.pushTimeHasTimezoneComponent(pushTimeParam); |
| 196 | date = new Date(pushTimeParam); |
| 197 | } else { |
| 198 | throw new Parse.Error( |
| 199 | Parse.Error.PUSH_MISCONFIGURED, |
| 200 | body['push_time'] + ' is not valid time.' |
| 201 | ); |
| 202 | } |
| 203 | // Check pushTime is valid or not, if it is not valid, pushTime is NaN |
| 204 | if (!isFinite(date)) { |
| 205 | throw new Parse.Error( |
| 206 | Parse.Error.PUSH_MISCONFIGURED, |
| 207 | body['push_time'] + ' is not valid time.' |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | return { |
| 212 | date, |
| 213 | isLocalTime, |
| 214 | }; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Checks if a ISO8601 formatted date contains a timezone component |
no test coverage detected