PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / fzaninotto / faker / src / Faker / Provider / DateTime.php
kubio / vendor / fzaninotto / faker / src / Faker / Provider Last commit date
ar_JO 1 year ago ar_SA 1 year ago at_AT 1 year ago bg_BG 1 year ago bn_BD 1 year ago cs_CZ 1 year ago da_DK 1 year ago de_AT 1 year ago de_CH 1 year ago de_DE 1 year ago el_CY 1 year ago el_GR 1 year ago en_AU 1 year ago en_CA 1 year ago en_GB 1 year ago en_HK 1 year ago en_IN 1 year ago en_NG 1 year ago en_NZ 1 year ago en_PH 1 year ago en_SG 1 year ago en_UG 1 year ago en_US 1 year ago en_ZA 1 year ago es_AR 1 year ago es_ES 1 year ago es_PE 1 year ago es_VE 1 year ago et_EE 1 year ago fa_IR 1 year ago fi_FI 1 year ago fr_BE 1 year ago fr_CA 1 year ago fr_CH 1 year ago fr_FR 1 year ago he_IL 1 year ago hr_HR 1 year ago hu_HU 1 year ago hy_AM 1 year ago id_ID 1 year ago is_IS 1 year ago it_CH 1 year ago it_IT 1 year ago ja_JP 1 year ago ka_GE 1 year ago kk_KZ 1 year ago ko_KR 1 year ago lt_LT 1 year ago lv_LV 1 year ago me_ME 1 year ago mn_MN 1 year ago ms_MY 1 year ago nb_NO 1 year ago ne_NP 1 year ago nl_BE 1 year ago nl_NL 1 year ago pl_PL 1 year ago pt_BR 1 year ago pt_PT 1 year ago ro_MD 1 year ago ro_RO 1 year ago ru_RU 1 year ago sk_SK 1 year ago sl_SI 1 year ago sr_Cyrl_RS 1 year ago sr_Latn_RS 1 year ago sr_RS 1 year ago sv_SE 1 year ago th_TH 1 year ago tr_TR 1 year ago uk_UA 1 year ago vi_VN 1 year ago zh_CN 1 year ago zh_TW 1 year ago Address.php 1 year ago Barcode.php 1 year ago Base.php 1 year ago Biased.php 1 year ago Color.php 1 year ago Company.php 1 year ago DateTime.php 1 year ago File.php 1 year ago HtmlLorem.php 1 year ago Image.php 1 year ago Internet.php 1 year ago Lorem.php 1 year ago Miscellaneous.php 1 year ago Payment.php 1 year ago Person.php 1 year ago PhoneNumber.php 1 year ago Text.php 1 year ago UserAgent.php 1 year ago Uuid.php 1 year ago
DateTime.php
341 lines
1 <?php
2
3 namespace Faker\Provider;
4
5 class DateTime extends Base
6 {
7 protected static $century = array('I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV','XVI','XVII','XVIII','XIX','XX','XXI');
8
9 protected static $defaultTimezone = null;
10
11 /**
12 * @param \DateTime|string|float|int $max
13 * @return int|false
14 */
15 protected static function getMaxTimestamp($max = 'now')
16 {
17 if (is_numeric($max)) {
18 return (int) $max;
19 }
20
21 if ($max instanceof \DateTime) {
22 return $max->getTimestamp();
23 }
24
25 return strtotime(empty($max) ? 'now' : $max);
26 }
27
28 /**
29 * Get a timestamp between January 1, 1970 and now
30 *
31 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
32 * @return int
33 *
34 * @example 1061306726
35 */
36 public static function unixTime($max = 'now')
37 {
38 return mt_rand(0, static::getMaxTimestamp($max));
39 }
40
41 /**
42 * Get a datetime object for a date between January 1, 1970 and now
43 *
44 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
45 * @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`
46 * @example DateTime('2005-08-16 20:39:21')
47 * @return \DateTime
48 * @see http://php.net/manual/en/timezones.php
49 * @see http://php.net/manual/en/function.date-default-timezone-get.php
50 */
51 public static function dateTime($max = 'now', $timezone = null)
52 {
53 return static::setTimezone(
54 new \DateTime('@' . static::unixTime($max)),
55 $timezone
56 );
57 }
58
59 /**
60 * Get a datetime object for a date between January 1, 001 and now
61 *
62 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
63 * @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`
64 * @example DateTime('1265-03-22 21:15:52')
65 * @return \DateTime
66 * @see http://php.net/manual/en/timezones.php
67 * @see http://php.net/manual/en/function.date-default-timezone-get.php
68 */
69 public static function dateTimeAD($max = 'now', $timezone = null)
70 {
71 $min = (PHP_INT_SIZE>4 ? -62135597361 : -PHP_INT_MAX);
72 return static::setTimezone(
73 new \DateTime('@' . mt_rand($min, static::getMaxTimestamp($max))),
74 $timezone
75 );
76 }
77
78 /**
79 * get a date string formatted with ISO8601
80 *
81 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
82 * @return string
83 * @example '2003-10-21T16:05:52+0000'
84 */
85 public static function iso8601($max = 'now')
86 {
87 return static::date(\DateTime::ISO8601, $max);
88 }
89
90 /**
91 * Get a date string between January 1, 1970 and now
92 *
93 * @param string $format
94 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
95 * @return string
96 * @example '2008-11-27'
97 */
98 public static function date($format = 'Y-m-d', $max = 'now')
99 {
100 return static::dateTime($max)->format($format);
101 }
102
103 /**
104 * Get a time string (24h format by default)
105 *
106 * @param string $format
107 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
108 * @return string
109 * @example '15:02:34'
110 */
111 public static function time($format = 'H:i:s', $max = 'now')
112 {
113 return static::dateTime($max)->format($format);
114 }
115
116 /**
117 * Get a DateTime object based on a random date between two given dates.
118 * Accepts date strings that can be recognized by strtotime().
119 *
120 * @param \DateTime|string $startDate Defaults to 30 years ago
121 * @param \DateTime|string $endDate Defaults to "now"
122 * @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`
123 * @example DateTime('1999-02-02 11:42:52')
124 * @return \DateTime
125 * @see http://php.net/manual/en/timezones.php
126 * @see http://php.net/manual/en/function.date-default-timezone-get.php
127 */
128 public static function dateTimeBetween($startDate = '-30 years', $endDate = 'now', $timezone = null)
129 {
130 $startTimestamp = $startDate instanceof \DateTime ? $startDate->getTimestamp() : strtotime($startDate);
131 $endTimestamp = static::getMaxTimestamp($endDate);
132
133 if ($startTimestamp > $endTimestamp) {
134 throw new \InvalidArgumentException('Start date must be anterior to end date.');
135 }
136
137 $timestamp = mt_rand($startTimestamp, $endTimestamp);
138
139 return static::setTimezone(
140 new \DateTime('@' . $timestamp),
141 $timezone
142 );
143 }
144
145 /**
146 * Get a DateTime object based on a random date between one given date and
147 * an interval
148 * Accepts date string that can be recognized by strtotime().
149 *
150 * @param \DateTime|string $date Defaults to 30 years ago
151 * @param string $interval Defaults to 5 days after
152 * @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`
153 * @example dateTimeInInterval('1999-02-02 11:42:52', '+ 5 days')
154 * @return \DateTime
155 * @see http://php.net/manual/en/timezones.php
156 * @see http://php.net/manual/en/function.date-default-timezone-get.php
157 */
158 public static function dateTimeInInterval($date = '-30 years', $interval = '+5 days', $timezone = null)
159 {
160 $intervalObject = \DateInterval::createFromDateString($interval);
161 $datetime = $date instanceof \DateTime ? $date : new \DateTime($date);
162 $otherDatetime = clone $datetime;
163 $otherDatetime->add($intervalObject);
164
165 $begin = $datetime > $otherDatetime ? $otherDatetime : $datetime;
166 $end = $datetime===$begin ? $otherDatetime : $datetime;
167
168 return static::dateTimeBetween(
169 $begin,
170 $end,
171 $timezone
172 );
173 }
174
175 /**
176 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
177 * @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`
178 * @example DateTime('1964-04-04 11:02:02')
179 * @return \DateTime
180 */
181 public static function dateTimeThisCentury($max = 'now', $timezone = null)
182 {
183 return static::dateTimeBetween('-100 year', $max, $timezone);
184 }
185
186 /**
187 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
188 * @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`
189 * @example DateTime('2010-03-10 05:18:58')
190 * @return \DateTime
191 */
192 public static function dateTimeThisDecade($max = 'now', $timezone = null)
193 {
194 return static::dateTimeBetween('-10 year', $max, $timezone);
195 }
196
197 /**
198 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
199 * @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`
200 * @example DateTime('2011-09-19 09:24:37')
201 * @return \DateTime
202 */
203 public static function dateTimeThisYear($max = 'now', $timezone = null)
204 {
205 return static::dateTimeBetween('-1 year', $max, $timezone);
206 }
207
208 /**
209 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
210 * @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`
211 * @example DateTime('2011-10-05 12:51:46')
212 * @return \DateTime
213 */
214 public static function dateTimeThisMonth($max = 'now', $timezone = null)
215 {
216 return static::dateTimeBetween('-1 month', $max, $timezone);
217 }
218
219 /**
220 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
221 * @return string
222 * @example 'am'
223 */
224 public static function amPm($max = 'now')
225 {
226 return static::dateTime($max)->format('a');
227 }
228
229 /**
230 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
231 * @return string
232 * @example '22'
233 */
234 public static function dayOfMonth($max = 'now')
235 {
236 return static::dateTime($max)->format('d');
237 }
238
239 /**
240 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
241 * @return string
242 * @example 'Tuesday'
243 */
244 public static function dayOfWeek($max = 'now')
245 {
246 return static::dateTime($max)->format('l');
247 }
248
249 /**
250 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
251 * @return string
252 * @example '7'
253 */
254 public static function month($max = 'now')
255 {
256 return static::dateTime($max)->format('m');
257 }
258
259 /**
260 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
261 * @return string
262 * @example 'September'
263 */
264 public static function monthName($max = 'now')
265 {
266 return static::dateTime($max)->format('F');
267 }
268
269 /**
270 * @param \DateTime|int|string $max maximum timestamp used as random end limit, default to "now"
271 * @return string
272 * @example '1673'
273 */
274 public static function year($max = 'now')
275 {
276 return static::dateTime($max)->format('Y');
277 }
278
279 /**
280 * @return string
281 * @example 'XVII'
282 */
283 public static function century()
284 {
285 return static::randomElement(static::$century);
286 }
287
288 /**
289 * @return string
290 * @example 'Europe/Paris'
291 */
292 public static function timezone()
293 {
294 return static::randomElement(\DateTimeZone::listIdentifiers());
295 }
296
297 /**
298 * Internal method to set the time zone on a DateTime.
299 *
300 * @param \DateTime $dt
301 * @param string|null $timezone
302 *
303 * @return \DateTime
304 */
305 private static function setTimezone(\DateTime $dt, $timezone)
306 {
307 return $dt->setTimezone(new \DateTimeZone(static::resolveTimezone($timezone)));
308 }
309
310 /**
311 * Sets default time zone.
312 *
313 * @param string $timezone
314 *
315 * @return void
316 */
317 public static function setDefaultTimezone($timezone = null)
318 {
319 static::$defaultTimezone = $timezone;
320 }
321
322 /**
323 * Gets default time zone.
324 *
325 * @return string|null
326 */
327 public static function getDefaultTimezone()
328 {
329 return static::$defaultTimezone;
330 }
331
332 /**
333 * @param string|null $timezone
334 * @return null|string
335 */
336 private static function resolveTimezone($timezone)
337 {
338 return ((null === $timezone) ? ((null === static::$defaultTimezone) ? date_default_timezone_get() : static::$defaultTimezone) : $timezone);
339 }
340 }
341