本文整理汇总了PHP中DateTimeImmutable::format方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeImmutable::format方法的具体用法?PHP DateTimeImmutable::format怎么用?PHP DateTimeImmutable::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeImmutable
的用法示例。
在下文中一共展示了DateTimeImmutable::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Starting...');
$output->writeln('Getting disrupted lines...');
$lines = $this->getContainer()->get('console.services.line')->findAllDisrupted();
$count = $lines->getResultCount();
$output->writeln($count . ' disrupted lines');
$now = new \DateTimeImmutable();
if ($count > 0) {
$lines = $lines->getDomainModels();
$day = (int) $now->format('N');
$hour = (int) $now->format('H');
foreach ($lines as $line) {
$output->writeln('Getting relevant subscriptions for ' . $line->getName() . ' on day ' . $day . ', hour ' . $hour . '...');
$subscriptions = $this->getContainer()->get('console.services.subscription')->findAllForLineAndHour($line, $day, $hour);
$scount = $subscriptions->getResultCount();
$output->writeln($scount . ' subscriptions found');
if ($scount > 0) {
$title = $line->getStatusSummary();
$this->notify($line, $title, $subscriptions->getDomainModels());
$output->writeln('Notified ' . $line->getName() . ': ' . $title);
// if we sent out some notifications, sleep for 2 seconds before sending more
sleep(2);
}
}
}
$output->writeln('Done');
}
示例2: testResponseToPropertiesTimestampValue
public function testResponseToPropertiesTimestampValue()
{
$date = new \DateTimeImmutable();
$data = ['foo' => ['timestampValue' => $date->format(self::DATE_FORMAT)]];
$res = $this->mapper->responseToEntityProperties($data)['properties'];
$this->assertInstanceOf(\DateTimeImmutable::class, $res['foo']);
$this->assertEquals($date->format('c'), $res['foo']->format('c'));
}
示例3: toString
public function toString() : string
{
if ($this->expiry instanceof \DateTimeImmutable) {
$rawToken = $this->token . self::DELIMITER . $this->expiry->format(self::DATE_FORMAT);
} else {
$rawToken = $this->token;
}
return base64_encode($rawToken);
}
示例4:
/**
* @test
*/
function it_creates_a_new_message_from_array_and_fqcn()
{
$uuid = Uuid::uuid4();
$createdAt = new \DateTimeImmutable();
$command = $this->messageFactory->createMessageFromArray(DoSomething::class, ['uuid' => $uuid->toString(), 'version' => 1, 'payload' => ['command' => 'payload'], 'metadata' => ['command' => 'metadata'], 'created_at' => $createdAt->format(\DateTime::ISO8601)]);
$this->assertEquals(DoSomething::class, $command->messageName());
$this->assertEquals($uuid->toString(), $command->uuid()->toString());
$this->assertEquals($createdAt->format(\DateTime::ISO8601), $command->createdAt()->format(\DateTime::ISO8601));
$this->assertEquals(1, $command->version());
$this->assertEquals(['command' => 'payload'], $command->payload());
$this->assertEquals(['command' => 'metadata'], $command->metadata());
}
示例5: calculateCalendarMonths
private function calculateCalendarMonths()
{
$months = ((int) $this->date->format('Y') - (int) $this->baseDate->format('Y')) * 12;
$months += (int) $this->date->format('m') - (int) $this->baseDate->format('m');
if ($this->date > $this->baseDate) {
return $months + ($this->date->format('d') < $this->baseDate->format('d') ? -1 : 0);
} else {
if ($this->date < $this->baseDate) {
return $months + ($this->date->format('d') > $this->baseDate->format('d') ? 1 : 0);
}
}
return $months;
}
示例6: hourAction
public function hourAction()
{
//Define your file path based on the cache one
$filename = $this->container->getParameter('kernel.cache_dir') . '/timestamps/hour.txt';
$data = @file_get_contents($filename);
$now = new \DateTimeImmutable();
$min = (int) $now->format('i');
$timestamp = $now->getTimestamp();
$last = (int) $data ?? 0;
$diff = $timestamp - $last;
// can only run in the first 5 mins of an hour,
// and cannot run again within 10 mins
$withinMin = $min <= 5;
if ($withinMin && $diff > 10 * 60) {
$command = new StatusHourlyCommand();
$command->setContainer($this->container);
$input = new ArrayInput([]);
$output = new NullOutput();
$resultCode = $command->run($input, $output);
//Create your own folder in the cache directory
$fs = new Filesystem();
$fs->mkdir(dirname($filename));
file_put_contents($filename, $timestamp);
} else {
$resultCode = 1;
}
return new JsonResponse((object) ['status' => $resultCode, 'diff' => $diff, 'inWindow' => $withinMin]);
}
示例7: testTransformDateTimeImmutable
public function testTransformDateTimeImmutable()
{
$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
$output = $input->format('U');
$input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
$this->assertEquals($output, $transformer->transform($input));
}
示例8: addCookie
/**
* @param Response $response
* @param string $cookieName
* @param string $cookieValue
* @return Response
*/
public static function addCookie(Response $response, $cookieName, $cookieValue)
{
$expirationMinutes = 10;
$expiry = new \DateTimeImmutable('now + ' . $expirationMinutes . 'minutes');
$cookie = urlencode($cookieName) . '=' . urlencode($cookieValue) . '; expires=' . $expiry->format(\DateTime::COOKIE) . '; Max-Age=' . $expirationMinutes * 60 . '; path=/; secure; httponly';
$response = $response->withAddedHeader('Set-Cookie', $cookie);
return $response;
}
示例9: getFieldBody
/**
* Get the string value of the body in this Header.
*
* This is not necessarily RFC 2822 compliant since folding white space will
* not be added at this stage (see {@link toString()} for that).
*
* @see toString()
*
* @return string
*/
public function getFieldBody()
{
if (!$this->getCachedValue()) {
if (isset($this->dateTime)) {
$this->setCachedValue($this->dateTime->format(DateTime::RFC2822));
}
}
return $this->getCachedValue();
}
示例10: postUp
public function postUp(Schema $schema)
{
$lineData = [['bakerloo-line', 'bakerloo', 'Bakerloo', 'Bakerloo Line'], ['central-line', 'central', 'Central', 'Central Line'], ['circle-line', 'circle', 'Circle', 'Circle Line'], ['district-line', 'district', 'District', 'District Line'], ['hammersmith-city-line', 'hammersmith-city', 'Hammersmith & City', 'Hammersmith & City Line'], ['jubilee-line', 'jubilee', 'Jubilee', 'Jubilee Line'], ['metropolitan-line', 'metropolitan', 'Metropolitan', 'Metropolitan Line'], ['northern-line', 'northern', 'Northern', 'Northern Line'], ['piccadilly-line', 'piccadilly', 'Piccadilly', 'Piccadilly Line'], ['victoria-line', 'victoria', 'Victoria', 'Victoria Line'], ['waterloo-city-line', 'waterloo-city', 'Waterloo & City', 'Waterloo & City Line'], ['dlr', 'dlr', 'DLR', 'DLR'], ['london-overground', 'london-overground', 'London Overground', 'London Overground'], ['tfl-rail', 'tfl-rail', 'TFL Rail', 'TFL Rail']];
$now = new \DateTimeImmutable();
$iso = $now->format('c');
foreach ($lineData as $i => $line) {
$this->addSql('INSERT INTO `tube_lines` (url_key, tfl_key, short_name, name, display_order, created_at, updated_at) VALUES (?,?,?,?,?,?,?)', [$line[0], $line[1], $line[2], $line[3], $i + 1, $iso, $iso]);
}
}
示例11: generate
/**
* @param int $fromTs
* @param int $toTs
*
* @return \Generator
*/
public static function generate($fromTs, $toTs)
{
$firstDay = new \DateTimeImmutable(date('Y-m-d', $fromTs));
$lastDay = new \DateTimeImmutable(date('Y-m-d', $toTs));
$cursor = new \DateTime($lastDay->format('Y-m-d'));
while ($cursor >= $firstDay) {
(yield $cursor->format('Y-m-d'));
$cursor->sub(new \DateInterval('P1D'));
}
}
示例12: testDisplayValueForDateTimeImmutable
public function testDisplayValueForDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('\\DateTimeImmutable was introduced in PHP 5.5');
}
$now = new \DateTimeImmutable();
$column = new DateTimeColumn();
$column->setFormat('Y-m-d H:i:s');
$this->assertEquals($now->format('Y-m-d H:i:s'), $column->getDisplayedValue($now));
}
示例13: build
/**
* Builds the cookie into a HTTP response header.
*
* @return string
*/
public function build() : string
{
$str = urlencode($this->name()) . '=' . urlencode($this->value());
if ($this->expiration) {
$str .= '; expires=' . $this->expiration->format(\DateTime::COOKIE);
}
if (isset($this->attributes[CookieInterface::ATTR_PATH])) {
$str .= '; path=' . $this->attributes[CookieInterface::ATTR_PATH];
}
if (isset($this->attributes[CookieInterface::ATTR_DOMAIN])) {
$str .= '; domain=' . $this->attributes[CookieInterface::ATTR_DOMAIN];
}
if (isset($this->attributes[CookieInterface::ATTR_SECURE]) && $this->attributes[CookieInterface::ATTR_SECURE] === true) {
$str .= '; secure';
}
if (isset($this->attributes[CookieInterface::ATTR_HTTP]) && $this->attributes[CookieInterface::ATTR_HTTP] === true) {
$str .= '; httponly';
}
return $str;
}
示例14: testTransformDateTimeImmutable
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}
$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
$output = $input->format('U');
$input = $input->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
$this->assertEquals($output, $transformer->transform($input));
}
示例15: getListingsOf
/**
* @param Channel $channel
* @param \DateTimeImmutable $specifiedDate
* @return array
*/
public function getListingsOf(Channel $channel, \DateTimeImmutable $specifiedDate)
{
$criteria = array('channel' => array('builder' => function ($alias) {
return sprintf("%s.channel", $alias);
}, 'value' => $channel), 'programDate' => array('builder' => function ($alias) {
return sprintf("DATE(%s.programDate)", $alias);
}, 'value' => $specifiedDate->format('Y-m-d')), 'orderBy' => array('builder' => function ($alias) {
return sprintf("%s.programDate", $alias);
}, 'value' => 'ASC'));
return $this->entityManager->findBy(Listing::class, $criteria);
}