public function __construct(\DateTimeInterface $date, \DateTimeInterface $baseDate) { $this->date = $date instanceof \DateTime ? \DateTimeImmutable::createFromMutable($date) : $date; $this->baseDate = $baseDate instanceof \DateTime ? \DateTimeImmutable::createFromMutable($baseDate) : $baseDate; $this->interval = $date->diff($baseDate); $this->diffInSeconds = $date->format('U') - $baseDate->format('U'); $this->calendarMonths = $this->calculateCalendarMonths(); }
/** * Get the aggregate root if it exists otherwise null * * @param AggregateType $aggregateType * @param string $aggregateId * @return Snapshot */ public function get(AggregateType $aggregateType, $aggregateId) { $gridFs = $this->getGridFs($aggregateType); $gridFsfile = $gridFs->findOne(['$query' => ['aggregate_type' => $aggregateType->toString(), 'aggregate_id' => $aggregateId], '$orderBy' => ['last_version' => -1]]); if (!$gridFsfile) { return; } return new Snapshot($aggregateType, $aggregateId, unserialize($gridFsfile->getBytes()), $gridFsfile->file['last_version'], \DateTimeImmutable::createFromMutable($gridFsfile->file['created_at']->toDateTime())); }
/** * Run the database seeds. * * @return void */ public function run() { $repo = App::make(Repository::class); $faker = App::make(Faker\Generator::class); $genders = ['male', 'female']; for ($i = 0; $i < 10; $i++) { $id = RegistrationRequestId::generate(); $gender = $faker->randomElement($genders); $request = RegistrationRequest::submit($id, new FullName($faker->firstName($gender), '', $faker->lastName), Gender::fromString($gender), DateTimeImmutable::createFromMutable($faker->dateTimeInInterval('- 30 years', '-16 years')), ContactInfo::describe(new Email($faker->safeEmail), new Address($faker->city, $faker->postCode, $faker->streetAddress)), new StudyDetails('Msc Applied Mathematics', new DateTimeImmutable('2011-09-01'), 's2218356'), new PaymentInfo(true, $faker->boolean)); $repo->save($request); } }
/** * @param string|int|\DateTimeInterface $dateTime */ public function __construct($dateTime) { if ($dateTime instanceof \DateTimeInterface) { if ($dateTime instanceof \DateTime) { $dateTime = \DateTimeImmutable::createFromMutable($dateTime); } parent::__construct($dateTime); } elseif (is_numeric($dateTime)) { parent::__construct(new \DateTimeImmutable(date('Y-m-d H:i:s', $dateTime), new \DateTimeZone(date_default_timezone_get()))); } else { throw new Kdyby\Clock\NotImplementedException(sprintf('Cannot process datetime in given format %s', $dateTime)); } }
public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null || $value instanceof \DateTimeImmutable) { return $value; } elseif ($value instanceof \DateTime) { return \DateTimeImmutable::createFromMutable($value); } $val = \DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value, self::getUtc()); if (!$val) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); } return $val; }
/** * Generate schedule for selected objects * * @param \DateTime|null $scheduledStartTime * @return Generator */ public function generate(\DateTime $startTime = null) { if (!$startTime) { $startTime = new \DateTimeImmutable(); $startTime = $startTime->setTime($startTime->format("H"), ceil($startTime->format("i") / 5) * 5); } if (!$startTime instanceof \DateTimeImmutable) { $startTime = \DateTimeImmutable::createFromMutable($startTime); } foreach ($this->objects as $object) { $duration = \DateInterval::createFromDateString(ceil($object->getScheduledDuration() / 5) * 5 . " minutes"); $endTime = $startTime->add($duration); $object->setSheduledStartTime($startTime->format(\DateTime::RFC3339)); $object->setSheduledEndTime($endTime->format(\DateTime::RFC3339)); $object->scheduledStartTime = $startTime->format(\DateTime::RFC3339); $object->scheduledEndTime = $endTime->format(\DateTime::RFC3339); // var_dump([$startTime->format('m-d H:i'), (ceil($object->getScheduledDuration() / 5) * 5)." minutes", $endTime->format('m-d H:i')]); $startTime = $endTime; } }
<?php $current = "2014-03-02 16:24:08"; $i = DateTimeImmutable::createFromMutable(date_create($current)); var_dump($i); $i = DateTimeImmutable::createFromMutable(date_create_immutable($current)); var_dump($i);
function from($mutable_datetime) { $datetime = DateTimeImmutable::createFromMutable($mutable_datetime); $gigasecond = new DateInterval('PT1000000000S'); return $datetime->add($gigasecond); }
public function testCreateFromMutable() { $time = '2000-01-02T03:14:25'; $mutable = new DateTime($time); $immutable = DateTimeImmutable::createFromMutable($mutable); $this->assertTrue($immutable instanceof DateTimeImmutable); }
/** * @return \DateTimeImmutable */ private function getNextTimeOfDispatch() { return \DateTimeImmutable::createFromMutable($this->lastSending)->modify(self::NEXT_DISPATCH); }
<?php $date = new DateTime("2014-06-20 11:45 Europe/London"); $immutable = DateTimeImmutable::createFromMutable($date);
/** * Creates a new Card. * * The values can be any of the following: * ``` * name / p-name - The full/formatted name of the person or organisation * Can either be a string or a Name object. * email / u-email - email address * logo / u-logo - a logo representing the person or organisation * photo / u-photo * url / u-url - home page * uid / u-uid - universally unique identifier, typically canonical URL * category / p-category - category/tag * address / p-adr - An Address object * tel / p-tel - telephone number * note / p-note - additional notes * birthday / dt-bday - birth date * key / u-key - cryptographic public key e.g. SSH or GPG * org / p-org - affiliated organization, either a string or Card * String values overwrite the p-organization-name field * orgName / p-organization-name * title / p-job-title - job title * role / p-role - description of role * impp / u-impp per RFC4770 * sex / p-sex - biological sex * gender / p-gender-identity - gender identity * anniversary / dt-anniversary - date of anniversary * ``` * * @param array $values The values */ public function __construct(array $values) { if (array_key_exists('p-name', $values)) { if ($values['p-name'] instanceof Name) { $this->name = $values['p-name']; } else { $this->fullName = trim($values['p-name']); } } elseif (array_key_exists('name', $values)) { if ($values['name'] instanceof Name) { $this->name = $values['name']; } else { $this->fullName = trim($values['name']); } } foreach (self::$strings as $mf => $p) { if (array_key_exists($mf, $values)) { $this->{$p} = trim($values[$mf]); } elseif (array_key_exists($p, $values)) { $this->{$p} = trim($values[$p]); } } foreach (self::$dates as $mf => $p) { if (array_key_exists($mf, $values)) { $val = $values[$mf]; if ($val instanceof \DateTimeInterface) { $this->{$p} = $val instanceof \DateTime ? \DateTimeImmutable::createFromMutable($val) : $val; } } elseif (array_key_exists($p, $values)) { $val = $values[$p]; if ($val instanceof \DateTimeInterface) { $this->{$p} = $val instanceof \DateTime ? \DateTimeImmutable::createFromMutable($val) : $val; } } } if (array_key_exists('p-adr', $values)) { if ($values['p-adr'] instanceof Address) { $this->address = $values['p-adr']; } } elseif (array_key_exists('address', $values)) { if ($values['address'] instanceof Address) { $this->address = $values['address']; } } if (array_key_exists('p-org', $values)) { if ($values['p-org'] instanceof Card) { $this->org = $values['p-org']; } else { $this->orgName = trim($values['p-org']); } } elseif (array_key_exists('org', $values)) { if ($values['org'] instanceof Card) { $this->org = $values['org']; } else { $this->orgName = trim($values['org']); } } }
private function buildRefreshToken(AccessToken $accessToken) { $refreshToken = null; if ($this->configuration->alwaysGenerateARefreshToken()) { $token = $this->configuration->getTokenGenerator()->generate(['length' => $this->configuration->getAccessTokenLength()]); $expiresAt = new \DateTime('now', new \DateTimeZone('UTC')); $expiresAt->add(\DateInterval::createFromDateString(sprintf("%d seconds", $this->configuration->getRefreshTokenTTL()))); $refreshToken = new RefreshToken($token, $accessToken, \DateTimeImmutable::createFromMutable($expiresAt)); $this->refreshTokenStorage->save($refreshToken); } return $refreshToken; }