Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
1ea6881
stash
Shamzik Nov 13, 2025
de28cdc
stash
Shamzik Nov 13, 2025
cf33fba
stash
Shamzik Dec 10, 2025
bb4c735
stash
Shamzik Dec 10, 2025
d9fb062
fixes
Shamzik Dec 10, 2025
0c3dd19
datetime methods
Shamzik Dec 10, 2025
fa32f61
kphp::memory::libc_alloc_guard
Shamzik Dec 11, 2025
a6960b9
some tests
Shamzik Dec 11, 2025
bdecead
fixes
Shamzik Dec 11, 2025
f7ed08c
format
Shamzik Dec 11, 2025
4619bdc
get_last_errors
Shamzik Dec 11, 2025
b7f9d61
error messages
Shamzik Dec 11, 2025
28f92b2
test 12_create_interval.php
Shamzik Dec 11, 2025
1f4aaf2
remove extra ';'
Shamzik Dec 11, 2025
7cf3dc6
auto -> int32_t
Shamzik Dec 12, 2025
4bf55ff
fixes
Shamzik Dec 12, 2025
b50703e
implement setISODate method
Shamzik Dec 12, 2025
b60ffe9
implement sub methods
Shamzik Dec 12, 2025
22b8dd8
implement getOffset methods
Shamzik Dec 15, 2025
dc5c81e
construct -> parse
Shamzik Dec 25, 2025
f4c71eb
use destructor{}
Shamzik Dec 25, 2025
f4f6d29
move NOW_STR into time state
Shamzik Jan 14, 2026
d5cba95
remove include
Shamzik Jan 14, 2026
f69ff84
use type wrappers
Shamzik Jan 14, 2026
a4fdf9c
fix parse_interval
Shamzik Jan 14, 2026
903bcb7
refactoring
Shamzik Jan 16, 2026
bca5cc6
destructors
Shamzik Jan 16, 2026
722803d
revert string_decl
Shamzik Jan 19, 2026
1ae6379
move string_back_insert_iterator into separated header
Shamzik Jan 19, 2026
b72569d
fixes
Shamzik Jan 19, 2026
063c78d
move NOW_ into TimeImageState
Shamzik Jan 19, 2026
5ce4529
move destructors into details namespace
Shamzik Jan 19, 2026
01ec2fc
remove `_t` suffix
Shamzik Jan 19, 2026
16f47e5
fix
Shamzik Jan 19, 2026
bcab4b3
rename
Shamzik Jan 19, 2026
4c0d07d
fixes
Shamzik Jan 19, 2026
5ab3b67
std::string_view
Shamzik Jan 19, 2026
3e21836
make tzinfo wrapper
Shamzik Jan 20, 2026
3b4ad77
lambdas & includes
Shamzik Jan 21, 2026
40671af
remove const
Shamzik Jan 21, 2026
69bf18e
fix fill_holes_with_now_info
Shamzik Jan 21, 2026
b96d7f2
std::size_t -> size_t
Shamzik Jan 21, 2026
42e7b8c
optimize libc_alloc_guard
Shamzik Jan 21, 2026
ef144b3
fix weekYearSet
Shamzik Jan 21, 2026
e7772b4
swap -> move
Shamzik Jan 21, 2026
58ea8ed
Copyright (c) 2026 LLC «V Kontakte»
Shamzik Jan 21, 2026
d99e4cb
rename files
Shamzik Jan 21, 2026
bdaa10f
move some functions into headers
Shamzik Jan 21, 2026
b5467df
get_timezone_info
Shamzik Jan 21, 2026
4f63cce
remove _sv suffixes
Shamzik Jan 21, 2026
f0efc5e
std::output_iterator<const char&>
Shamzik Jan 21, 2026
90cdede
revert put method
Shamzik Jan 21, 2026
80aae55
remove make method
Shamzik Jan 21, 2026
6420426
fixes
Shamzik Jan 21, 2026
79cb5b7
fixed formatted_* args
Shamzik Jan 21, 2026
081eb61
fixes
Shamzik Jan 21, 2026
097ea30
fix split commens
Shamzik Jan 21, 2026
42f2ef1
fix parse_interval
Shamzik Jan 22, 2026
bfbf8f9
move some timelib functions to header
Shamzik Jan 22, 2026
8c64b6b
full qualified names
Shamzik Jan 22, 2026
bc2e1e5
move chrono up
Shamzik Jan 22, 2026
a20610a
fix timelib_parse_tzfile usage
Shamzik Jan 22, 2026
e496a39
refactor timezone_cache initialization
Shamzik Jan 22, 2026
ca808f6
move TimeInstanceState::get() to local var
Shamzik Jan 22, 2026
64568d3
move small date-time functions into headers
Shamzik Jan 22, 2026
e9c7f6e
includes
Shamzik Jan 22, 2026
840d90d
move common timelib functions into runtime-common
Shamzik Jan 27, 2026
29c2fd6
format
Shamzik Jan 27, 2026
7303222
remove iterator.h
Shamzik Jan 27, 2026
7e49066
fixes
Shamzik Jan 29, 2026
2b89c3b
fix timelib.cmake
Shamzik Jan 29, 2026
26deb64
fixes
Shamzik Jan 29, 2026
8d7ef0f
common define for runtimes
Shamzik Jan 29, 2026
4a4317b
2026
Shamzik Jan 29, 2026
e37820f
fix gen_error_msg
Shamzik Jan 29, 2026
2bec904
undo template files
Shamzik Jan 29, 2026
c4929b0
remove type aliases
Shamzik Jan 29, 2026
958bc6e
move `sign` functions up
Shamzik Jan 29, 2026
cd17d65
improve string::append
Shamzik Jan 29, 2026
1bf3373
cc
Shamzik Jan 29, 2026
b472cdb
fix checkdate
Shamzik Jan 30, 2026
d370b56
fix includes
Shamzik Jan 30, 2026
c658646
link runtime-light to timelib
Shamzik Jan 30, 2026
92b7f45
write diff as bytes
Shamzik Jan 30, 2026
7147fd8
revert compiler-settings.cpp format
Shamzik Jan 30, 2026
63b990e
remove static_buf alias
Shamzik Jan 30, 2026
47fcb5d
use holders as possible
Shamzik Jan 30, 2026
22fcc11
make default methods of timezone_cache
Shamzik Jan 30, 2026
6f896f4
move string constants of get_last_errors into image state
Shamzik Jan 30, 2026
867cdd6
#include <cstring>
Shamzik Jan 30, 2026
1d2db98
move get_time_interval to header
Shamzik Jan 30, 2026
fa2c595
parse_time -> kphp::timelib::parse_time
Shamzik Jan 30, 2026
62ecfa8
add warning in timezone_cache init
Shamzik Jan 30, 2026
b719fd4
fix ExtraRefCnt::for_global_const
Shamzik Jan 30, 2026
183e0ec
auto -> const auto*
Shamzik Jan 30, 2026
7b42135
uppercase static constexpr
Shamzik Jan 30, 2026
3555039
add timezone to DateTimeZone
Shamzik Feb 1, 2026
0e0d278
use std::strlen
Shamzik Feb 1, 2026
08eff85
move f$DateInterval$$__construct to cpp file
Shamzik Feb 1, 2026
f0203a4
use std::optional for get_last_errors
Shamzik Feb 2, 2026
7d643f5
string optimizations
Shamzik Feb 2, 2026
d6ece61
fix appending char
Shamzik Feb 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ include(${THIRD_PARTY_DIR}/re2-cmake/re2.cmake)
include(${THIRD_PARTY_DIR}/yaml-cpp-cmake/yaml-cpp.cmake)
include(${THIRD_PARTY_DIR}/uber-h3-cmake/uber-h3.cmake)

