1717
1818final class Convert
1919{
20- private static DateTimeZone |null $ dateTimeZone = null ;
20+ private DateTimeZone |null $ dateTimeZone = null ;
2121
22- private static string $ dateTimeFormat = 'c ' ;
22+ private string $ dateTimeFormat = 'c ' ;
23+
24+ public static function instance (): self
25+ {
26+ static $ instance = new self ();
27+
28+ return $ instance ;
29+ }
2330
2431 /** @return ($value is null ? null : bool) */
25- public static function asBool (mixed $ value ): bool |null
32+ public function asBool (mixed $ value ): bool |null
2633 {
2734 if ($ value === null ) {
2835 return null ;
@@ -44,7 +51,7 @@ public static function asBool(mixed $value): bool|null
4451 }
4552
4653 /** @return ($value is null ? null : float) */
47- public static function asFloat (mixed $ value ): float |null
54+ public function asFloat (mixed $ value ): float |null
4855 {
4956 if ($ value === null ) {
5057 return null ;
@@ -66,7 +73,7 @@ public static function asFloat(mixed $value): float|null
6673 }
6774
6875 /** @return ($value is null ? null : int) */
69- public static function asInt (mixed $ value ): int |null
76+ public function asInt (mixed $ value ): int |null
7077 {
7178 if ($ value === null ) {
7279 return null ;
@@ -88,7 +95,7 @@ public static function asInt(mixed $value): int|null
8895 }
8996
9097 /** @return ($value is null ? null : string) */
91- public static function asString (mixed $ value ): string |null
98+ public function asString (mixed $ value ): string |null
9299 {
93100 if ($ value === null ) {
94101 return null ;
@@ -110,18 +117,18 @@ public static function asString(mixed $value): string|null
110117 }
111118
112119 /** @return ($value is null ? null : DateTimeImmutable) */
113- public static function asDateTimeImmutable (mixed $ value ): DateTimeImmutable |null
120+ public function asDateTimeImmutable (mixed $ value ): DateTimeImmutable |null
114121 {
115122 if ($ value === null ) {
116123 return null ;
117124 }
118125
119126 if ($ value instanceof DateTimeImmutable) {
120- if ($ value ->getTimezone ()->getName () === self :: timeZone ()->getName ()) {
127+ if ($ value ->getTimezone ()->getName () === $ this -> timeZone ()->getName ()) {
121128 return $ value ;
122129 }
123130
124- return $ value ->setTimezone (self :: timeZone ());
131+ return $ value ->setTimezone ($ this -> timeZone ());
125132 }
126133
127134 if ($ value instanceof Stringable) {
@@ -132,40 +139,40 @@ public static function asDateTimeImmutable(mixed $value): DateTimeImmutable|null
132139 throw NotConvertable::toDateTime ($ value );
133140 }
134141
135- return new DateTimeImmutable (asString ($ value ), self :: timeZone ());
142+ return new DateTimeImmutable (asString ($ value ), $ this -> timeZone ());
136143 }
137144
138145 /** @return ($value is null ? null : string) */
139- public static function asDateTimeString (mixed $ value ): string |null
146+ public function asDateTimeString (mixed $ value ): string |null
140147 {
141148 if ($ value === null ) {
142149 return null ;
143150 }
144151
145152 $ value = asDateTimeImmutable ($ value );
146153
147- return $ value ->format (self :: dateTimeFormat ());
154+ return $ value ->format ($ this -> dateTimeFormat ());
148155 }
149156
150- public static function timeZone (DateTimeZone |string |null $ timeZone = null ): DateTimeZone
157+ public function timeZone (DateTimeZone |string |null $ timeZone = null ): DateTimeZone
151158 {
152159 if (is_string ($ timeZone )) {
153- self :: $ dateTimeZone = new DateTimeZone ($ timeZone );
160+ $ this -> dateTimeZone = new DateTimeZone ($ timeZone );
154161 } elseif ($ timeZone instanceof DateTimeZone) {
155- self :: $ dateTimeZone = $ timeZone ;
156- } elseif (!self :: $ dateTimeZone instanceof DateTimeZone) {
157- self :: $ dateTimeZone = new DateTimeZone (ini_get ('date.timezone ' ));
162+ $ this -> dateTimeZone = $ timeZone ;
163+ } elseif (!$ this -> dateTimeZone instanceof DateTimeZone) {
164+ $ this -> dateTimeZone = new DateTimeZone (ini_get ('date.timezone ' ));
158165 }
159166
160- return self :: $ dateTimeZone ;
167+ return $ this -> dateTimeZone ;
161168 }
162169
163- public static function dateTimeFormat (string |null $ dateTimeFormat = null ): string
170+ public function dateTimeFormat (string |null $ dateTimeFormat = null ): string
164171 {
165172 if ($ dateTimeFormat !== null ) {
166- self :: $ dateTimeFormat = $ dateTimeFormat ;
173+ $ this -> dateTimeFormat = $ dateTimeFormat ;
167174 }
168175
169- return self :: $ dateTimeFormat ;
176+ return $ this -> dateTimeFormat ;
170177 }
171178}
0 commit comments