/** * Constructor. * * @param Carbon|null $after * @param Carbon|null $before * @param null|string $name * * @throws TimezoneException|DateRangeException */ public function __construct(Carbon $after = null, Carbon $before = null, $name = null) { $this->name = $name; $this->after = $after; $this->before = $before; if (is_null($after) && is_null($before)) { throw new DateRangeException('Either an after date or before date must be provided.'); } elseif (is_null($after) && !is_null($before)) { $this->timezone = $before->getTimezone(); } elseif (is_null($before)) { $this->timezone = $after->getTimezone(); } else { $this->timezone = $this->after->getTimezone(); $before_tz = is_null($this->before->getTimezone()) ? null : $this->before->getTimezone(); if ($before_tz->getName() !== $this->timezone->getName()) { throw new TimezoneException('Multiple timezones are not supported.'); } } }
/** * @param string $name * @param \Carbon\Carbon $date */ protected function setDateProperty(string $name, Carbon $date) { $eventDateTime = new Google_Service_Calendar_EventDateTime(); if (in_array($name, ['start.date', 'end.date'])) { $eventDateTime->setDate($date->format('Y-m-d')); $eventDateTime->setTimezone($date->getTimezone()); } if (in_array($name, ['start.dateTime', 'end.dateTime'])) { $eventDateTime->setDateTime($date->format(DateTime::RFC3339)); $eventDateTime->setTimezone($date->getTimezone()); } if (starts_with($name, 'start')) { $this->googleEvent->setStart($eventDateTime); } if (starts_with($name, 'end')) { $this->googleEvent->setEnd($eventDateTime); } }
<?php require_once 'vendor/autoload.php'; use Carbon\Carbon; use Citco\Carbon as CitcoCarbon; use CarbonExt\FiscalYear\Calculator; // Object Instantiation $brisbane = new Carbon('2015-12-01', 'Australia/Brisbane'); $newYorkCity = new Carbon('2015-12-01', 'America/New_York'); $dtBerlin = new Carbon('2015-12-01', 'Europe/Berlin'); $outputString = "Time difference between %s & %s: %s hours.\n"; // Date difference printf($outputString, "Berlin", "Brisbane, Australia", $dtBerlin->diffInHours($brisbane, false)); printf($outputString, "Berlin", "New York City, America", $dtBerlin->diffInHours($newYorkCity, false)); $septEighteen2014 = Carbon::createFromDate(2014, 9, 18, $dtBerlin->getTimezone()); printf("difference between now and %s in \n\thours: %d, \n\tdays: %d, \n\tweeks: %d, \n\tweekend days: %d, \n\tweek days: %s, \n\thuman readable: %s\n", $septEighteen2014->toFormattedDateString(), $dtBerlin->diffInHours($septEighteen2014), $dtBerlin->diffInDays($septEighteen2014), $dtBerlin->diffInWeeks($septEighteen2014), $dtBerlin->diffInWeekendDays($septEighteen2014), $dtBerlin->diffInWeekDays($septEighteen2014), $dtBerlin->diffForHumans($septEighteen2014)); // Date formatting echo $dtBerlin->toDateString() . "\n"; echo $dtBerlin->toFormattedDateString() . "\n"; echo $dtBerlin->toTimeString() . "\n"; echo $dtBerlin->toDateTimeString() . "\n"; echo $dtBerlin->toDayDateTimeString() . "\n"; echo $dtBerlin->toRfc1036String() . "\n"; echo $dtBerlin->toAtomString() . "\n"; echo $dtBerlin->toCookieString() . "\n"; echo $dtBerlin->toRssString() . "\n"; $dtBerlin->setToStringFormat('l jS \\of F Y'); echo $dtBerlin . "\n"; echo (int) $dtBerlin->isLeapYear() . "\n"; // is* range of functions test printf("Is yesterday? %s\n", $dtBerlin->isYesterday() ? "yes" : "no");
/** * Serialize SharePoint Access Token * * @access public * @return string */ public function serialize() { return serialize([$this->token, $this->expires->getTimestamp(), $this->expires->getTimezone()->getName()]); }
/** * Serialize SharePoint Access Token * * @return string */ public function serialize() { return serialize([$this->value, $this->expiration->getTimestamp(), $this->expiration->getTimezone()->getName()]); }