55[ ![ Maintainability] [ maintainability-badge ]] [ maintainability ]
66[ ![ Test Coverage] [ coverage-badge ]] [ coverage ]
77
8- Extends PHP's DateTime class by SAP week, date, time and timestamp format.
8+ Extends PHP's [ DateTime] [ datetime ] class by SAP week, date, time and timestamp
9+ format. Extends PHP's [ DateInterval] [ dateinterval ] class by SAP time format.
910
1011* SAP week in format ` <year><week> `
1112* SAP date in format ` <year><month><day> `
@@ -78,6 +79,28 @@ echo $dateTime->format('H:i:s') . PHP_EOL;
7879 */
7980```
8081
82+ ### Parse a SAP time string into a DateInterval object
83+
84+ This example uses 25 hours to demonstrate the usage of a DateInterval object
85+ in combination with a DateTime object. Please beware, that the ` format() `
86+ method is more like PHP's ` sprintf() ` and less like ` date() ` .
87+
88+ ``` php
89+ <?php
90+ use phpsap\DateTime\SapDateInterval;
91+ $time = SapDateInterval::createFromDateString('252003');
92+ echo $time->format('%H:%I:%S') . PHP_EOL;
93+ /**
94+ * Output: 25:20:03
95+ */
96+ $date = new DateTime('2018-11-01 00:00:00');
97+ $date->add($time);
98+ echo $date->format('Y-m-d H:i:s');
99+ /**
100+ * Output: 2018-11-02 01:20:03
101+ */
102+ ```
103+
81104### Format a DateTime object as SAP time
82105
83106``` php
@@ -90,6 +113,18 @@ echo $dateTime->format(SapDateTime::SAP_TIME) . PHP_EOL;
90113 */
91114```
92115
116+ ### Format a DateInterval object as SAP time
117+
118+ ``` php
119+ <?php
120+ use phpsap\DateTime\SapDateInterval;
121+ $time = new SapDateInterval('PTH21M45S05');
122+ echo $time->format(SapDateInterval::SAP_TIME) . PHP_EOL;
123+ /**
124+ * Output: 214505
125+ */
126+ ```
127+
93128### Parse a SAP timestamp into a DateTime object
94129
95130``` php
@@ -121,3 +156,5 @@ echo $dateTime->format(SapDateTime::SAP_TIMESTAMP) . PHP_EOL;
121156[ maintainability ] : https://codeclimate.com/github/php-sap/datetime/maintainability
122157[ coverage-badge ] : https://api.codeclimate.com/v1/badges/1bfab925e39bfaf242fc/test_coverage
123158[ coverage ] : https://codeclimate.com/github/php-sap/datetime/test_coverage
159+ [ datetime ] : https://www.php.net/manual/en/class.datetime.php
160+ [ dateinterval ] : https://www.php.net/manual/en/class.dateinterval.php
0 commit comments