ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 25 of file DateFormatTest.php.

Member Function Documentation

◆ setUp()

DateFormatTest::setUp ( )

Definition at line 29 of file DateFormatTest.php.

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

References Vendor\Package\$f.

◆ testDateFormatApplyTo()

DateFormatTest::testDateFormatApplyTo ( )

Definition at line 79 of file DateFormatTest.php.

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

◆ testDateFormatApplyToWithTime()

DateFormatTest::testDateFormatApplyToWithTime ( )

Definition at line 87 of file DateFormatTest.php.

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

◆ testDateFormatBuilderAndGetters()

DateFormatTest::testDateFormatBuilderAndGetters ( )

Definition at line 44 of file DateFormatTest.php.

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

◆ testDateFormatExpand()

DateFormatTest::testDateFormatExpand ( )

Definition at line 103 of file DateFormatTest.php.

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

◆ testDateFormatFactory()

DateFormatTest::testDateFormatFactory ( )

Definition at line 35 of file DateFormatTest.php.

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

◆ testDateFormatInvalidTokens()

DateFormatTest::testDateFormatInvalidTokens ( )

Definition at line 73 of file DateFormatTest.php.

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

Field Documentation

◆ $df

DateFormat Factory DateFormatTest::$df
protected

Definition at line 27 of file DateFormatTest.php.


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