/
Time.php
1185 lines (1038 loc) · 30.4 KB
/
Time.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\I18n;
use CodeIgniter\I18n\Exceptions\I18nException;
use DateInterval;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Exception;
use IntlCalendar;
use IntlDateFormatter;
use Locale;
use ReturnTypeWillChange;
/**
* A localized date/time package inspired
* by Nesbot/Carbon and CakePHP/Chronos.
*
* Requires the intl PHP extension.
*
* @property string $date
*/
class Time extends DateTime
{
/**
* @var DateTimeZone
*/
protected $timezone;
/**
* @var string
*/
protected $locale;
/**
* Format to use when displaying datetime through __toString
*
* @var string
*/
protected $toStringFormat = 'yyyy-MM-dd HH:mm:ss';
/**
* Used to check time string to determine if it is relative time or not....
*
* @var string
*/
protected static $relativePattern = '/this|next|last|tomorrow|yesterday|midnight|today|[+-]|first|last|ago/i';
/**
* @var DateTimeInterface|static|null
*/
protected static $testNow;
//--------------------------------------------------------------------
// Constructors
//--------------------------------------------------------------------
/**
* Time constructor.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*/
public function __construct(?string $time = null, $timezone = null, ?string $locale = null)
{
$this->locale = $locale ?: Locale::getDefault();
$time ??= '';
// If a test instance has been provided, use it instead.
if ($time === '' && static::$testNow instanceof self) {
$timezone = $timezone ?: static::$testNow->getTimezone();
$time = (string) static::$testNow->toDateTimeString();
}
$timezone = $timezone ?: date_default_timezone_get();
$this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
// If the time string was a relative string (i.e. 'next Tuesday')
// then we need to adjust the time going in so that we have a current
// timezone to work with.
if ($time !== '' && static::hasRelativeKeywords($time)) {
$instance = new DateTime('now', $this->timezone);
$instance->modify($time);
$time = $instance->format('Y-m-d H:i:s');
}
parent::__construct($time, $this->timezone);
}
/**
* Returns a new Time instance with the timezone set.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function now($timezone = null, ?string $locale = null)
{
return new self(null, $timezone, $locale);
}
/**
* Returns a new Time instance while parsing a datetime string.
*
* Example:
* $time = Time::parse('first day of December 2008');
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function parse(string $datetime, $timezone = null, ?string $locale = null)
{
return new self($datetime, $timezone, $locale);
}
/**
* Return a new time with the time set to midnight.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function today($timezone = null, ?string $locale = null)
{
return new self(date('Y-m-d 00:00:00'), $timezone, $locale);
}
/**
* Returns an instance set to midnight yesterday morning.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function yesterday($timezone = null, ?string $locale = null)
{
return new self(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale);
}
/**
* Returns an instance set to midnight tomorrow morning.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function tomorrow($timezone = null, ?string $locale = null)
{
return new self(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale);
}
/**
* Returns a new instance based on the year, month and day. If any of those three
* are left empty, will default to the current value.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function createFromDate(?int $year = null, ?int $month = null, ?int $day = null, $timezone = null, ?string $locale = null)
{
return static::create($year, $month, $day, null, null, null, $timezone, $locale);
}
/**
* Returns a new instance with the date set to today, and the time set to the values passed in.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function createFromTime(?int $hour = null, ?int $minutes = null, ?int $seconds = null, $timezone = null, ?string $locale = null)
{
return static::create(null, null, null, $hour, $minutes, $seconds, $timezone, $locale);
}
/**
* Returns a new instance with the date time values individually set.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function create(?int $year = null, ?int $month = null, ?int $day = null, ?int $hour = null, ?int $minutes = null, ?int $seconds = null, $timezone = null, ?string $locale = null)
{
$year ??= date('Y');
$month ??= date('m');
$day ??= date('d');
$hour = empty($hour) ? 0 : $hour;
$minutes = empty($minutes) ? 0 : $minutes;
$seconds = empty($seconds) ? 0 : $seconds;
return new self(date('Y-m-d H:i:s', strtotime("{$year}-{$month}-{$day} {$hour}:{$minutes}:{$seconds}")), $timezone, $locale);
}
/**
* Provides a replacement for DateTime's own createFromFormat function, that provides
* more flexible timeZone handling
*
* @param string $format
* @param string $datetime
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
#[ReturnTypeWillChange]
public static function createFromFormat($format, $datetime, $timezone = null)
{
if (! $date = parent::createFromFormat($format, $datetime)) {
throw I18nException::forInvalidFormat($format);
}
return new self($date->format('Y-m-d H:i:s'), $timezone);
}
/**
* Returns a new instance with the datetime set based on the provided UNIX timestamp.
*
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*
* @return Time
*/
public static function createFromTimestamp(int $timestamp, $timezone = null, ?string $locale = null)
{
$time = new self(gmdate('Y-m-d H:i:s', $timestamp), 'UTC', $locale);
$timezone ??= 'UTC';
return $time->setTimezone($timezone);
}
/**
* Takes an instance of DateTimeInterface and returns an instance of Time with it's same values.
*
* @throws Exception
*
* @return Time
*/
public static function createFromInstance(DateTimeInterface $dateTime, ?string $locale = null)
{
$date = $dateTime->format('Y-m-d H:i:s');
$timezone = $dateTime->getTimezone();
return new self($date, $timezone, $locale);
}
/**
* Takes an instance of DateTime and returns an instance of Time with it's same values.
*
* @throws Exception
*
* @return Time
*
* @deprecated Use createFromInstance() instead
* @codeCoverageIgnore
*/
public static function instance(DateTime $dateTime, ?string $locale = null)
{
return self::createFromInstance($dateTime, $locale);
}
/**
* Converts the current instance to a mutable DateTime object.
*
* @throws Exception
*
* @return DateTime
*/
public function toDateTime()
{
$dateTime = new DateTime('', $this->getTimezone());
$dateTime->setTimestamp(parent::getTimestamp());
return $dateTime;
}
//--------------------------------------------------------------------
// For Testing
//--------------------------------------------------------------------
/**
* Creates an instance of Time that will be returned during testing
* when calling 'Time::now' instead of the current time.
*
* @param DateTimeInterface|string|Time|null $datetime
* @param DateTimeZone|string|null $timezone
*
* @throws Exception
*/
public static function setTestNow($datetime = null, $timezone = null, ?string $locale = null)
{
// Reset the test instance
if ($datetime === null) {
static::$testNow = null;
return;
}
// Convert to a Time instance
if (is_string($datetime)) {
$datetime = new self($datetime, $timezone, $locale);
} elseif ($datetime instanceof DateTimeInterface && ! $datetime instanceof self) {
$datetime = new self($datetime->format('Y-m-d H:i:s'), $timezone);
}
static::$testNow = $datetime;
}
/**
* Returns whether we have a testNow instance saved.
*/
public static function hasTestNow(): bool
{
return static::$testNow !== null;
}
//--------------------------------------------------------------------
// Getters
//--------------------------------------------------------------------
/**
* Returns the localized Year
*
* @throws Exception
*/
public function getYear(): string
{
return $this->toLocalizedString('y');
}
/**
* Returns the localized Month
*
* @throws Exception
*/
public function getMonth(): string
{
return $this->toLocalizedString('M');
}
/**
* Return the localized day of the month.
*
* @throws Exception
*/
public function getDay(): string
{
return $this->toLocalizedString('d');
}
/**
* Return the localized hour (in 24-hour format).
*
* @throws Exception
*/
public function getHour(): string
{
return $this->toLocalizedString('H');
}
/**
* Return the localized minutes in the hour.
*
* @throws Exception
*/
public function getMinute(): string
{
return $this->toLocalizedString('m');
}
/**
* Return the localized seconds
*
* @throws Exception
*/
public function getSecond(): string
{
return $this->toLocalizedString('s');
}
/**
* Return the index of the day of the week
*
* @throws Exception
*/
public function getDayOfWeek(): string
{
return $this->toLocalizedString('c');
}
/**
* Return the index of the day of the year
*
* @throws Exception
*/
public function getDayOfYear(): string
{
return $this->toLocalizedString('D');
}
/**
* Return the index of the week in the month
*
* @throws Exception
*/
public function getWeekOfMonth(): string
{
return $this->toLocalizedString('W');
}
/**
* Return the index of the week in the year
*
* @throws Exception
*/
public function getWeekOfYear(): string
{
return $this->toLocalizedString('w');
}
/**
* Returns the age in years from the "current" date and 'now'
*
* @throws Exception
*
* @return int
*/
public function getAge()
{
$now = self::now()->getTimestamp();
$time = $this->getTimestamp();
// future dates have no age
return max(0, date('Y', $now) - date('Y', $time));
}
/**
* Returns the number of the current quarter for the year.
*
* @throws Exception
*/
public function getQuarter(): string
{
return $this->toLocalizedString('Q');
}
/**
* Are we in daylight savings time currently?
*/
public function getDst(): bool
{
return $this->format('I') === '1'; // 1 if Daylight Saving Time, 0 otherwise.
}
/**
* Returns boolean whether the passed timezone is the same as
* the local timezone.
*/
public function getLocal(): bool
{
$local = date_default_timezone_get();
return $local === $this->timezone->getName();
}
/**
* Returns boolean whether object is in UTC.
*/
public function getUtc(): bool
{
return $this->getOffset() === 0;
}
/**
* Returns the name of the current timezone.
*/
public function getTimezoneName(): string
{
return $this->timezone->getName();
}
//--------------------------------------------------------------------
// Setters
//--------------------------------------------------------------------
/**
* Sets the current year for this instance.
*
* @param int|string $value
*
* @throws Exception
*
* @return Time
*/
public function setYear($value)
{
return $this->setValue('year', $value);
}
/**
* Sets the month of the year.
*
* @param int|string $value
*
* @throws Exception
*
* @return Time
*/
public function setMonth($value)
{
if (is_numeric($value) && ($value < 1 || $value > 12)) {
throw I18nException::forInvalidMonth($value);
}
if (is_string($value) && ! is_numeric($value)) {
$value = date('m', strtotime("{$value} 1 2017"));
}
return $this->setValue('month', $value);
}
/**
* Sets the day of the month.
*
* @param int|string $value
*
* @throws Exception
*
* @return Time
*/
public function setDay($value)
{
if ($value < 1 || $value > 31) {
throw I18nException::forInvalidDay($value);
}
$date = $this->getYear() . '-' . $this->getMonth();
$lastDay = date('t', strtotime($date));
if ($value > $lastDay) {
throw I18nException::forInvalidOverDay($lastDay, $value);
}
return $this->setValue('day', $value);
}
/**
* Sets the hour of the day (24 hour cycle)
*
* @param int|string $value
*
* @throws Exception
*
* @return Time
*/
public function setHour($value)
{
if ($value < 0 || $value > 23) {
throw I18nException::forInvalidHour($value);
}
return $this->setValue('hour', $value);
}
/**
* Sets the minute of the hour
*
* @param int|string $value
*
* @throws Exception
*
* @return Time
*/
public function setMinute($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidMinutes($value);
}
return $this->setValue('minute', $value);
}
/**
* Sets the second of the minute.
*
* @param int|string $value
*
* @throws Exception
*
* @return Time
*/
public function setSecond($value)
{
if ($value < 0 || $value > 59) {
throw I18nException::forInvalidSeconds($value);
}
return $this->setValue('second', $value);
}
/**
* Helper method to do the heavy lifting of the 'setX' methods.
*
* @param int $value
*
* @throws Exception
*
* @return Time
*/
protected function setValue(string $name, $value)
{
[$year, $month, $day, $hour, $minute, $second] = explode('-', $this->format('Y-n-j-G-i-s'));
${$name} = $value;
return self::create(
(int) $year,
(int) $month,
(int) $day,
(int) $hour,
(int) $minute,
(int) $second,
$this->getTimezoneName(),
$this->locale
);
}
/**
* Returns a new instance with the revised timezone.
*
* @param DateTimeZone|string $timezone
*
* @throws Exception
*
* @return Time
*/
#[ReturnTypeWillChange]
public function setTimezone($timezone)
{
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
return self::createFromInstance($this->toDateTime()->setTimezone($timezone), $this->locale);
}
/**
* Returns a new instance with the date set to the new timestamp.
*
* @param int $timestamp
*
* @throws Exception
*
* @return Time
*/
#[ReturnTypeWillChange]
public function setTimestamp($timestamp)
{
$time = date('Y-m-d H:i:s', $timestamp);
return self::parse($time, $this->timezone, $this->locale);
}
//--------------------------------------------------------------------
// Add/Subtract
//--------------------------------------------------------------------
/**
* Returns a new Time instance with $seconds added to the time.
*
* @return static
*/
public function addSeconds(int $seconds)
{
$time = clone $this;
return $time->add(DateInterval::createFromDateString("{$seconds} seconds"));
}
/**
* Returns a new Time instance with $minutes added to the time.
*
* @return static
*/
public function addMinutes(int $minutes)
{
$time = clone $this;
return $time->add(DateInterval::createFromDateString("{$minutes} minutes"));
}
/**
* Returns a new Time instance with $hours added to the time.
*
* @return static
*/
public function addHours(int $hours)
{
$time = clone $this;
return $time->add(DateInterval::createFromDateString("{$hours} hours"));
}
/**
* Returns a new Time instance with $days added to the time.
*
* @return static
*/
public function addDays(int $days)
{
$time = clone $this;
return $time->add(DateInterval::createFromDateString("{$days} days"));
}
/**
* Returns a new Time instance with $months added to the time.
*
* @return static
*/
public function addMonths(int $months)
{
$time = clone $this;
return $time->add(DateInterval::createFromDateString("{$months} months"));
}
/**
* Returns a new Time instance with $years added to the time.
*
* @return static
*/
public function addYears(int $years)
{
$time = clone $this;
return $time->add(DateInterval::createFromDateString("{$years} years"));
}
/**
* Returns a new Time instance with $seconds subtracted from the time.
*
* @return static
*/
public function subSeconds(int $seconds)
{
$time = clone $this;
return $time->sub(DateInterval::createFromDateString("{$seconds} seconds"));
}
/**
* Returns a new Time instance with $minutes subtracted from the time.
*
* @return static
*/
public function subMinutes(int $minutes)
{
$time = clone $this;
return $time->sub(DateInterval::createFromDateString("{$minutes} minutes"));
}
/**
* Returns a new Time instance with $hours subtracted from the time.
*
* @return static
*/
public function subHours(int $hours)
{
$time = clone $this;
return $time->sub(DateInterval::createFromDateString("{$hours} hours"));
}
/**
* Returns a new Time instance with $days subtracted from the time.
*
* @return static
*/
public function subDays(int $days)
{
$time = clone $this;
return $time->sub(DateInterval::createFromDateString("{$days} days"));
}
/**
* Returns a new Time instance with $months subtracted from the time.
*
* @return static
*/
public function subMonths(int $months)
{
$time = clone $this;
return $time->sub(DateInterval::createFromDateString("{$months} months"));
}
/**
* Returns a new Time instance with $hours subtracted from the time.
*
* @return static
*/
public function subYears(int $years)
{
$time = clone $this;
return $time->sub(DateInterval::createFromDateString("{$years} years"));
}
//--------------------------------------------------------------------
// Formatters
//--------------------------------------------------------------------
/**
* Returns the localized value of the date in the format 'Y-m-d H:i:s'
*
* @throws Exception
*/
public function toDateTimeString()
{
return $this->toLocalizedString('yyyy-MM-dd HH:mm:ss');
}
/**
* Returns a localized version of the date in Y-m-d format.
*
* @throws Exception
*
* @return string
*/
public function toDateString()
{
return $this->toLocalizedString('yyyy-MM-dd');
}
/**
* Returns a localized version of the date in nicer date format:
*
* i.e. Apr 1, 2017
*
* @throws Exception
*
* @return string
*/
public function toFormattedDateString()
{
return $this->toLocalizedString('MMM d, yyyy');
}
/**
* Returns a localized version of the time in nicer date format:
*
* i.e. 13:20:33
*
* @throws Exception
*
* @return string
*/
public function toTimeString()
{
return $this->toLocalizedString('HH:mm:ss');
}
/**
* Returns the localized value of this instance in $format.
*
* @throws Exception
*
* @return bool|string
*/
public function toLocalizedString(?string $format = null)
{
$format ??= $this->toStringFormat;
return IntlDateFormatter::formatObject($this->toDateTime(), $format, $this->locale);
}
//--------------------------------------------------------------------
// Comparison
//--------------------------------------------------------------------
/**
* Determines if the datetime passed in is equal to the current instance.
* Equal in this case means that they represent the same moment in time,
* and are not required to be in the same timezone, as both times are
* converted to UTC and compared that way.
*
* @param DateTimeInterface|string|Time $testTime
*
* @throws Exception
*/
public function equals($testTime, ?string $timezone = null): bool
{
$testTime = $this->getUTCObject($testTime, $timezone);
$ourTime = $this->toDateTime()
->setTimezone(new DateTimeZone('UTC'))
->format('Y-m-d H:i:s');
return $testTime->format('Y-m-d H:i:s') === $ourTime;
}
/**
* Ensures that the times are identical, taking timezone into account.
*
* @param DateTimeInterface|string|Time $testTime
*
* @throws Exception
*/
public function sameAs($testTime, ?string $timezone = null): bool
{
if ($testTime instanceof DateTimeInterface) {
$testTime = $testTime->format('Y-m-d H:i:s');
} elseif (is_string($testTime)) {
$timezone = $timezone ?: $this->timezone;
$timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
$testTime = new DateTime($testTime, $timezone);
$testTime = $testTime->format('Y-m-d H:i:s');
}
$ourTime = $this->toDateTimeString();
return $testTime === $ourTime;
}
/**
* Determines if the current instance's time is before $testTime,
* after converting to UTC.
*
* @param mixed $testTime
*
* @throws Exception
*/
public function isBefore($testTime, ?string $timezone = null): bool
{
$testTime = $this->getUTCObject($testTime, $timezone)->getTimestamp();
$ourTime = $this->getTimestamp();
return $ourTime < $testTime;
}
/**
* Determines if the current instance's time is after $testTime,
* after converting in UTC.
*
* @param mixed $testTime
*
* @throws Exception
*/
public function isAfter($testTime, ?string $timezone = null): bool
{
$testTime = $this->getUTCObject($testTime, $timezone)->getTimestamp();
$ourTime = $this->getTimestamp();
return $ourTime > $testTime;
}
//--------------------------------------------------------------------
// Differences
//--------------------------------------------------------------------
/**
* Returns a text string that is easily readable that describes
* how long ago, or how long from now, a date is, like:
*
* - 3 weeks ago
* - in 4 days
* - 6 hours ago