The TimeWrapper
interface implemented by Timespan
and Timestamp
(possibly more to come), started more as a convenience than actually any real requirement. Soon after implementing this interface the usage of the Datetime
classes increased, thanks to the greater interoperability they had acquired. This in turn resulted in them quickly evolving from the skinny classes they were to what they are now, skinny but with some meat on them. Enough rambling and there’s nothing left to say about it anyway.
There are three interface methods shared by Datetime`
classes:
-
public function getSeconds(): int
-
public function format(string $format = 'Y-m-d H:i:s'): string
-
public function absoluteCopy(): Timestamp
At the core it’s all numbers and for these numbers it’s the seconds returned by this method.
public function getSeconds(): int;
Used to get the object as a string using a custom format pattern. The actual implementations may use different format options best suited to the type of data they contain. Where possible patterns mimic existing php patterns.
-
Timestamp
:\DateTimeInterface::format()
-
Timespan
:\DateTimeInterface::format()
The method uses the same formatting pattern as date
and DateTime
, as well as numerous other php functions, to return a string representation of the object.
public function format(string $format = ''): string;
Get a copy of the object with an absolute value.
public function absoluteCopy(): TimeWrapper;
A subset of format options commonly used by Datetime
classes.
format character | Description | Example returned values |
---|---|---|
Day |
--- |
--- |
d |
Day of the month, 2 digits with leading zeros |
01 to 31 |
D |
A textual representation of a day, three letters |
Mon through Sun |
j |
Day of the month without leading zeros |
1 to 31 |
l (lowercase 'L') |
A full textual representation of the day of the week |
Sunday through Saturday |
Month |
--- |
--- |
F |
A full textual representation of a month |
January through December |
m |
Numeric representation of a month, with leading zeros |
01 through 12 |
M |
A three letter textual representation of a month |
Jan through Dec |
n |
Numeric representation of a month, no leading zeros |
1 through 12 |
Year |
--- |
--- |
Y |
Full numeric year, at least 4 digits, - for years BCE |
Examples: -0055, 0787, 1999, 2003, 10191 |
Time |
--- |
--- |
a |
Lowercase Ante meridiem and Post meridiem |
am or pm |
A |
Uppercase Ante meridiem and Post meridiem |
AM or PM |
g |
12-hour format of an hour without leading zeros |
1 through 12 |
G |
24-hour format of an hour without leading zeros |
0 through 23 |
h |
12-hour format of an hour with leading zeros |
01 through 12 |
H |
24-hour format of an hour with leading zeros |
00 through 23 |
i |
Minutes with leading zeros |
00 to 59 |
s |
Seconds with leading zeros |
00 through 59 |
Full date/time |
--- |
--- |
c |
ISO 8601 date |
2004-02-12T15:19:21+00:00 |
r |
» RFC 2822/» RFC 5322 formatted date |
Example: Thu, 21 Dec 2000 16:01:07 +0200 |