brick / date-time

Date and time library for PHP
MIT License
323 stars 29 forks source link

Make the TimeZone parameter optional in *::now(..) #21

Closed kagmole closed 4 years ago

kagmole commented 4 years ago

Make the TimeZone parameter optional in the following static factory methods:

If no time zone is provided, the default one is used. Say:

if ($timeZone === null) {
    $timeZone = TimeZone::fromDateTimeZone(new \DateTimeZone());
}

If the proposal is accepted, I can write the changes.

BenMorel commented 4 years ago

Hi, thanks for your suggestion. I'm uncomfortable with having a default timezone, as people will start using it without thinking about it twice, and this will lead to bugs as soon as the default is changed.

I've always found it much more solid to manually provide the timezone, and it always made sense to provide it wherever I used now().

NB: The only thing that has a default value is the Clock, as it would be very cumbersome to have to provide your own. Timezone? It's always good to provide it explicitly, and I feel like this is an advantage of this library over PHP's DateTime, which is affected by the default timezone, and can have the same code produce different outputs on different platforms.