5pm-HDH / churchtools-api

The Churchtools-API Client is a wrapper for the churchtools-api written in PHP.
MIT License
19 stars 8 forks source link

Date-Fields as DateTime object #158

Closed DumbergerL closed 1 year ago

DumbergerL commented 1 year ago

Convert date-fields (e.q. startDate, endDate) to DateTime objects instead of strings.

Attention: Time is in UTC-Format (https://github.com/5pm-HDH/churchtools-api/issues/138#issuecomment-1568102822)

One potential solution is to introduce an additional getter that returns the start date as a converted date-time value:

However, this approach has a drawback. The internal type of the start date would still be a string. Consequently, the conversion would occur only when the getter is called, and the "FillWithData" trait would not guarantee that the input provided is of type date.

BiKi05 commented 1 year ago

👍

DumbergerL commented 1 year ago

Attention:

The createFromFormat-Method uses the current time when it only receives a date! This method should therefore only be used for dates with time!

$date = DateTime::createFromFormat("Y-m-d", "2021-06-21");
var_dump($date->getTimestamp());
var_dump($date->format("Y-m-d H:i:s"));