# Timelib shoud use manualy specified allocations routines name prefix
if(COMPILE_RUNTIME_LIGHT)
set(TIMELIB_ALLOC_FUNC_PREFIX timelib_)
else()
set(TIMELIB_ALLOC_FUNC_PREFIX)
endif()
include(${THIRD_PARTY_DIR}/timelib-cmake/timelib.cmake)

# TODO: use FetchContent_Declare instead of include_directories
include_directories(.)
include_directories(${INCLUDE_DIR})
Expand Down
88 changes: 26 additions & 62 deletions builtin-functions/kphp-light/stdlib/time-functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,19 @@ function set_timer(int $timeout, callable():void $callback) ::: void;

function checkdate ($month ::: int, $day ::: int, $year ::: int) ::: bool;

// ===== UNSUPPORTED =====

/** @kphp-generate-stub-class */
class DateInterval {
/** @kphp-extern-func-info can_throw stub generation-required */
/** @kphp-extern-func-info can_throw */
public function __construct(string $duration);
/** @kphp-extern-func-info stub generation-required */
public static function createFromDateString(string $datetime): ?DateInterval;
/** @kphp-extern-func-info stub generation-required */
public function format(string $format): string;
}

/** @kphp-generate-stub-class */
class DateTimeZone {
/** @kphp-extern-func-info can_throw stub generation-required */
/** @kphp-extern-func-info can_throw */
public function __construct(string $timezone);
/** @kphp-extern-func-info stub generation-required */
public function getName(): string;
}

