Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Time zone inconsistency in dateTime* methods #676

Closed
bishopb opened this issue Aug 19, 2015 · 2 comments
Closed

Time zone inconsistency in dateTime* methods #676

bishopb opened this issue Aug 19, 2015 · 2 comments

Comments

@bishopb
Copy link
Contributor

bishopb commented Aug 19, 2015

There are four DateTime returning methods: dateTime, dateTimeAD, dateTimeBetween, and dateTimeInterval, Two of them set the time zone (dateTimeBetween and dateTimeInterval) on the returned object, while the other two do not. This leads to user land code having to juggle time zones when comparing dates returned from the different generators.

The generators should all return times in the same zone, unless the user specifically says to return times in different time zones. PR #675 adds this support:

$faker->dateTime; // time zone is UTC
$faker->dateTime('now', 'America/New_York'); // custom time zone

// likewise for dateTimeAD, dateTimeBetween, and dateTimeInterval
@jremes-foss
Copy link
Contributor

Right, I see what this is about.

Method dateTimeBetween returns a timestamp, like this:

        $timestamp = mt_rand($startTimestamp, $endTimestamp);
        $ts = new \DateTime('@' . $timestamp);
        $ts->setTimezone(new \DateTimeZone(date_default_timezone_get()));
        return $ts;

Where as, dateTimeInInterval doesn't:

return static::dateTimeBetween($begin, $end);

Question follows: should dateTimeBetween return such a time stamp as well? My opinion is that it actually should.

Method dateTimeInterval gets a DateTime object based on a random date between two given dates, dateTimeInterval gets a DateTime object based on a random date between one given date and an interval.

It might be a bit tricky to implement but I need to see how that interval thing actually works. If someone has some sample data, please feel free to post it to this thread.

@bishopb
Copy link
Contributor Author

bishopb commented May 3, 2016

The now closed PR #675 standardized this behavior: all these methods now return a \DateTime with the timezone set to the system default, with the possibility to set the timezone in the generator.

@bishopb bishopb closed this as completed May 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants