Blame view

vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php 3.38 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  <?php
  
  namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
  
  use PhpOffice\PhpSpreadsheet\Calculation\Exception;
  
  class Month
  {
      /**
       * EDATE.
       *
       * Returns the serial number that represents the date that is the indicated number of months
       * before or after a specified date (the start_date).
       * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
       * as the date of issue.
       *
       * Excel Function:
       *        EDATE(dateValue,adjustmentMonths)
       *
       * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
       *                                        PHP DateTime object, or a standard date string
       * @param int $adjustmentMonths The number of months before or after start_date.
       *                                        A positive value for months yields a future date;
       *                                        a negative value yields a past date.
       *
       * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
       *                        depending on the value of the ReturnDateType flag
       */
      public static function adjust($dateValue, $adjustmentMonths)
      {
          try {
              $dateValue = Helpers::getDateValue($dateValue, false);
              $adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths);
          } catch (Exception $e) {
              return $e->getMessage();
          }
          $adjustmentMonths = floor($adjustmentMonths);
  
          // Execute function
          $PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths);
  
          return Helpers::returnIn3FormatsObject($PHPDateObject);
      }
  
      /**
       * EOMONTH.
       *
       * Returns the date value for the last day of the month that is the indicated number of months
       * before or after start_date.
       * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
       *
       * Excel Function:
       *        EOMONTH(dateValue,adjustmentMonths)
       *
       * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
       *                                        PHP DateTime object, or a standard date string
       * @param int $adjustmentMonths The number of months before or after start_date.
       *                                        A positive value for months yields a future date;
       *                                        a negative value yields a past date.
       *
       * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
       *                        depending on the value of the ReturnDateType flag
       */
      public static function lastDay($dateValue, $adjustmentMonths)
      {
          try {
              $dateValue = Helpers::getDateValue($dateValue, false);
              $adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths);
          } catch (Exception $e) {
              return $e->getMessage();
          }
          $adjustmentMonths = floor($adjustmentMonths);
  
          // Execute function
          $PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths + 1);
          $adjustDays = (int) $PHPDateObject->format('d');
          $adjustDaysString = '-' . $adjustDays . ' days';
          $PHPDateObject->modify($adjustDaysString);
  
          return Helpers::returnIn3FormatsObject($PHPDateObject);
      }
  }