/** @kphp-generate-stub-class */
interface DateTimeInterface {
/* Constants */
const ATOM = "Y-m-d\TH:i:sP";
Expand Down Expand Up @@ -86,84 +78,56 @@ interface DateTimeInterface {
public function getTimestamp(): int;
}

/** @kphp-generate-stub-class */
class DateTime implements DateTimeInterface {
/** @kphp-extern-func-info can_throw stub generation-required */
class DateTimeImmutable implements DateTimeInterface {
/** @kphp-extern-func-info can_throw */
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null);
/** @kphp-extern-func-info stub generation-required */
public function add(DateInterval $interval): DateTime;
/** @kphp-extern-func-info stub generation-required */
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): ?DateTime;
/** @kphp-extern-func-info stub generation-required */
public static function createFromImmutable(DateTimeImmutable $object): DateTime;
/** @kphp-extern-func-info stub generation-required */
public function add(DateInterval $interval): DateTimeImmutable;
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): ?DateTimeImmutable;
public static function createFromMutable(DateTime $object): DateTimeImmutable;
public static function getLastErrors(): array|false;
/** @kphp-extern-func-info stub generation-required */
public function modify(string $modifier): ?DateTime;
/** @kphp-extern-func-info stub generation-required */
public function setDate(int $year, int $month, int $day): DateTime;
/** @kphp-extern-func-info stub generation-required */
public function setISODate(int $year, int $week, int $dayOfWeek = 1): DateTime;
/** @kphp-extern-func-info stub generation-required */
public function modify(string $modifier): ?DateTimeImmutable;
public function setDate(int $year, int $month, int $day): DateTimeImmutable;
public function setISODate(int $year, int $week, int $dayOfWeek = 1): DateTimeImmutable;
public function setTime(
int $hour,
int $minute,
int $second = 0,
int $microsecond = 0
): DateTime;
/** @kphp-extern-func-info stub generation-required */
public function setTimestamp(int $timestamp): DateTime;
/** @kphp-extern-func-info stub generation-required */
public function sub(DateInterval $interval): DateTime;
/** @kphp-extern-func-info stub generation-required */
): DateTimeImmutable;
public function setTimestamp(int $timestamp): DateTimeImmutable;
public function sub(DateInterval $interval): DateTimeImmutable;
public function diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval;
/** @kphp-extern-func-info stub generation-required */
public function format(string $format): string;
/** @kphp-extern-func-info stub generation-required */
public function getOffset(): int;
/** @kphp-extern-func-info stub generation-required */
public function getTimestamp(): int;
}

/** @kphp-generate-stub-class */
class DateTimeImmutable implements DateTimeInterface {
/** @kphp-extern-func-info can_throw stub generation-required */
class DateTime implements DateTimeInterface {
/** @kphp-extern-func-info can_throw */
public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null);
/** @kphp-extern-func-info stub generation-required */
public function add(DateInterval $interval): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): ?DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public static function createFromMutable(DateTime $object): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public function add(DateInterval $interval): DateTime;
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null): ?DateTime;
public static function createFromImmutable(DateTimeImmutable $object): DateTime;
public static function getLastErrors(): array|false;
/** @kphp-extern-func-info stub generation-required */
public function modify(string $modifier): ?DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public function setDate(int $year, int $month, int $day): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public function setISODate(int $year, int $week, int $dayOfWeek = 1): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public function modify(string $modifier): ?DateTime;
public function setDate(int $year, int $month, int $day): DateTime;
public function setISODate(int $year, int $week, int $dayOfWeek = 1): DateTime;
public function setTime(
int $hour,
int $minute,
int $second = 0,
int $microsecond = 0
): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public function setTimestamp(int $timestamp): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
public function sub(DateInterval $interval): DateTimeImmutable;
/** @kphp-extern-func-info stub generation-required */
): DateTime;
public function setTimestamp(int $timestamp): DateTime;
public function sub(DateInterval $interval): DateTime;
public function diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval;
/** @kphp-extern-func-info stub generation-required */
public function format(string $format): string;
/** @kphp-extern-func-info stub generation-required */
public function getOffset(): int;
/** @kphp-extern-func-info stub generation-required */
public function getTimestamp(): int;
}

// ===== UNSUPPORTED =====

