# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php

TablePress – Tables in WordPress made easy, version 3.4. 153 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php
- Modified: 2025-12-16T10:47:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;

use TablePress\PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception;
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use TablePress\PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
use Throwable;

class TimeParts
{
	use ArrayEnabled;

	/**
	 * HOUROFDAY.
	 *
	 * Returns the hour of a time value.
	 * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
	 *
	 * Excel Function:
	 *        HOUR(timeValue)
	 *
	 * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
	 *                                    PHP DateTime object, or a standard time string
	 *                         Or can be an array of date/time values
	 *
	 * @return array<mixed>|int|string Hour
	 *         If an array of numbers is passed as the argument, then the returned result will also be an array
	 *            with the same dimensions
	 */
	public static function hour($timeValue)
	{
		if (is_array($timeValue)) {
			return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
		}

		try {
			Helpers::nullFalseTrueToNumber($timeValue);
			if (is_string($timeValue) && !is_numeric($timeValue)) {
				$timeValue = Helpers::getTimeValue($timeValue);
			}
			Helpers::validateNotNegative($timeValue);
		} catch (Exception $e) {
			return $e->getMessage();
		}

		// Execute function
		try {
			SharedDateHelper::excelToDateTimeObject($timeValue);
		} catch (Throwable $exception) {
			return ExcelError::NAN();
		}
		$timeValue = fmod($timeValue, 1);
		$timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
		SharedDateHelper::roundMicroseconds($timeValue);

		return (int) $timeValue->format('H');
	}

	/**
	 * MINUTE.
	 *
	 * Returns the minutes of a time value.
	 * The minute is given as an integer, ranging from 0 to 59.
	 *
	 * Excel Function:
	 *        MINUTE(timeValue)
	 *
	 * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
	 *                                    PHP DateTime object, or a standard time string
	 *                         Or can be an array of date/time values
	 *
	 * @return array<mixed>|int|string Minute
	 *         If an array of numbers is passed as the argument, then the returned result will also be an array
	 *            with the same dimensions
	 */
	public static function minute($timeValue)
	{
		if (is_array($timeValue)) {
			return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
		}

		try {
			Helpers::nullFalseTrueToNumber($timeValue);
			if (is_string($timeValue) && !is_numeric($timeValue)) {
				$timeValue = Helpers::getTimeValue($timeValue);
			}
			Helpers::validateNotNegative($timeValue);
		} catch (Exception $e) {
			return $e->getMessage();
		}

		// Execute function
		try {
			SharedDateHelper::excelToDateTimeObject($timeValue);
		} catch (Throwable $exception) {
			return ExcelError::NAN();
		}
		$timeValue = fmod($timeValue, 1);
		$timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
		SharedDateHelper::roundMicroseconds($timeValue);

		return (int) $timeValue->format('i');
	}

	/**
	 * SECOND.
	 *
	 * Returns the seconds of a time value.
	 * The minute is given as an integer, ranging from 0 to 59.
	 *
	 * Excel Function:
	 *        SECOND(timeValue)
	 *
	 * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
	 *                                    PHP DateTime object, or a standard time string
	 *                         Or can be an array of date/time values
	 *
	 * @return array<mixed>|int|string Second
	 *         If an array of numbers is passed as the argument, then the returned result will also be an array
	 *            with the same dimensions
	 */
	public static function second($timeValue)
	{
		if (is_array($timeValue)) {
			return self::evaluateSingleArgumentArray([self::class, __FUNCTION__], $timeValue);
		}

		try {
			Helpers::nullFalseTrueToNumber($timeValue);
			if (is_string($timeValue) && !is_numeric($timeValue)) {
				$timeValue = Helpers::getTimeValue($timeValue);
			}
			Helpers::validateNotNegative($timeValue);
		} catch (Exception $e) {
			return $e->getMessage();
		}

		// Execute function
		try {
			SharedDateHelper::excelToDateTimeObject($timeValue);
		} catch (Throwable $exception) {
			return ExcelError::NAN();
		}
		$timeValue = fmod($timeValue, 1);
		$timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
		SharedDateHelper::roundMicroseconds($timeValue);

		return (int) $timeValue->format('s');
	}
}

```
