| 1 |
<?php |
| 2 |
|
| 3 |
namespace TablePress\PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel; |
| 4 |
|
| 5 |
use DateTime; |
| 6 |
use DateTimeImmutable; |
| 7 |
use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
| 8 |
|
| 9 |
class Current |
| 10 |
{ |
| 11 |
/** |
| 12 |
* DATENOW. |
| 13 |
* |
| 14 |
* Returns the current date. |
| 15 |
* The NOW function is useful when you need to display the current date and time on a worksheet or |
| 16 |
* calculate a value based on the current date and time, and have that value updated each time you |
| 17 |
* open the worksheet. |
| 18 |
* |
| 19 |
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
| 20 |
* and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
| 21 |
* |
| 22 |
* Excel Function: |
| 23 |
* TODAY() |
| 24 |
* |
| 25 |
* @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
| 26 |
* depending on the value of the ReturnDateType flag |
| 27 |
*/ |
| 28 |
public static function today() |
| 29 |
{ |
| 30 |
$dti = new DateTimeImmutable(); |
| 31 |
$dateArray = Helpers::dateParse($dti->format('c')); |
| 32 |
|
| 33 |
return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : ExcelError::VALUE(); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* DATETIMENOW. |
| 38 |
* |
| 39 |
* Returns the current date and time. |
| 40 |
* The NOW function is useful when you need to display the current date and time on a worksheet or |
| 41 |
* calculate a value based on the current date and time, and have that value updated each time you |
| 42 |
* open the worksheet. |
| 43 |
* |
| 44 |
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date |
| 45 |
* and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way. |
| 46 |
* |
| 47 |
* Excel Function: |
| 48 |
* NOW() |
| 49 |
* |
| 50 |
* @return DateTime|float|int|string Excel date/time serial value, PHP date/time serial value or PHP date/time object, |
| 51 |
* depending on the value of the ReturnDateType flag |
| 52 |
*/ |
| 53 |
public static function now() |
| 54 |
{ |
| 55 |
$dti = new DateTimeImmutable(); |
| 56 |
$dateArray = Helpers::dateParse($dti->format('c')); |
| 57 |
|
| 58 |
return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : ExcelError::VALUE(); |
| 59 |
} |
| 60 |
} |
| 61 |
|