Skip to content

Latest commit

 

History

History
102 lines (78 loc) · 4.42 KB

timewrapper.adoc

File metadata and controls

102 lines (78 loc) · 4.42 KB

TimeWrapper

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.

1. Interface Methods

tag::interfaceMethods[]

There are three interface methods shared by Datetime` classes:

interface methods
  • public function getSeconds(): int

  • public function format(string $format = 'Y-m-d H:i:s'): string

  • public function absoluteCopy(): Timestamp

end::interfaceMethods[]

.1. getSeconds: int

At the core it’s all numbers and for these numbers it’s the seconds returned by this method.

method: getSeconds
public function getSeconds(): int;

.2. format: string

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.

method: format
public function format(string $format = ''): string;

.3. absoluteCopy: TimeWrapper

Get a copy of the object with an absolute value.

method: absoluteCopy
public function absoluteCopy(): TimeWrapper;

4. Format

A subset of format options commonly used by Datetime classes.

Table 1. Format Subset
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