static function snapMonth($dt, $direction)
 {
     $month = null;
     $days = Std::int(($dt - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($dt)) / 86400) + 1;
     $month = datetime_utils_DateTimeMonthUtils::getMonth($days, datetime__DateTime_DateTime_Impl_::isLeapYear($dt));
     $isLeap = datetime__DateTime_DateTime_Impl_::isLeapYear($dt);
     switch ($direction) {
         case -1:
             return datetime__DateTime_DateTime_Impl_::yearStart($dt) + datetime_utils_DateTimeMonthUtils::toSeconds($month, $isLeap);
             break;
         case 1:
             return datetime__DateTime_DateTime_Impl_::yearStart($dt) + datetime_utils_DateTimeMonthUtils::toSeconds($month, $isLeap) + datetime_utils_DateTimeMonthUtils::days($month, $isLeap) * 86400;
             break;
         case 0:
             $previous = datetime__DateTime_DateTime_Impl_::yearStart($dt) + datetime_utils_DateTimeMonthUtils::toSeconds($month, $isLeap);
             $next = datetime__DateTime_DateTime_Impl_::yearStart($dt) + datetime_utils_DateTimeMonthUtils::toSeconds($month, $isLeap) + datetime_utils_DateTimeMonthUtils::days($month, $isLeap) * 86400;
             if ($next - ($dt - 62135596800.0) > $dt - 62135596800.0 - $previous) {
                 return $previous;
             } else {
                 return $next;
             }
             break;
     }
 }
 public function getMonths()
 {
     if ($this->months < 0) {
         $monthBegin = null;
         $this1 = $this->begin;
         $days = Std::int(($this1 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this1)) / 86400) + 1;
         $monthBegin = datetime_utils_DateTimeMonthUtils::getMonth($days, datetime__DateTime_DateTime_Impl_::isLeapYear($this1));
         $monthEnd = null;
         $this2 = $this->end;
         $days1 = Std::int(($this2 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this2)) / 86400) + 1;
         $monthEnd = datetime_utils_DateTimeMonthUtils::getMonth($days1, datetime__DateTime_DateTime_Impl_::isLeapYear($this2));
         if ($monthBegin <= $monthEnd) {
             $this->months = $monthEnd - $monthBegin;
         } else {
             $this->months = 12 - $monthBegin + $monthEnd;
         }
         $d1 = null;
         $this3 = $this->begin;
         $days2 = Std::int(($this3 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this3)) / 86400) + 1;
         $d1 = datetime_utils_DateTimeMonthUtils::getMonthDay($days2, datetime__DateTime_DateTime_Impl_::isLeapYear($this3));
         $d2 = null;
         $this4 = $this->end;
         $days3 = Std::int(($this4 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this4)) / 86400) + 1;
         $d2 = datetime_utils_DateTimeMonthUtils::getMonthDay($days3, datetime__DateTime_DateTime_Impl_::isLeapYear($this4));
         if ($d2 < $d1) {
             $this->months--;
         } else {
             if ($d1 === $d2) {
                 $h1 = null;
                 $this5 = $this->begin;
                 $h1 = Std::int(($this5 - Math::ffloor($this5 / 86400) * 86400) / 3600);
                 $h2 = null;
                 $this6 = $this->end;
                 $h2 = Std::int(($this6 - Math::ffloor($this6 / 86400) * 86400) / 3600);
                 if ($h2 < $h1) {
                     $this->months--;
                 } else {
                     if ($h2 === $h1) {
                         $m1 = null;
                         $this7 = $this->begin;
                         $m1 = Std::int(($this7 - Math::ffloor($this7 / 3600) * 3600) / 60);
                         $m2 = null;
                         $this8 = $this->end;
                         $m2 = Std::int(($this8 - Math::ffloor($this8 / 3600) * 3600) / 60);
                         if ($m2 < $m1) {
                             $this->months--;
                         } else {
                             if ($m2 === $m1 && datetime_cores_DateTimeIntervalCore_2($this, $d1, $d2, $h1, $h2, $m1, $m2, $monthBegin, $monthEnd) < datetime_cores_DateTimeIntervalCore_3($this, $d1, $d2, $h1, $h2, $m1, $m2, $monthBegin, $monthEnd)) {
                                 $this->months--;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this->months;
 }
Esempio n. 3
0
 static function toString($this1)
 {
     $Y = datetime__DateTime_DateTime_Impl_::getYear($this1);
     $M = null;
     $days = Std::int(($this1 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this1)) / 86400) + 1;
     $M = datetime_utils_DateTimeMonthUtils::getMonth($days, datetime__DateTime_DateTime_Impl_::isLeapYear($this1));
     $D = null;
     $days1 = Std::int(($this1 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this1)) / 86400) + 1;
     $D = datetime_utils_DateTimeMonthUtils::getMonthDay($days1, datetime__DateTime_DateTime_Impl_::isLeapYear($this1));
     $h = Std::int(($this1 - Math::ffloor($this1 / 86400) * 86400) / 3600);
     $m = Std::int(($this1 - Math::ffloor($this1 / 3600) * 3600) / 60);
     $s = Std::int($this1 - Math::ffloor($this1 / 60) * 60);
     return "" . _hx_string_rec($Y, "") . "-" . _hx_string_or_null(datetime__DateTime_DateTime_Impl__4($D, $M, $Y, $h, $m, $s, $this1)) . "-" . _hx_string_or_null(datetime__DateTime_DateTime_Impl__5($D, $M, $Y, $h, $m, $s, $this1)) . " " . _hx_string_or_null(datetime__DateTime_DateTime_Impl__6($D, $M, $Y, $h, $m, $s, $this1)) . ":" . _hx_string_or_null(datetime__DateTime_DateTime_Impl__7($D, $M, $Y, $h, $m, $s, $this1)) . ":" . _hx_string_or_null(datetime__DateTime_DateTime_Impl__8($D, $M, $Y, $h, $m, $s, $this1));
 }
Esempio n. 4
0
 static function getWeekDayNum($dt, $weekDay, $num)
 {
     $month = null;
     $days = Std::int(($dt - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($dt)) / 86400) + 1;
     $month = datetime_utils_DateTimeMonthUtils::getMonth($days, datetime__DateTime_DateTime_Impl_::isLeapYear($dt));
     if ($num > 0) {
         $start = null;
         $time = datetime__DateTime_DateTime_Impl_::monthStart($dt, $month) - 1;
         $start = $time + 62135596800.0;
         $first = datetime__DateTime_DateTime_Impl_::snap($start, datetime_DTSnap::Week(1, $weekDay));
         $this1 = null;
         $period = datetime_DTPeriod::Week($num - 1);
         $this1 = datetime__DateTime_DateTime_Impl_::add($first, $period);
         return $this1 - 62135596800.0;
     } else {
         if ($num < 0) {
             $start1 = null;
             $time1 = datetime__DateTime_DateTime_Impl_::monthStart($dt, $month + 1) - 1;
             $start1 = $time1 + 62135596800.0;
             $first1 = datetime__DateTime_DateTime_Impl_::snap($start1, datetime_DTSnap::Week(-1, $weekDay));
             $this2 = null;
             $period1 = datetime_DTPeriod::Week($num + 1);
             $this2 = datetime__DateTime_DateTime_Impl_::add($first1, $period1);
             return $this2 - 62135596800.0;
         } else {
             return $dt - 62135596800.0;
         }
     }
 }