本文整理汇总了PHP中DateTimeImmutable::createFromMutable方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::createFromMutable方法的具体用法?PHP DateTimeImmutable::createFromMutable怎么用?PHP DateTimeImmutable::createFromMutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeImmutable
的用法示例。
在下文中一共展示了DateTimeImmutable::createFromMutable方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
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();
}
示例2: get
/**
* 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()));
}
示例3: run
/**
* 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);
}
}
示例4: __construct
/**
* @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));
}
}
示例5: convertToPHPValue
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;
}
示例6: generate
/**
* 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;
}
}
示例7: var_dump
<?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);
示例8: from
function from($mutable_datetime)
{
$datetime = DateTimeImmutable::createFromMutable($mutable_datetime);
$gigasecond = new DateInterval('PT1000000000S');
return $datetime->add($gigasecond);
}
示例9: testCreateFromMutable
public function testCreateFromMutable()
{
$time = '2000-01-02T03:14:25';
$mutable = new DateTime($time);
$immutable = DateTimeImmutable::createFromMutable($mutable);
$this->assertTrue($immutable instanceof DateTimeImmutable);
}
示例10: getNextTimeOfDispatch
/**
* @return \DateTimeImmutable
*/
private function getNextTimeOfDispatch()
{
return \DateTimeImmutable::createFromMutable($this->lastSending)->modify(self::NEXT_DISPATCH);
}
示例11: DateTime
<?php
$date = new DateTime("2014-06-20 11:45 Europe/London");
$immutable = DateTimeImmutable::createFromMutable($date);
示例12: __construct
/**
* 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']);
}
}
}
示例13: buildRefreshToken
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;
}