public function getYears()
 {
     if ($this->years < 0) {
         $this->years = datetime__DateTime_DateTime_Impl_::getYear($this->end) - datetime__DateTime_DateTime_Impl_::getYear($this->begin);
         $m1 = null;
         $this1 = $this->begin;
         $days = Std::int(($this1 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this1)) / 86400) + 1;
         $m1 = datetime_utils_DateTimeMonthUtils::getMonth($days, datetime__DateTime_DateTime_Impl_::isLeapYear($this1));
         $m2 = null;
         $this2 = $this->end;
         $days1 = Std::int(($this2 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this2)) / 86400) + 1;
         $m2 = datetime_utils_DateTimeMonthUtils::getMonth($days1, datetime__DateTime_DateTime_Impl_::isLeapYear($this2));
         if ($m2 < $m1) {
             $this->years--;
         } else {
             if ($m1 === $m2) {
                 $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->years--;
                 } 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->years--;
                         } else {
                             if ($h2 === $h1) {
                                 $m11 = null;
                                 $this7 = $this->begin;
                                 $m11 = Std::int(($this7 - Math::ffloor($this7 / 3600) * 3600) / 60);
                                 $m21 = null;
                                 $this8 = $this->end;
                                 $m21 = Std::int(($this8 - Math::ffloor($this8 / 3600) * 3600) / 60);
                                 if ($m21 < $m11) {
                                     $this->years--;
                                 } else {
                                     if ($m21 === $m11 && datetime_cores_DateTimeIntervalCore_0($this, $d1, $d2, $h1, $h2, $m1, $m11, $m2, $m21) < datetime_cores_DateTimeIntervalCore_1($this, $d1, $d2, $h1, $h2, $m1, $m11, $m2, $m21)) {
                                         $this->years--;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this->years;
 }
Esempio n. 2
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. 3
0
 static function strftime($dt, $format)
 {
     $prevPos = 0;
     $pos = _hx_index_of($format, "%", null);
     $str = "";
     while ($pos >= 0) {
         $str .= _hx_string_or_null(_hx_substring($format, $prevPos, $pos));
         $pos++;
         $_g = ord(substr($format, $pos, 1));
         switch ($_g) {
             case 100:
                 $s = null;
                 $s = _hx_string_rec(datetime_utils_DateTimeUtils_5($_g, $dt, $format, $pos, $prevPos, $s, $str), "") . "";
                 if (strlen("0") === 0 || strlen($s) >= 2) {
                     $str .= _hx_string_or_null($s);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s, Math::ceil((2 - strlen($s)) / strlen("0")) * strlen("0") + strlen($s), "0", STR_PAD_LEFT));
                 }
                 break;
             case 101:
                 $s1 = null;
                 $s1 = _hx_string_rec(datetime_utils_DateTimeUtils_6($_g, $dt, $format, $pos, $prevPos, $s1, $str), "") . "";
                 if (strlen(" ") === 0 || strlen($s1) >= 2) {
                     $str .= _hx_string_or_null($s1);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s1, Math::ceil((2 - strlen($s1)) / strlen(" ")) * strlen(" ") + strlen($s1), " ", STR_PAD_LEFT));
                 }
                 break;
             case 106:
                 $day = Std::int(($dt - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($dt)) / 86400) + 1;
                 $s2 = "" . _hx_string_rec($day, "");
                 if (strlen("0") === 0 || strlen($s2) >= 3) {
                     $str .= _hx_string_or_null($s2);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s2, Math::ceil((3 - strlen($s2)) / strlen("0")) * strlen("0") + strlen($s2), "0", STR_PAD_LEFT));
                 }
                 break;
             case 117:
                 $str .= _hx_string_rec(datetime__DateTime_DateTime_Impl_::getWeekDay($dt, true), "") . "";
                 break;
             case 119:
                 $str .= _hx_string_rec(datetime__DateTime_DateTime_Impl_::getWeekDay($dt, null), "") . "";
                 break;
             case 109:
                 $s3 = null;
                 $s3 = _hx_string_rec(datetime_utils_DateTimeUtils_7($_g, $dt, $format, $pos, $prevPos, $s3, $str), "") . "";
                 if (strlen("0") === 0 || strlen($s3) >= 2) {
                     $str .= _hx_string_or_null($s3);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s3, Math::ceil((2 - strlen($s3)) / strlen("0")) * strlen("0") + strlen($s3), "0", STR_PAD_LEFT));
                 }
                 break;
             case 67:
                 $s4 = _hx_string_rec(Std::int(datetime__DateTime_DateTime_Impl_::getYear($dt) / 100), "") . "";
                 if (strlen("0") === 0 || strlen($s4) >= 2) {
                     $str .= _hx_string_or_null($s4);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s4, Math::ceil((2 - strlen($s4)) / strlen("0")) * strlen("0") + strlen($s4), "0", STR_PAD_LEFT));
                 }
                 break;
             case 121:
                 $s5 = _hx_substr(_hx_string_rec(datetime__DateTime_DateTime_Impl_::getYear($dt), "") . "", -2, null);
                 if (strlen("0") === 0 || strlen($s5) >= 2) {
                     $str .= _hx_string_or_null($s5);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s5, Math::ceil((2 - strlen($s5)) / strlen("0")) * strlen("0") + strlen($s5), "0", STR_PAD_LEFT));
                 }
                 break;
             case 89:
                 $str .= _hx_string_rec(datetime__DateTime_DateTime_Impl_::getYear($dt), "") . "";
                 break;
             case 86:
                 $s6 = _hx_string_rec(datetime__DateTime_DateTime_Impl_::getWeek($dt), "") . "";
                 if (strlen("0") === 0 || strlen($s6) >= 2) {
                     $str .= _hx_string_or_null($s6);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s6, Math::ceil((2 - strlen($s6)) / strlen("0")) * strlen("0") + strlen($s6), "0", STR_PAD_LEFT));
                 }
                 break;
             case 72:
                 $s7 = _hx_string_rec(Std::int(($dt - Math::ffloor($dt / 86400) * 86400) / 3600), "") . "";
                 if (strlen("0") === 0 || strlen($s7) >= 2) {
                     $str .= _hx_string_or_null($s7);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s7, Math::ceil((2 - strlen($s7)) / strlen("0")) * strlen("0") + strlen($s7), "0", STR_PAD_LEFT));
                 }
                 break;
             case 107:
                 $s8 = _hx_string_rec(Std::int(($dt - Math::ffloor($dt / 86400) * 86400) / 3600), "") . "";
                 if (strlen(" ") === 0 || strlen($s8) >= 2) {
                     $str .= _hx_string_or_null($s8);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s8, Math::ceil((2 - strlen($s8)) / strlen(" ")) * strlen(" ") + strlen($s8), " ", STR_PAD_LEFT));
                 }
                 break;
             case 73:
                 $s9 = _hx_string_rec(datetime__DateTime_DateTime_Impl_::getHour12($dt), "") . "";
                 if (strlen("0") === 0 || strlen($s9) >= 2) {
                     $str .= _hx_string_or_null($s9);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s9, Math::ceil((2 - strlen($s9)) / strlen("0")) * strlen("0") + strlen($s9), "0", STR_PAD_LEFT));
                 }
                 break;
             case 108:
                 $s10 = _hx_string_rec(datetime__DateTime_DateTime_Impl_::getHour12($dt), "") . "";
                 if (strlen(" ") === 0 || strlen($s10) >= 2) {
                     $str .= _hx_string_or_null($s10);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s10, Math::ceil((2 - strlen($s10)) / strlen(" ")) * strlen(" ") + strlen($s10), " ", STR_PAD_LEFT));
                 }
                 break;
             case 77:
                 $s11 = _hx_string_rec(Std::int(($dt - Math::ffloor($dt / 3600) * 3600) / 60), "") . "";
                 if (strlen("0") === 0 || strlen($s11) >= 2) {
                     $str .= _hx_string_or_null($s11);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s11, Math::ceil((2 - strlen($s11)) / strlen("0")) * strlen("0") + strlen($s11), "0", STR_PAD_LEFT));
                 }
                 break;
             case 112:
                 if (Std::int(($dt - Math::ffloor($dt / 86400) * 86400) / 3600) < 12) {
                     $str .= "AM";
                 } else {
                     $str .= "PM";
                 }
                 break;
             case 80:
                 if (Std::int(($dt - Math::ffloor($dt / 86400) * 86400) / 3600) < 12) {
                     $str .= "am";
                 } else {
                     $str .= "pm";
                 }
                 break;
             case 114:
                 $str .= _hx_string_or_null(datetime_utils_DateTimeUtils_8($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_9($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_10($_g, $dt, $format, $pos, $prevPos, $str));
                 break;
             case 82:
                 $str .= _hx_string_or_null(datetime_utils_DateTimeUtils_11($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_12($_g, $dt, $format, $pos, $prevPos, $str));
                 break;
             case 83:
                 $s17 = _hx_string_rec(Std::int($dt - Math::ffloor($dt / 60) * 60), "") . "";
                 if (strlen("0") === 0 || strlen($s17) >= 2) {
                     $str .= _hx_string_or_null($s17);
                 } else {
                     $str .= _hx_string_or_null(str_pad($s17, Math::ceil((2 - strlen($s17)) / strlen("0")) * strlen("0") + strlen($s17), "0", STR_PAD_LEFT));
                 }
                 break;
             case 84:
                 $str .= _hx_string_or_null(datetime_utils_DateTimeUtils_13($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_14($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_15($_g, $dt, $format, $pos, $prevPos, $str));
                 break;
             case 68:
                 $str .= _hx_string_or_null(datetime_utils_DateTimeUtils_16($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_17($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_18($_g, $dt, $format, $pos, $prevPos, $str));
                 break;
             case 70:
                 $str .= _hx_string_rec(datetime__DateTime_DateTime_Impl_::getYear($dt), "") . "-" . _hx_string_or_null(datetime_utils_DateTimeUtils_19($_g, $dt, $format, $pos, $prevPos, $str)) . _hx_string_or_null(datetime_utils_DateTimeUtils_20($_g, $dt, $format, $pos, $prevPos, $str));
                 break;
             case 115:
                 $str .= _hx_string_rec($dt - 62135596800.0, "") . "";
                 break;
             case 37:
                 $str .= "%";
                 break;
         }
         unset($_g);
         $prevPos = $pos + 1;
         $pos = _hx_index_of($format, "%", $pos + 1);
     }
     $str .= _hx_string_or_null(_hx_substring($format, $prevPos, null));
     return $str;
 }