Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $clock implements Clock
- // interface Clock
- // {
- // public function now() : DateTimeImmutable;
- // }
- // setup
- $startDate = Date::fromString('2019-01-04');
- // variant 1A) Tell, Don't Ask
- $isNotPast = $startDate->isNotInThePast($clock);
- // variant 1B)
- $isNotPast = (new IsNotInThePastValidator($clock))
- ->isNotInThePast($startDate);
- // ==== Add Offset Support, Check if given Date is today in another Timezone
- // Example: It's 2019-01-04 08:00 in UTC
- // User Submitted 2019-01-03 as Checkindate
- // Check if 2019-01-03 is still today for an earlier timezone.
- // setup
- $startDate = Date::fromString('2019-01-04');
- $offset = '-0800';
- // variant 2A) Tell, Don't Ask
- $isNotPast = $startDate->isNotInThePast($clock, $offset);
- // via @matthiasnoback
- $isNotPast = $startDate->isNotInThePast($clock->now(), $offset);
- // variant 2B)
- $isNotPast = (new IsNotInThePastValidator($clock, $offset))
- ->isNotInThePast($startDate);
- // variant 2C)
- $isNotPast = (new IsNotInThePastValidator($clock))
- ->isNotInThePast($startDate, $offset);
Add Comment
Please, Sign In to add comment