@@ -67,6 +67,27 @@ public static function createFromSapWeek($sapWeek, $timezone = null)
6767 return new parent ($ week , $ timezone );
6868 }
6969
70+ /**
71+ * Parse an SAP date string into a new DateTime object.
72+ *
73+ * @param string $sapDate String representing the SAP date.
74+ * @param \DateTimeZone $timezone A DateTimeZone object representing the desired
75+ * time zone.
76+ * @return \DateTime|false
77+ */
78+ public static function createFromSapDate ($ sapDate , $ timezone = null )
79+ {
80+ if ($ timezone === null ) {
81+ $ result = parent ::createFromFormat (static ::SAP_DATE , $ sapDate );
82+ } else {
83+ $ result = parent ::createFromFormat (static ::SAP_DATE , $ sapDate , $ timezone );
84+ }
85+ if ($ result !== false ) {
86+ $ result ->setTime (0 , 0 , 0 );
87+ }
88+ return $ result ;
89+ }
90+
7091 /**
7192 * Parse a string into a new DateTime object according to the specified format.
7293 *
@@ -87,13 +108,8 @@ public static function createFromFormat(
87108 if ($ format === static ::SAP_WEEK ) {
88109 return static ::createFromSapWeek ($ time , $ timezone );
89110 }
90- if ($ format === static ::SAP_DATE && $ timezone === null ) {
91- return parent ::createFromFormat ($ format , $ time )
92- ->setTime (0 , 0 , 0 );
93- }
94111 if ($ format === static ::SAP_DATE ) {
95- return parent ::createFromFormat ($ format , $ time , $ timezone )
96- ->setTime (0 , 0 , 0 );
112+ return static ::createFromSapDate ($ time , $ timezone );
97113 }
98114 if ($ timezone === null ) {
99115 return parent ::createFromFormat ($ format , $ time );
0 commit comments