Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DateTimeUtilTest.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
37  class DateTimeUtilTest extends BaseTest
38  {
39  public function teardown()
40  {
41  parent::teardown();
42  //reset language to english
43  Yii::app()->setLanguage('en');
44  }
45 
46  //todo:getDatesBetweenTwoDatesInARange($beginDate, $endDate)
47 
48  //todo:getMonthStartAndEndDatesBetweenTwoDatesInARange($beginDate, $endDate)
49  //todo:test year spanning range for days, weeks and months
50  //todo:test timzeon stuff on these??
51 
52  public function testGetDatesBetweenTwoDatesInARange()
53  {
54  $monthsData = DateTimeUtil::getDatesBetweenTwoDatesInARange('2013-01-20', '2013-01-24');
55  $compareData = array('2013-01-20',
56  '2013-01-21',
57  '2013-01-22',
58  '2013-01-23',
59  '2013-01-24');
60  $this->assertEquals($compareData, $monthsData);
61  $monthsData = DateTimeUtil::getDatesBetweenTwoDatesInARange('2013-06-29', '2013-07-01');
62  $compareData = array('2013-06-29',
63  '2013-06-30',
64  '2013-07-01');
65  $this->assertEquals($compareData, $monthsData);
66  $monthsData = DateTimeUtil::getDatesBetweenTwoDatesInARange('2012-12-28', '2013-01-03');
67  $compareData = array('2012-12-28',
68  '2012-12-29',
69  '2012-12-30',
70  '2012-12-31',
71  '2013-01-01',
72  '2013-01-02',
73  '2013-01-03');
74  $this->assertEquals($compareData, $monthsData);
75  }
76 
77  public function testGetWeekStartAndEndDatesBetweenTwoDatesInARange()
78  {
79  $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-08-03');
80  $this->assertEquals('2013-01-20', $monthsData['2013-01-14']);
81  $this->assertEquals('2013-08-04', $monthsData['2013-07-29']);
82  $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-21', '2013-01-28');
83  $compareData = array(
84  '2013-01-21' => '2013-01-27',
85  '2013-01-28' => '2013-02-03');
86  $this->assertEquals($compareData, $monthsData);
87  $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-01-26');
88  $compareData = array(
89  '2013-01-14' => '2013-01-20',
90  '2013-01-21' => '2013-01-27');
91  $this->assertEquals($compareData, $monthsData);
92  $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2014-01-26');
93  $this->assertEquals('2013-01-20', $monthsData['2013-01-14']);
94  $this->assertEquals('2014-01-26', $monthsData['2014-01-20']);
95  $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2012-12-28', '2013-01-03');
96  $compareData = array(
97  '2012-12-24' => '2012-12-30',
98  '2012-12-31' => '2013-01-06');
99  $this->assertEquals($compareData, $monthsData);
100  $monthsData = DateTimeUtil::getWeekStartAndEndDatesBetweenTwoDatesInARange('2013-04-01', '2013-04-01');
101  $compareData = array(
102  '2013-04-01' => '2013-04-07');
103  $this->assertEquals($compareData, $monthsData);
104  }
105 
106  public function testGetMonthStartAndEndDatesBetweenTwoDatesInARange()
107  {
108  $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-02-01', '2013-06-01');
109  $compareData = array(
110  '2013-02-01' => '2013-02-28',
111  '2013-03-01' => '2013-03-31',
112  '2013-04-01' => '2013-04-30',
113  '2013-05-01' => '2013-05-31',
114  '2013-06-01' => '2013-06-30');
115  $this->assertEquals($compareData, $monthsData);
116  $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-08-03');
117  $compareData = array(
118  '2013-01-01' => '2013-01-31',
119  '2013-02-01' => '2013-02-28',
120  '2013-03-01' => '2013-03-31',
121  '2013-04-01' => '2013-04-30',
122  '2013-05-01' => '2013-05-31',
123  '2013-06-01' => '2013-06-30',
124  '2013-07-01' => '2013-07-31',
125  '2013-08-01' => '2013-08-31');
126  $this->assertEquals($compareData, $monthsData);
127  $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2013-01-26');
128  $compareData = array(
129  '2013-01-01' => '2013-01-31');
130  $this->assertEquals($compareData, $monthsData);
131  $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-01-20', '2014-01-26');
132  $compareData = array(
133  '2013-01-01' => '2013-01-31',
134  '2013-02-01' => '2013-02-28',
135  '2013-03-01' => '2013-03-31',
136  '2013-04-01' => '2013-04-30',
137  '2013-05-01' => '2013-05-31',
138  '2013-06-01' => '2013-06-30',
139  '2013-07-01' => '2013-07-31',
140  '2013-08-01' => '2013-08-31',
141  '2013-09-01' => '2013-09-30',
142  '2013-10-01' => '2013-10-31',
143  '2013-11-01' => '2013-11-30',
144  '2013-12-01' => '2013-12-31',
145  '2014-01-01' => '2014-01-31');
146  $this->assertEquals($compareData, $monthsData);
147  $monthsData = DateTimeUtil::getMonthStartAndEndDatesBetweenTwoDatesInARange('2013-04-01', '2013-04-01');
148  $compareData = array(
149  '2013-04-01' => '2013-04-30');
150  $this->assertEquals($compareData, $monthsData);
151  }
152 
153  public function testGetTimeSinceDisplayContent()
154  {
155  //30 minutes ago
156  $timeStampLatestUpdate = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - (30 * 60));
157  $timeSinceLastestUpdate = DateTimeUtil::getTimeSinceDisplayContent($timeStampLatestUpdate);
158  $this->assertEquals('30 minutes ago', $timeSinceLastestUpdate);
159 
160  //58 minutes ago
161  $timeStampLatestUpdate = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - (58 * 60));
162  $timeSinceLastestUpdate = DateTimeUtil::getTimeSinceDisplayContent($timeStampLatestUpdate);
163  $this->assertEquals('58 minutes ago', $timeSinceLastestUpdate);
164 
165  //61 minutes ago
166  $timeStampLatestUpdate = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - (61 * 60));
167  $timeSinceLastestUpdate = DateTimeUtil::getTimeSinceDisplayContent($timeStampLatestUpdate);
168  $this->assertEquals('1 hour ago', $timeSinceLastestUpdate);
169 
170  //3 hours ago
171  $timeStampLatestUpdate = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - (3 * 60 * 60));
172  $timeSinceLastestUpdate = DateTimeUtil::getTimeSinceDisplayContent($timeStampLatestUpdate);
173  $this->assertEquals('3 hours ago', $timeSinceLastestUpdate);
174 
175  //27 hours ago
176  $timeStampLatestUpdate = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - (27 * 60 * 60));
177  $timeSinceLastestUpdate = DateTimeUtil::getTimeSinceDisplayContent($timeStampLatestUpdate);
178  $this->assertEquals('1 day ago', $timeSinceLastestUpdate);
179 
180  //10 days ago
181  $timeStampLatestUpdate = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - (10 * 24 * 60 * 60));
182  $timeSinceLastestUpdate = DateTimeUtil::getTimeSinceDisplayContent($timeStampLatestUpdate);
183  $this->assertEquals('10 days ago', $timeSinceLastestUpdate);
184  }
185 
186  public function testConvertTimestampToDbFormatDateTimeAndBackToTimeStamp()
187  {
188  $time = time();
189  $timeZone = date_default_timezone_get();
190 
191  date_default_timezone_set('GMT');
192  $gmtDbFormatDateTime = Yii::app()->dateFormatter->format(
194 
195  date_default_timezone_set('America/New_York');
196  $dbFormatDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($time);
197  $timeStamp = DateTimeUtil::convertDbFormatDateTimeToTimestamp($dbFormatDateTime);
198  $this->assertEquals($gmtDbFormatDateTime, $dbFormatDateTime);
199  $this->assertEquals($time, $timeStamp);
200  date_default_timezone_set($timeZone);
201  }
202 
203  public function testGetLocaleFormats()
204  {
205  $language = Yii::app()->getLanguage();
206  $this->assertEquals($language, 'en');
207  $this->assertEquals('M/d/yy h:mm a', DateTimeUtil::getLocaleDateTimeFormat());
208  $this->assertEquals('M/d/yy', DateTimeUtil::getLocaleDateFormat());
209  $this->assertEquals('h:mm a', DateTimeUtil::getLocaleTimeFormat());
210  Yii::app()->setLanguage('de');
211  $this->assertEquals('dd.MM.yy HH:mm', DateTimeUtil::getLocaleDateTimeFormat());
212  $this->assertEquals('dd.MM.yy', DateTimeUtil::getLocaleDateFormat());
213  $this->assertEquals('HH:mm', DateTimeUtil::getLocaleTimeFormat());
214  }
215 
216  public function testIsLocaleTimeDisplayedAs12Hours()
217  {
218  $language = Yii::app()->getLanguage();
219  $this->assertEquals($language, 'en');
220  $this->assertTrue(DateTimeUtil::isLocaleTimeDisplayedAs12Hours());
221  Yii::app()->setLanguage('de');
222  $this->assertFalse(DateTimeUtil::isLocaleTimeDisplayedAs12Hours());
223  Yii::app()->setLanguage('fr');
224  $this->assertFalse(DateTimeUtil::isLocaleTimeDisplayedAs12Hours());
225  Yii::app()->setLanguage('it');
226  $this->assertFalse(DateTimeUtil::isLocaleTimeDisplayedAs12Hours());
227  Yii::app()->setLanguage('es');
228  $this->assertFalse(DateTimeUtil::isLocaleTimeDisplayedAs12Hours());
229  }
230 
231  public function testResolveTimeStampForDateTimeLocaleFormattedDisplay()
232  {
233  $value = strtotime("3 June 1980");
234  $displayValue = DateTimeUtil::resolveTimeStampForDateTimeLocaleFormattedDisplay($value);
235  $this->assertEquals('6/3/80 12:00 AM', $displayValue);
236  //For input
237  $value = strtotime("3 June 1920");
238  $displayValue = DateTimeUtil::resolveTimeStampForDateTimeLocaleFormattedDisplay(
239  $value,
240  DateTimeUtil::DATETIME_FORMAT_DATE_WIDTH,
241  DateTimeUtil::DATETIME_FORMAT_TIME_WIDTH,
242  true);
243  $this->assertEquals('6/3/1920 12:00 AM', $displayValue);
244  //other locales
245  Yii::app()->setLanguage('de');
246  $value = strtotime("3 June 1980");
247  $displayValue = DateTimeUtil::resolveTimeStampForDateTimeLocaleFormattedDisplay($value);
248  $this->assertEquals('03.06.80 00:00', $displayValue);
249  //For input
250  $value = strtotime("3 June 1920");
251  $displayValue = DateTimeUtil::resolveTimeStampForDateTimeLocaleFormattedDisplay(
252  $value,
253  DateTimeUtil::DATETIME_FORMAT_DATE_WIDTH,
254  DateTimeUtil::DATETIME_FORMAT_TIME_WIDTH,
255  true);
256  $this->assertEquals('03.06.1920 00:00', $displayValue);
257  }
258 
259  public function testResolveValueForDateLocaleFormattedDisplay()
260  {
261  $displayValue = DateTimeUtil::resolveValueForDateLocaleFormattedDisplay('2007-07-01');
262  $this->assertEquals('7/1/07', $displayValue);
263  //For input
264  $displayValue = DateTimeUtil::resolveValueForDateLocaleFormattedDisplay('2007-07-01', DateTimeUtil::DISPLAY_FORMAT_FOR_INPUT);
265  $this->assertEquals('7/1/2007', $displayValue);
266  //other locales
267  Yii::app()->setLanguage('de');
268  $displayValue = DateTimeUtil::resolveValueForDateLocaleFormattedDisplay('2007-07-01');
269  $this->assertEquals('01.07.07', $displayValue);
270  //For input
271  $displayValue = DateTimeUtil::resolveValueForDateLocaleFormattedDisplay('2007-07-01', DateTimeUtil::DISPLAY_FORMAT_FOR_INPUT);
272  $this->assertEquals('01.07.2007', $displayValue);
273  }
274 
275  public function testResolveValueForDateDBFormatted()
276  {
277  $displayValue = DateTimeUtil::resolveValueForDateDBFormatted('7/1/2007');
278  $this->assertEquals('2007-07-01', $displayValue);
279  //other locales
280  Yii::app()->setLanguage('de');
281  $displayValue = DateTimeUtil::resolveValueForDateDBFormatted('01.07.2007');
282  $this->assertEquals('2007-07-01', $displayValue);
283  }
284 
285  public function testConvertFromUtcUnixStampByTimeZone()
286  {
287  $timeZoneObject = new DateTimeZone('America/Chicago');
288  $offset = $timeZoneObject->getOffset(new DateTime());
289  $this->assertTrue($offset == -18000 || $offset == -21600);
290  $utcTimeStamp = time();
291  $adjustedTimeStamp = DateTimeUtil::convertFromUtcUnixStampByTimeZone($utcTimeStamp, 'America/Chicago');
292  $this->assertEquals($utcTimeStamp + $offset, $adjustedTimeStamp);
293 
294  //other locales
295  $timeZoneObject = new DateTimeZone('America/New_York');
296  $offset = $timeZoneObject->getOffset(new DateTime());
297  $this->assertTrue($offset == -18000 || $offset == -14400);
298  $adjustedTimeStamp = DateTimeUtil::convertFromUtcUnixStampByTimeZone($utcTimeStamp, 'America/New_York');
299  $this->assertEquals($utcTimeStamp + $offset, $adjustedTimeStamp);
300  }
301 
302  public function testIsValidDbFormattedDate()
303  {
304  $this->assertTrue (DateTimeUtil::isValidDbFormattedDate('2011-09-23'));
305  $this->assertTrue (DateTimeUtil::isValidDbFormattedDate('1756-01-01'));
306  $this->assertFalse(DateTimeUtil::isValidDbFormattedDate('0011-09-23'));
307  $this->assertFalse(DateTimeUtil::isValidDbFormattedDate('2011-13-32'));
308  $this->assertFalse(DateTimeUtil::isValidDbFormattedDate('zxczxc'));
309  }
310 
311  public function testIsValidDbFormattedDateTime()
312  {
313  $this->assertTrue (DateTimeUtil::isValidDbFormattedDateTime('2011-09-23 23:23:23'));
314  $this->assertTrue (DateTimeUtil::isValidDbFormattedDateTime('1756-01-01 00:59:59'));
315  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('0011-09-23 23:23:23'));
316  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-13-32 23:23:23'));
317  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('1011-09-23 24:23:23'));
318  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-12-32 23:23:23'));
319  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-12-32 23:60:23'));
320  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('2011-12-32 23:23:60'));
321  $this->assertFalse(DateTimeUtil::isValidDbFormattedDateTime('cascacasc'));
322  }
323 
324  public function testConvertDbFormattedDateTimeToLocaleFormattedDisplay()
325  {
326  $timeZone = date_default_timezone_get();
327  date_default_timezone_set('GMT');
328  $displayValue = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay('1980-06-03 00:00:00');
329  $this->assertEquals('6/3/80 12:00 AM', $displayValue);
330  //other locales
331  Yii::app()->setLanguage('de');
332  $displayValue = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay('1980-06-03 00:00:00');
333  $this->assertEquals('03.06.80 00:00', $displayValue);
334 
335  //test null value returns null.
336  $displayValue = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay(null);
337  $this->assertEquals(null, $displayValue);
338  date_default_timezone_set($timeZone);
339  }
340 
341  public function testConvertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero()
342  {
343  $timeZone = date_default_timezone_get();
344  date_default_timezone_set('GMT');
346  $this->assertEquals('1980-06-03 00:00:00', $dbValue);
347 
348  //other locales
349  Yii::app()->setLanguage('de');
351  $this->assertEquals('1980-06-03 00:00:00', $displayValue);
352 
353  Yii::app()->setLanguage('it');
355  $this->assertEquals('1980-06-03 00:00:00', $displayValue);
356 
357  Yii::app()->setLanguage('fr');
359  $this->assertEquals('1980-06-03 00:00:00', $displayValue);
360 
361  //test null value returns null.
362  $displayValue = DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay(null);
363  $this->assertEquals(null, $displayValue);
364  date_default_timezone_set($timeZone);
365  }
366 
367  public function testGetLocaleDateTimeFormatForInput()
368  {
369  $timeZone = date_default_timezone_get();
370  date_default_timezone_set('GMT');
371  $localDateTimeFormatForInput = DateTimeUtil::getLocaleDateTimeFormatForInput();
372  $this->assertEquals('M/d/yyyy h:mm a', $localDateTimeFormatForInput);
373 
374  //other locales
375  Yii::app()->setLanguage('de');
376  $localDateTimeFormatForInput = DateTimeUtil::getLocaleDateTimeFormatForInput();
377  $this->assertEquals('dd.MM.yyyy HH:mm', $localDateTimeFormatForInput);
378 
379  Yii::app()->setLanguage('it');
380  $localDateTimeFormatForInput = DateTimeUtil::getLocaleDateTimeFormatForInput();
381  $this->assertEquals('dd/MM/yyyy HH:mm', $localDateTimeFormatForInput);
382 
383  Yii::app()->setLanguage('fr');
384  $localDateTimeFormatForInput = DateTimeUtil::getLocaleDateTimeFormatForInput();
385  $this->assertEquals('dd/MM/yyyy HH:mm', $localDateTimeFormatForInput);
386  date_default_timezone_set($timeZone);
387  }
388 
389  public function testGetLocaleDateFormatForInput()
390  {
391  $timeZone = date_default_timezone_get();
392  date_default_timezone_set('GMT');
393  $localDateFormatForInput = DateTimeUtil::getLocaleDateFormatForInput();
394  $this->assertEquals('M/d/yyyy', $localDateFormatForInput);
395 
396  //other locales
397  Yii::app()->setLanguage('de');
398  $localDateFormatForInput = DateTimeUtil::getLocaleDateFormatForInput();
399  $this->assertEquals('dd.MM.yyyy', $localDateFormatForInput);
400 
401  Yii::app()->setLanguage('it');
402  $localDateFormatForInput = DateTimeUtil::getLocaleDateFormatForInput();
403  $this->assertEquals('dd/MM/yyyy', $localDateFormatForInput);
404 
405  Yii::app()->setLanguage('fr');
406  $localDateFormatForInput = DateTimeUtil::getLocaleDateFormatForInput();
407  $this->assertEquals('dd/MM/yyyy', $localDateFormatForInput);
408  date_default_timezone_set($timeZone);
409  }
410 
411  public function testConvertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay()
412  {
413  SecurityTestHelper::createSuperAdmin();
414  Yii::app()->user->userModel = User::getByUsername('super');
415  $super = Yii::app()->user->userModel;
416 
417  $super->timeZone = 'Africa/Nairobi';
418  $saved = $super->save();
419  if (!$saved)
420  {
421  throw new FailedToSaveModelException();
422  }
424  $this->assertEquals($startDateTime, '2014-03-02 21:00:00');
425 
426  $super->timeZone = 'Asia/Hong_Kong';
427  $saved = $super->save();
428  if (!$saved)
429  {
430  throw new FailedToSaveModelException();
431  }
433  $this->assertEquals($startDateTime, '2014-03-02 16:00:00');
434 
435  $super->timeZone = 'America/Chicago';
436  $saved = $super->save();
437  if (!$saved)
438  {
439  throw new FailedToSaveModelException();
440  }
442  $this->assertEquals($startDateTime, '2014-03-03 06:00:00');
444  $this->assertEquals($startDateTime, '2014-03-29 05:00:00');
445  }
446 
447  public function testConvertDateIntoTimeZoneAdjustedDateTimeEndOfDay()
448  {
449  SecurityTestHelper::createSuperAdmin();
450  Yii::app()->user->userModel = User::getByUsername('super');
451  $super = Yii::app()->user->userModel;
452 
453  $super->timeZone = 'Africa/Nairobi';
454  $saved = $super->save();
455  if (!$saved)
456  {
457  throw new FailedToSaveModelException();
458  }
460  $this->assertEquals($endDateTime, '2014-03-03 20:59:59');
461 
462  $super->timeZone = 'Asia/Hong_Kong';
463  $saved = $super->save();
464  if (!$saved)
465  {
466  throw new FailedToSaveModelException();
467  }
469  $this->assertEquals($endDateTime, '2014-03-03 15:59:59');
470 
471  $super->timeZone = 'America/Chicago';
472  $saved = $super->save();
473  if (!$saved)
474  {
475  throw new FailedToSaveModelException();
476  }
478  $this->assertEquals($endDateTime, '2014-03-04 05:59:59');
480  $this->assertEquals($endDateTime, '2014-03-30 04:59:59');
481  }
482 
483  public function testGetFirstDayOfAWeek()
484  {
485  $this->assertEquals('2014-04-21', DateTimeUtil::getFirstDayOfAWeek('2014-04-21 00:00:01'));
486  $this->assertEquals('2014-04-21', DateTimeUtil::getFirstDayOfAWeek('2014-04-23 12:00:00'));
487  $this->assertEquals('2014-04-21', DateTimeUtil::getFirstDayOfAWeek('2014-04-27 23:59:59'));
488  $this->assertEquals('2014-04-14', DateTimeUtil::getFirstDayOfAWeek('2014-04-20 23:59:59'));
489  $this->assertEquals('2014-04-21', DateTimeUtil::getFirstDayOfAWeek('2014-04-24 12:00:00'));
490  $this->assertEquals('2014-04-28', DateTimeUtil::getFirstDayOfAWeek('2014-04-28 00:00:01'));
491  }
492 
493  public function testGetLastDayOfAWeek()
494  {
495  $this->assertEquals('2014-04-27', DateTimeUtil::getLastDayOfAWeek('2014-04-21 00:00:01'));
496  $this->assertEquals('2014-04-27', DateTimeUtil::getLastDayOfAWeek('2014-04-23 12:00:00'));
497  $this->assertEquals('2014-04-27', DateTimeUtil::getLastDayOfAWeek('2014-04-27 23:59:59'));
498  $this->assertEquals('2014-04-20', DateTimeUtil::getLastDayOfAWeek('2014-04-20 23:59:59'));
499  $this->assertEquals('2014-04-27', DateTimeUtil::getLastDayOfAWeek('2014-04-24 12:00:00'));
500  $this->assertEquals('2014-05-04', DateTimeUtil::getLastDayOfAWeek('2014-04-28 00:00:01'));
501  }
502  }
503 ?>
static getByUsername($username)
Definition: User.php:49
static getTimeSinceDisplayContent($dateTime, $durationDisplayFormat=false)
static convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero($localeFormattedDateTime)
static getLocaleDateTimeFormat()
static convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($dateValue)
static getFirstDayOfAWeek($stringTime=null)
static getLastDayOfAWeek($stringTime=null)
static resolveValueForDateLocaleFormattedDisplay($date, $displayFormat=null)
static getMonthStartAndEndDatesBetweenTwoDatesInARange($beginDate, $endDate)
static getDatesBetweenTwoDatesInARange($beginDate, $endDate)
static convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($dateValue)
static getWeekStartAndEndDatesBetweenTwoDatesInARange($beginDate, $endDate)
static convertFromUtcUnixStampByTimeZone($utcTimeStamp, $timeZone)
Generated on Sat Jul 4 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.