Exemplo n.º 1
0
 static function getWeek($this1)
 {
     $week = Std::int((Std::int(($this1 - 62135596800.0 - datetime__DateTime_DateTime_Impl_::yearStart($this1)) / 86400) + 1 - datetime__DateTime_DateTime_Impl_::getWeekDay($this1, true) + 10) / 7);
     $year = datetime__DateTime_DateTime_Impl_::getYear($this1);
     if ($week < 1) {
         return datetime__DateTime_DateTime_Impl_::weeksInYear($year - 1);
     } else {
         if ($week > 52 && $week > datetime__DateTime_DateTime_Impl_::weeksInYear($year)) {
             return 1;
         } else {
             return $week;
         }
     }
 }
Exemplo n.º 2
0
 static function snapWeek($dt, $direction, $required)
 {
     $current = datetime__DateTime_DateTime_Impl_::getWeekDay($dt, null);
     $days = Math::ffloor(($dt - 62135596800.0) / 86400);
     switch ($direction) {
         case -1:
             $diff = null;
             if ($current >= $required) {
                 $diff = $current - $required;
             } else {
                 $diff = $current + 7 - $required;
             }
             return ($days - $diff) * 86400;
             break;
         case 1:
             $diff1 = null;
             if ($required > $current) {
                 $diff1 = $required - $current;
             } else {
                 $diff1 = $required + 7 - $current;
             }
             return ($days + $diff1) * 86400;
             break;
         case 0:
             $diff2 = null;
             if ($current >= $required) {
                 $diff2 = $current - $required;
             } else {
                 $diff2 = $current + 7 - $required;
             }
             $previous = ($days - $diff2) * 86400;
             $diff3 = null;
             if ($required > $current) {
                 $diff3 = $required - $current;
             } else {
                 $diff3 = $required + 7 - $current;
             }
             $next = ($days + $diff3) * 86400;
             if ($next - ($dt - 62135596800.0) > $dt - 62135596800.0 - $previous) {
                 return $previous;
             } else {
                 return $next;
             }
             break;
     }
 }
Exemplo 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;
 }