ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
DateFormatTest Class Reference
+ Inheritance diagram for DateFormatTest:
+ Collaboration diagram for DateFormatTest:

Public Member Functions

 setUp ()
 
 testDateFormatFactory ()
 
 testDateFormatBuilderAndGetters ()
 
 testDateFormatInvalidTokens ()
 
 testDateFormatApplyTo ()
 
 testDateFormatApplyToWithTime ()
 
 testDateFormatExpand ()
 

Protected Attributes

DateFormat Factory $df
 

Detailed Description

Definition at line 26 of file DateFormatTest.php.

Member Function Documentation

◆ setUp()

DateFormatTest::setUp ( )

Definition at line 30 of file DateFormatTest.php.

30 : void
31 {
32 $f = new ILIAS\Data\Factory();
33 $this->df = $f->dateFormat();
34 }
Builds data types.
Definition: Factory.php:36

References Vendor\Package\$f.

◆ testDateFormatApplyTo()

DateFormatTest::testDateFormatApplyTo ( )

Definition at line 80 of file DateFormatTest.php.

80 : void
81 {
82 $dt = new DateTimeImmutable("1985-04-05");
83 $format = $this->df->germanShort();
84 $this->assertEquals("05.04.1985", $format->applyTo($dt));
85 $this->assertEquals("05.04.1985", $dt->format((string) $format));
86 }

◆ testDateFormatApplyToWithTime()

DateFormatTest::testDateFormatApplyToWithTime ( )

Definition at line 88 of file DateFormatTest.php.

88 : void
89 {
90 $dt = new DateTimeImmutable("1985-04-05 21:12:30");
91 $format = $this->df->custom()
92 ->day()->dot()->month()->dot()->year()
93 ->space()->hours12()->colon()->minutes()->space()->meridiem()
94 ->get();
95 $this->assertEquals("05.04.1985 09:12 pm", $format->applyTo($dt));
96 $this->assertEquals("05.04.1985 09:12 pm", $dt->format((string) $format));
97 $format = $this->df->custom()
98 ->day()->dot()->month()->dot()->year()
99 ->space()->hours24()->colon()->minutes()->colon()->seconds()
100 ->get();
101 $this->assertEquals("05.04.1985 21:12:30", $format->applyTo($dt));
102 }

◆ testDateFormatBuilderAndGetters()

DateFormatTest::testDateFormatBuilderAndGetters ( )

Definition at line 45 of file DateFormatTest.php.

45 : void
46 {
47 $expect = [
48 '.', ',', '-', '/', ' ', ':', 'd', 'jS', 'l', 'D', 'W', 'm', 'F', 'M', 'Y', 'y', 'h','H', 'i', 's', 'a'
49 ];
50 $format = $this->df->custom()
51 ->dot()->comma()->dash()->slash()->space()->colon()
52 ->day()->dayOrdinal()->weekday()->weekdayShort()
53 ->week()->month()->monthSpelled()->monthSpelledShort()
54 ->year()->twoDigitYear()
55 ->hours12()->hours24()->minutes()->seconds()->meridiem()
56 ->get();
57
58 $this->assertEquals(
59 $expect,
60 $format->toArray()
61 );
62
63 $this->assertEquals(
64 implode('', $expect),
65 $format->toString()
66 );
67
68 $this->assertEquals(
69 $format->toString(),
70 (string) $format
71 );
72 }

◆ testDateFormatExpand()

DateFormatTest::testDateFormatExpand ( )

Definition at line 104 of file DateFormatTest.php.

104 : void
105 {
106 $format = $this->df->germanShort();
107 $appended = $this->df->amend($format)->dot()->dot()->get();
108 $this->assertInstanceOf(DateFormat\DateFormat::class, $appended);
109 $this->assertEquals(
110 array_merge($format->toArray(), ['.', '.']),
111 $appended->toArray()
112 );
113 }
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:28

◆ testDateFormatFactory()

DateFormatTest::testDateFormatFactory ( )

Definition at line 36 of file DateFormatTest.php.

36 : void
37 {
38 $this->assertInstanceOf(DateFormat\DateFormat::class, $this->df->standard());
39 $this->assertInstanceOf(DateFormat\DateFormat::class, $this->df->germanShort());
40 $this->assertInstanceOf(DateFormat\DateFormat::class, $this->df->germanLong());
41 $this->assertInstanceOf(DateFormat\DateFormat::class, $this->df->americanShort());
42 $this->assertInstanceOf(DateFormat\FormatBuilder::class, $this->df->custom());
43 }

◆ testDateFormatInvalidTokens()

DateFormatTest::testDateFormatInvalidTokens ( )

Definition at line 74 of file DateFormatTest.php.

74 : void
75 {
76 $this->expectException(InvalidArgumentException::class);
77 new DateFormat\DateFormat(['x', '2']);
78 }

Field Documentation

◆ $df

DateFormat Factory DateFormatTest::$df
protected

Definition at line 28 of file DateFormatTest.php.


The documentation for this class was generated from the following file: