PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / vendor / zbateson / mail-mime-parser / src / Header / DateHeader.php

DateHeader.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at vendor/zbateson/mail-mime-parser/src/Header/DateHeader.php

60 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file is part of the ZBateson\MailMimeParser project.
4 *
5 * @license http://opensource.org/licenses/bsd-license.php BSD
6 */
7
8 namespace ZBateson\MailMimeParser\Header;
9
10 use DateTimeImmutable;
11 use ZBateson\MailMimeParser\Header\Consumer\ConsumerService;
12 use ZBateson\MailMimeParser\Header\Part\DatePart;
13
14 /**
15 * Reads a DatePart value header in either RFC 2822 or RFC 822 format.
16 *
17 * @author Zaahid Bateson
18 */
19 class DateHeader extends AbstractHeader
20 {
21 /**
22 * Returns a DateConsumer.
23 *
24 * @return Consumer\AbstractConsumer
25 */
26 protected function getConsumer(ConsumerService $consumerService)
27 {
28 return $consumerService->getDateConsumer();
29 }
30
31 /**
32 * Convenience method returning the part's DateTime object, or null if the
33 * date could not be parsed.
34 *
35 * @return \DateTime|null The parsed DateTime object.
36 */
37 public function getDateTime() : ?\DateTime
38 {
39 if (!empty($this->parts) && $this->parts[0] instanceof DatePart) {
40 return $this->parts[0]->getDateTime();
41 }
42 return null;
43 }
44
45 /**
46 * Returns a DateTimeImmutable for the part's DateTime object, or null if
47 * the date could not be parsed.
48 *
49 * @return DateTimeImmutable|null The parsed DateTimeImmutable object.
50 */
51 public function getDateTimeImmutable() : ?\DateTimeImmutable
52 {
53 $dateTime = $this->getDateTime();
54 if ($dateTime !== null) {
55 return DateTimeImmutable::createFromMutable($dateTime);
56 }
57 return null;
58 }
59 }
60