3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Wrapper for PHP's DateTime class inspired by moment.js * * @author Tino Ehrich <ehrich@efides.com> * @version See composer.json * * @dependencies >= PHP 5.3.0 */ namespace Moment; class Moment extends \DateTime { /** @var string */ protected $_timezoneString; // ########################################## /** * @param string $dateTime * @param string $timezone */ public function __construct($dateTime = 'now', $timezone = 'UTC') { return $this->resetDateTime($dateTime, $timezone); } // ########################################## /** * @param string $timezoneString * * @return Moment */ protected function _setTimezoneString($timezoneString) { $this->_timezoneString = $timezoneString; return $this; } // ########################################## /** * @return string */ protected function _getTimezoneString() { return $this->_timezoneString; } // ########################################## /** * @param string $timezone * * @return \DateTimeZone */ protected function _getDateTimeZone($timezone) { return new \DateTimeZone($timezone); } // ########################################## /** * @param string $timezone * * @return \DateTime|Moment */ public function setTimezone($timezone) { $this->_setTimezoneString($timezone); parent::setTimezone($this->_getDateTimeZone($timezone)); return $this; } // ########################################## /** * @param string $dateTime * @param string $timezone * * @return Moment */ public function resetDateTime($dateTime = 'now', $timezone = 'UTC') { // cache timezone string $this->_setTimezoneString($timezone); // create instance parent::__construct($dateTime, $this->_getDateTimeZone($timezone)); return $this; } // ########################################## /** * @param null $format * @param null|FormatsInterface $formatsInterface * * @return string */ public function format($format = NULL, $formatsInterface = NULL) { // set default format if ($format === NULL) { $format = \DateTime::ISO8601; } // handle diverse format types if ($formatsInterface instanceof FormatsInterface) { $format = $formatsInterface->format($format); } return parent::format($format); } // ############################################ /** * @param string $type * @param int $value * * @return Moment */ public function add($type = 'day', $value = 1) { parent::modify('+' . $value . ' ' . $type); return $this; } // ############################################ /** * @param string $type * @param int $value * * @return Moment */ public function subtract($type = 'day', $value = 1) { parent::modify('-' . $value . ' ' . $type); return $this; } // ###################################### /** * @param string $dateTime * @param string $timezone * * @return MomentFromVo */ public function from($dateTime = 'now', $timezone = 'UTC') { $fromInstance = parent::diff(new Moment($dateTime, $timezone)); return (new MomentFromVo()) ->setDirection($fromInstance->format('%R')) ->setSeconds($this->_fromToSeconds($fromInstance)) ->setMinutes($this->_fromToMinutes($fromInstance)) ->setHours($this->_fromToHours($fromInstance)) ->setDays($this->_fromToDays($fromInstance)) ->setWeeks($this->_fromToWeeks($fromInstance)); } // ###################################### /** * @param string $timezone * * @return MomentFromVo */ public function fromNow($timezone = 'UTC') { return $this->from('now', $timezone); } // ###################################### /** * @param \DateInterval $dateInterval * * @return string */ protected function _fromToSeconds(\DateInterval $dateInterval) { return ($dateInterval->y * 365 * 24 * 60 * 60) + ($dateInterval->m * 30 * 24 * 60 * 60) + ($dateInterval->d * 24 * 60 * 60) + ($dateInterval->h * 60 * 60) + $dateInterval->s; } // ###################################### /** * @param \DateInterval $dateInterval * * @return string */ protected function _fromToMinutes(\DateInterval $dateInterval) { return $this->_fromToSeconds($dateInterval) / 60; } // ###################################### /** * @param \DateInterval $dateInterval * * @return string */ protected function _fromToHours(\DateInterval $dateInterval) { return $this->_fromToMinutes($dateInterval) / 60; } // ###################################### /** * @param \DateInterval $dateInterval * * @return string */ protected function _fromToDays(\DateInterval $dateInterval) { return $this->_fromToHours($dateInterval) / 24; } // ###################################### /** * @param \DateInterval $dateInterval * * @return string */ protected function _fromToWeeks(\DateInterval $dateInterval) { return $this->_fromToDays($dateInterval) / 7; } // ###################################### /** * @param $period * * @return MomentPeriodVo * @throws \Exception */ public function getPeriod($period) { switch ($period) { case 'week': $currentWeekDay = $this->format('N'); $start = (new Moment('@' . $this->format('U'))) ->setTimezone($this->_getTimezoneString()) ->subtract('day', $currentWeekDay - 1) ->setTime(0, 0, 0); $end = (new Moment('@' . $this->format('U'))) ->setTimezone($this->_getTimezoneString()) ->add('day', 7 - $currentWeekDay) ->setTime(23, 59, 59); break; // ------------------------------ case 'month': $maxMonthDays = $this->format('t'); $currentMonthDay = $this->format('j'); $start = (new Moment('@' . $this->format('U'))) ->setTimezone($this->_getTimezoneString()) ->subtract('day', $currentMonthDay - 1) ->setTime(0, 0, 0); $end = (new Moment('@' . $this->format('U'))) ->setTimezone($this->_getTimezoneString()) ->add('day', $maxMonthDays - $currentMonthDay) ->setTime(23, 59, 59); break; // ------------------------------ default: throw new \Exception("Period \"{$period}\" is not supported yet (supported are \"week\" and \"month\").", 500); } return (new MomentPeriodVo()) ->setRefDate($this) ->setStartDate($start) ->setEndDate($end); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0090.00618.68
8.3.50.0100.00621.14
8.3.40.0180.00018.98
8.3.30.0110.00419.27
8.3.20.0000.00720.35
8.3.10.0080.00021.97
8.3.00.0000.00822.42
8.2.180.0090.00616.75
8.2.170.0110.01122.96
8.2.160.0110.01120.47
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0030.00726.16
8.2.120.0080.00019.54
8.2.110.0060.00322.30
8.2.100.0030.00919.37
8.2.90.0000.00819.27
8.2.80.0000.00819.49
8.2.70.0060.00317.50
8.2.60.0000.00817.80
8.2.50.0060.00318.07
8.2.40.0030.00518.22
8.2.30.0040.00417.98
8.2.20.0040.00417.59
8.2.10.0060.00317.70
8.2.00.0050.00317.69
8.1.280.0000.01925.92
8.1.270.0040.00420.03
8.1.260.0030.00526.35
8.1.250.0060.00328.09
8.1.240.0060.00323.91
8.1.230.0040.00819.29
8.1.220.0030.00517.79
8.1.210.0050.00318.77
8.1.200.0030.00617.35
8.1.190.0040.00417.43
8.1.180.0040.00418.72
8.1.170.0040.00418.64
8.1.160.0040.00422.13
8.1.150.0080.00018.63
8.1.140.0030.00617.29
8.1.130.0000.00717.98
8.1.120.0000.00817.46
8.1.110.0040.00417.51
8.1.100.0040.00417.49
8.1.90.0050.00217.52
8.1.80.0040.00417.36
8.1.70.0000.00717.43
8.1.60.0030.00617.48
8.1.50.0040.00417.50
8.1.40.0030.00617.50
8.1.30.0000.00817.61
8.1.20.0040.00417.66
8.1.10.0050.00317.52
8.1.00.0080.00017.35
8.0.300.0060.00318.77
8.0.290.0070.00017.05
8.0.280.0070.00018.45
8.0.270.0040.00417.31
8.0.260.0000.00716.78
8.0.250.0030.00316.95
8.0.240.0080.00016.94
8.0.230.0070.00016.84
8.0.220.0070.00016.85
8.0.210.0050.00216.93
8.0.200.0050.00216.95
8.0.190.0030.00516.85
8.0.180.0000.00716.91
8.0.170.0040.00416.80
8.0.160.0000.00716.86
8.0.150.0000.00816.88
8.0.140.0040.00416.77
8.0.130.0060.00013.34
8.0.120.0080.00016.84
8.0.110.0050.00316.95
8.0.100.0040.00416.81
8.0.90.0000.00716.88
8.0.80.0070.01116.86
8.0.70.0000.00716.71
8.0.60.0050.00216.86
8.0.50.0050.00316.76
8.0.30.0030.01617.06
8.0.20.0150.00317.40
8.0.10.0040.00417.00
8.0.00.0080.01316.69
7.4.330.0030.00315.00
7.4.320.0030.00316.57
7.4.300.0030.00316.43
7.4.290.0030.00316.58
7.4.280.0040.00416.48
7.4.270.0030.00416.52
7.4.260.0000.00716.60
7.4.250.0000.00816.64
7.4.240.0050.00216.54
7.4.230.0000.00716.58
7.4.220.0090.00916.48
7.4.210.0080.00716.51
7.4.200.0000.00716.57
7.4.190.0040.00416.59
7.4.160.0100.00716.46
7.4.150.0110.01317.40
7.4.140.0090.01117.86
7.4.130.0090.01116.61
7.4.120.0100.01316.48
7.4.110.0090.00916.46
7.4.100.0090.00616.51
7.4.90.0090.00916.34
7.4.80.0000.02519.39
7.4.70.0100.00716.40
7.4.60.0100.01316.49
7.4.50.0030.00616.55
7.4.40.0090.00622.77
7.4.30.0050.01116.56
7.4.00.0000.01714.88
7.3.330.0050.00013.24
7.3.320.0000.00513.04
7.3.310.0000.00716.32
7.3.300.0070.00016.30
7.3.290.0100.00316.27
7.3.280.0070.01116.29
7.3.270.0100.00717.40
7.3.260.0160.00316.26
7.3.250.0110.00616.43
7.3.240.0110.01116.50
7.3.230.0170.00316.55
7.3.210.0060.01516.21
7.3.200.0060.01319.39
7.3.190.0040.01416.48
7.3.180.0100.00616.54
7.3.170.0100.00716.33
7.3.160.0030.01316.32
7.3.120.0100.00314.82
7.3.10.0030.01016.50
7.3.00.0070.00716.34
7.2.330.0150.00316.48
7.2.320.0060.01216.56
7.2.310.0130.01016.51
7.2.300.0120.01216.49
7.2.290.0030.01616.45
7.2.130.0100.00316.62
7.2.120.0030.00916.76
7.2.110.0000.01016.84
7.2.100.0030.00716.65
7.2.90.0070.00716.70
7.2.80.0000.00816.24
7.2.70.0090.00616.77
7.2.60.0030.01116.61
7.2.50.0090.00016.89
7.2.40.0030.00916.67
7.2.30.0000.01416.77
7.2.20.0150.00016.65
7.2.10.0030.00916.58
7.2.00.0030.01217.86
7.1.250.0000.00815.43
7.1.200.0060.00315.34
7.1.100.0060.00617.80
7.1.70.0060.00316.60
7.1.60.0090.01619.82
7.1.50.0060.00616.67
7.1.00.0070.06022.35
7.0.200.0000.00716.70
7.0.140.0030.07021.94
7.0.100.0300.08720.14
7.0.90.0330.08020.02
7.0.80.0330.08020.01
7.0.70.0030.08720.01
7.0.60.0100.08020.04
7.0.50.0100.07320.44
7.0.40.0130.06720.15
7.0.30.0130.07320.09
7.0.20.0170.04320.15
7.0.10.0130.04720.18
7.0.00.0200.03720.09
5.6.280.0030.07021.05
5.6.250.0130.08020.66
5.6.240.0200.07020.57
5.6.230.0070.08320.69
5.6.220.0230.07020.74
5.6.210.0100.07720.67
5.6.200.0130.06321.02
5.6.190.0070.04721.14
5.6.180.0070.06020.95
5.6.170.0030.08321.20
5.6.160.0130.07721.08
5.6.150.0100.07721.03
5.6.140.0100.06021.14
5.6.130.0030.09021.08
5.6.120.0200.07021.07
5.6.110.0100.08021.23
5.6.100.0030.05021.16
5.6.90.0070.08021.02
5.6.80.0030.08020.58
5.6.70.0030.06020.43
5.6.60.0030.07320.51
5.6.50.0070.08320.55
5.6.40.0100.07320.55
5.6.30.0070.04720.49
5.6.20.0130.06720.53
5.6.10.0170.06320.37
5.6.00.0000.06720.45
5.5.380.0070.06020.49
5.5.370.0070.08320.41
5.5.360.0100.06320.45
5.5.350.0100.03320.48
5.5.340.0130.06320.95
5.5.330.0030.08720.86
5.5.320.0170.07720.97
5.5.310.0000.05020.99
5.5.300.0130.04320.71
5.5.290.0070.08020.84
5.5.280.0070.08020.84
5.5.270.0070.04720.93
5.5.260.0000.09320.77
5.5.250.0170.06320.76
5.5.240.0170.04320.38
5.5.230.0170.06720.21
5.5.220.0070.07320.27
5.5.210.0030.08320.31
5.5.200.0100.07320.22
5.5.190.0070.07020.14
5.5.180.0130.07720.05
5.5.160.0170.06720.24
5.5.150.0000.08720.19
5.5.140.0100.07020.35
5.5.130.0170.06020.33
5.5.120.0100.07320.33
5.5.110.0130.07720.30
5.5.100.0000.08720.14
5.5.90.0030.06320.21
5.5.80.0130.06020.21
5.5.70.0200.07020.16
5.5.60.0130.05020.11
5.5.50.0070.07320.10
5.5.40.0030.04720.02
5.5.30.0000.09020.14
5.5.20.0100.04320.11
5.5.10.0100.07020.18
5.5.00.0100.04019.98
5.4.450.0100.04319.48
5.4.440.0100.07719.51
5.4.430.0070.04719.45
5.4.420.0070.04319.50
5.4.410.0070.07719.24
5.4.400.0030.07018.87
5.4.390.0100.08019.19
5.4.380.0070.07719.16
5.4.370.0100.07019.04
5.4.360.0070.07018.85
5.4.350.0100.07318.90
5.4.340.0130.05319.03
5.4.320.0130.06319.09
5.4.310.0030.04318.85
5.4.300.0030.07718.94
5.4.290.0070.08019.04
5.4.280.0130.07018.87
5.4.270.0100.07019.05
5.4.260.0070.08019.14
5.4.250.0070.07719.20
5.4.240.0000.08019.16
5.4.230.0170.08019.13
5.4.220.0100.06318.89
5.4.210.0130.07019.13
5.4.200.0070.07719.04
5.4.190.0100.04019.24
5.4.180.0100.06719.11
5.4.170.0170.05719.20
5.4.160.0070.07719.02
5.4.150.0030.05019.16
5.4.140.0000.04716.48
5.4.130.0070.07316.38
5.4.120.0130.06716.38
5.4.110.0030.07316.45
5.4.100.0070.07716.55
5.4.90.0130.03316.48
5.4.80.0030.07316.37
5.4.70.0000.06716.54
5.4.60.0130.06316.30
5.4.50.0070.07016.38
5.4.40.0100.06316.46
5.4.30.0030.06016.41
5.4.20.0070.07316.35
5.4.10.0030.08016.37
5.4.00.0070.07715.96
5.3.290.0030.04714.63
5.3.280.0030.06314.63
5.3.270.0070.07314.75
5.3.260.0070.07014.57
5.3.250.0130.05014.74
5.3.240.0130.06714.74
5.3.230.0100.07714.64
5.3.220.0100.07314.65
5.3.210.0100.04314.58
5.3.200.0000.04714.57
5.3.190.0030.04314.60
5.3.180.0170.06314.68
5.3.170.0100.03314.64
5.3.160.0030.05714.73
5.3.150.0100.06314.61
5.3.140.0100.06714.52
5.3.130.0070.04314.55
5.3.120.0030.08014.52
5.3.110.0100.06314.50
5.3.100.0030.07014.09
5.3.90.0030.07314.02
5.3.80.0200.04714.11
5.3.70.0030.07714.16
5.3.60.0100.07714.05
5.3.50.0100.07013.95
5.3.40.0130.07313.96
5.3.30.0000.06314.07
5.3.20.0030.07713.80
5.3.10.0000.06713.67
5.3.00.0170.06713.72

preferences:
38.71 ms | 401 KiB | 5 Q