define('DATE_ATOM', "Y-m-d\TH:i:sP");
define('DATE_COOKIE', "l, d-M-y H:i:s T");
define('DATE_ISO8601', "Y-m-d\TH:i:sO");
Expand Down
2 changes: 2 additions & 0 deletions compiler/compiler-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ void CompilerSettings::init() {
if (!dynamic_incremental_linkage.get() && mode.get() != "k2-lib") {
ss << " -fvisibility=hidden";
}
// Temporary solution. Required for allocator functions replacement in timelib
ss << " -DTIMELIB_ALLOC_FUNC_PREFIX=timelib_";
} else {
// default value is false
// when we build using full runtime, we should force to use runtime as static lib
Expand Down
5 changes: 5 additions & 0 deletions runtime-common/core/allocator/script-malloc-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ inline void* realloc(void* ptr, size_t new_size) noexcept {
return new_ptr;
}

inline char* strdup(const char* str1) noexcept {
auto* str2{static_cast<char*>(kphp::memory::script::alloc(std::strlen(str1) + 1))};
return std::strcpy(str2, str1);
}

} // namespace script

} // namespace memory
Expand Down
8 changes: 4 additions & 4 deletions runtime-common/runtime-common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ prepend(RUNTIME_COMMON_SRC ${RUNTIME_COMMON_DIR}/ "${RUNTIME_COMMON_SRC}")
vk_add_library_no_pic(runtime-common-no-pic OBJECT ${RUNTIME_COMMON_SRC})
vk_add_library_pic(runtime-common-pic OBJECT ${RUNTIME_COMMON_SRC})

target_link_libraries(runtime-common-pic PUBLIC UBER_H3::pic::uber-h3)
add_dependencies(runtime-common-pic UBER_H3::pic::uber-h3)
target_link_libraries(runtime-common-pic PUBLIC UBER_H3::pic::uber-h3 KPHP_TIMELIB::pic::timelib)
add_dependencies(runtime-common-pic UBER_H3::pic::uber-h3 KPHP_TIMELIB::pic::timelib)

target_link_libraries(runtime-common-no-pic PUBLIC UBER_H3::no-pic::uber-h3)
add_dependencies(runtime-common-no-pic UBER_H3::no-pic::uber-h3)
target_link_libraries(runtime-common-no-pic PUBLIC UBER_H3::no-pic::uber-h3 KPHP_TIMELIB::no-pic::timelib)
add_dependencies(runtime-common-no-pic UBER_H3::no-pic::uber-h3 KPHP_TIMELIB::no-pic::timelib)

if(COMPILE_RUNTIME_LIGHT)
target_compile_options(runtime-common-pic PUBLIC -stdlib=libc++ ${RUNTIME_LIGHT_VISIBILITY})
Expand Down
3 changes: 2 additions & 1 deletion runtime-common/stdlib/stdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ prepend(STDLIB_STRING stdlib/string/ mbstring-functions.cpp
prepend(STDLIB_SYSTEM stdlib/system/ system-functions.cpp)
prepend(STDLIB_SERVER stdlib/server/ url-functions.cpp
net-functions.cpp)
prepend(STDLIB_TIME stdlib/time/ timelib-functions.cpp)
prepend(STDLIB_UBERH3 stdlib/uber-h3/ uber-h3-functions.cpp)
prepend(STDLIB_VKEXT stdlib/vkext/ string-processing.cpp
vkext-functions.cpp vkext-stats.cpp)
Expand All @@ -20,4 +21,4 @@ if(COMPILER_CLANG)
endif()

set(STDLIB_SRC ${STDLIB_ARRAY} ${STDLIB_CRYPTO} ${STDLIB_MATH} ${STDLIB_MSGPACK} ${STDLIB_SERIALIZATION}
${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_UBERH3} ${STDLIB_VKEXT})
${STDLIB_STRING} ${STDLIB_SYSTEM} ${STDLIB_SERVER} ${STDLIB_TIME} ${STDLIB_UBERH3} ${STDLIB_VKEXT})
34 changes: 34 additions & 0 deletions runtime-common/stdlib/time/timelib-constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2026 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#pragma once

#include <array>

namespace kphp::timelib {

namespace timezones {

inline constexpr const char* MOSCOW = "Europe/Moscow";
Comment thread
PetrShumilov marked this conversation as resolved.
inline constexpr const char* GMT3 = "Etc/GMT-3";
inline constexpr const char* GMT4 = "Etc/GMT-4";

} // namespace timezones

namespace months {

constexpr inline std::array<const char*, 12> FULL_NAMES = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
constexpr inline std::array<const char*, 12> SHORT_NAMES = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

} // namespace months

namespace days {

constexpr inline std::array<const char*, 7> FULL_NAMES = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
constexpr inline std::array<const char*, 7> SHORT_NAMES = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

} // namespace days

} // namespace kphp::timelib
Loading
Loading