Guest User

Untitled

a guest
Jan 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2. // $clock implements Clock
  3. // interface Clock
  4. // {
  5. // public function now() : DateTimeImmutable;
  6. // }
  7.  
  8. // setup
  9. $startDate = Date::fromString('2019-01-04');
  10.  
  11. // variant 1A) Tell, Don't Ask
  12. $isNotPast = $startDate->isNotInThePast($clock);
  13.  
  14. // variant 1B)
  15. $isNotPast = (new IsNotInThePastValidator($clock))
  16. ->isNotInThePast($startDate);
  17.  
  18.  
  19. // ==== Add Offset Support, Check if given Date is today in another Timezone
  20. // Example: It's 2019-01-04 08:00 in UTC
  21. // User Submitted 2019-01-03 as Checkindate
  22. // Check if 2019-01-03 is still today for an earlier timezone.
  23.  
  24. // setup
  25. $startDate = Date::fromString('2019-01-04');
  26. $offset = '-0800';
  27.  
  28. // variant 2A) Tell, Don't Ask
  29. $isNotPast = $startDate->isNotInThePast($clock, $offset);
  30.  
  31. // via @matthiasnoback
  32. $isNotPast = $startDate->isNotInThePast($clock->now(), $offset);
  33.  
  34. // variant 2B)
  35. $isNotPast = (new IsNotInThePastValidator($clock, $offset))
  36. ->isNotInThePast($startDate);
  37.  
  38. // variant 2C)
  39. $isNotPast = (new IsNotInThePastValidator($clock))
  40. ->isNotInThePast($startDate, $offset);
Add Comment
Please, Sign In to add comment