Skip to content

Commit

Permalink
Merge pull request fzaninotto#1419 from TomzxForks/fixes/1418-datetim…
Browse files Browse the repository at this point in the history
…e-return-types

Update PHPDoc of the DateTime provider.
  • Loading branch information
fzaninotto authored Feb 5, 2018
2 parents d6e741d + 7d33ad9 commit c8db653
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/Faker/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@
* @property \DateTime $dateTimeThisYear
* @property \DateTime $dateTimeThisMonth
* @property string $amPm
* @property int $dayOfMonth
* @property int $dayOfWeek
* @property int $month
* @property string $dayOfMonth
* @property string $dayOfWeek
* @property string $month
* @property string $monthName
* @property int $year
* @property int $century
* @property string $year
* @property string $century
* @property string $timezone
* @method string amPm($max = 'now')
* @method string date($format = 'Y-m-d', $max = 'now')
Expand All @@ -109,7 +109,7 @@
* @method string month($max = 'now')
* @method string monthName($max = 'now')
* @method string time($format = 'H:i:s', $max = 'now')
* @method string unixTime($max = 'now')
* @method int unixTime($max = 'now')
* @method string year($max = 'now')
* @method \DateTime dateTime($max = 'now', $timezone = null)
* @method \DateTime dateTimeAd($max = 'now', $timezone = null)
Expand Down
32 changes: 20 additions & 12 deletions src/Faker/Provider/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class DateTime extends Base

protected static $defaultTimezone = null;

/**
* @param string|float|int $max
* @return int|false
*/
protected static function getMaxTimestamp($max = 'now')
{
if (is_numeric($max)) {
Expand Down Expand Up @@ -56,7 +60,7 @@ public static function dateTime($max = 'now', $timezone = null)
* Get a datetime object for a date between January 1, 001 and now
*
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example DateTime('1265-03-22 21:15:52')
* @return \DateTime
* @see http://php.net/manual/en/timezones.php
Expand Down Expand Up @@ -115,7 +119,7 @@ public static function time($format = 'H:i:s', $max = 'now')
*
* @param \DateTime|string $startDate Defaults to 30 years ago
* @param \DateTime|string $endDate Defaults to "now"
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example DateTime('1999-02-02 11:42:52')
* @return \DateTime
* @see http://php.net/manual/en/timezones.php
Expand Down Expand Up @@ -145,7 +149,7 @@ public static function dateTimeBetween($startDate = '-30 years', $endDate = 'now
*
* @param string $date Defaults to 30 years ago
* @param string $interval Defaults to 5 days after
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example dateTimeInInterval('1999-02-02 11:42:52', '+ 5 days')
* @return \DateTime
* @see http://php.net/manual/en/timezones.php
Expand All @@ -170,7 +174,7 @@ public static function dateTimeInInterval($date = '-30 years', $interval = '+5 d

/**
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example DateTime('1964-04-04 11:02:02')
* @return \DateTime
*/
Expand All @@ -181,7 +185,7 @@ public static function dateTimeThisCentury($max = 'now', $timezone = null)

/**
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example DateTime('2010-03-10 05:18:58')
* @return \DateTime
*/
Expand All @@ -192,7 +196,7 @@ public static function dateTimeThisDecade($max = 'now', $timezone = null)

/**
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example DateTime('2011-09-19 09:24:37')
* @return \DateTime
*/
Expand All @@ -203,7 +207,7 @@ public static function dateTimeThisYear($max = 'now', $timezone = null)

/**
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
* @param string $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @param string|null $timezone time zone in which the date time should be set, default to DateTime::$defaultTimezone, if set, otherwise the result of `date_default_timezone_get`
* @example DateTime('2011-10-05 12:51:46')
* @return \DateTime
*/
Expand Down Expand Up @@ -264,8 +268,8 @@ public static function monthName($max = 'now')

/**
* @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
* @return int
* @example 1673
* @return string
* @example '1673'
*/
public static function year($max = 'now')
{
Expand Down Expand Up @@ -294,9 +298,9 @@ public static function timezone()
* Internal method to set the time zone on a DateTime.
*
* @param \DateTime $dt
* @param string $timezone
* @param string|null $timezone
*
* @return $this
* @return \DateTime
*/
private static function setTimezone(\DateTime $dt, $timezone)
{
Expand All @@ -318,13 +322,17 @@ public static function setDefaultTimezone($timezone = null)
/**
* Gets default time zone.
*
* @return string
* @return string|null
*/
public static function getDefaultTimezone()
{
return static::$defaultTimezone;
}

/**
* @param string|null $timezone
* @return null|string
*/
private static function resolveTimezone($timezone)
{
return ((null === $timezone) ? ((null === static::$defaultTimezone) ? date_default_timezone_get() : static::$defaultTimezone) : $timezone);
Expand Down

0 comments on commit c8db653

Please sign in to comment.