-
Notifications
You must be signed in to change notification settings - Fork 110
[k2] add Date/Time classes to light runtime #1481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Shamzik
wants to merge
75
commits into
master
Choose a base branch
from
kshamazov/datetime
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,000
−822
Open
Changes from 21 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
91759b3
stash
Shamzik c35762c
stash
Shamzik 01f2476
stash
Shamzik b29deda
stash
Shamzik 6c3b902
fixes
Shamzik d9da675
datetime methods
Shamzik 9825b2b
kphp::memory::libc_alloc_guard
Shamzik 7161d44
some tests
Shamzik 283b554
fixes
Shamzik a7ac9db
format
Shamzik 40b60bd
get_last_errors
Shamzik d5bb003
error messages
Shamzik 6273913
test 12_create_interval.php
Shamzik cc608cb
remove extra ';'
Shamzik 028e647
auto -> int32_t
Shamzik dc43023
fixes
Shamzik 5362352
implement setISODate method
Shamzik 9b7918d
implement sub methods
Shamzik a96050c
implement getOffset methods
Shamzik 39cfffc
construct -> parse
Shamzik befbf8d
use destructor{}
Shamzik b55795f
move NOW_STR into time state
Shamzik 9cc1a77
remove include
Shamzik 22fede1
use type wrappers
Shamzik c2e2dd4
fix parse_interval
Shamzik 18a490d
refactoring
Shamzik 589fd73
destructors
Shamzik 2a67c1e
revert string_decl
Shamzik 35b8674
move string_back_insert_iterator into separated header
Shamzik 580e3db
fixes
Shamzik 8b8e1cc
move NOW_ into TimeImageState
Shamzik af121e2
move destructors into details namespace
Shamzik 4cfcaf0
remove `_t` suffix
Shamzik 8cc3b61
fix
Shamzik 8bad775
rename
Shamzik eb0dc06
fixes
Shamzik 08d673b
std::string_view
Shamzik e8ff62c
make tzinfo wrapper
Shamzik 8afb7f3
lambdas & includes
Shamzik bfc6bc7
remove const
Shamzik a9f8712
fix fill_holes_with_now_info
Shamzik 073ec0c
std::size_t -> size_t
Shamzik 250dd49
optimize libc_alloc_guard
Shamzik e304ce6
fix weekYearSet
Shamzik 58e3422
swap -> move
Shamzik 575379d
Copyright (c) 2026 LLC «V Kontakte»
Shamzik 6d9b904
rename files
Shamzik e2d6d90
move some functions into headers
Shamzik 713c2b0
get_timezone_info
Shamzik 079a6a7
remove _sv suffixes
Shamzik 60fc83f
std::output_iterator<const char&>
Shamzik 158f904
revert put method
Shamzik ad0755f
remove make method
Shamzik 193f031
fixes
Shamzik 5056017
fixed formatted_* args
Shamzik 74bccbb
fixes
Shamzik b2d42e2
fix split commens
Shamzik ab5a00d
fix parse_interval
Shamzik b0fcb23
move some timelib functions to header
Shamzik ac16618
full qualified names
Shamzik 3154b71
move chrono up
Shamzik 66cfeb5
fix timelib_parse_tzfile usage
Shamzik 933f4bd
refactor timezone_cache initialization
Shamzik 1cd498e
move TimeInstanceState::get() to local var
Shamzik d449771
move small date-time functions into headers
Shamzik ea202ab
includes
Shamzik 934873e
move common timelib functions into runtime-common
Shamzik f71df10
format
Shamzik da6c9d3
remove iterator.h
Shamzik fbc06e0
fixes
Shamzik c14fcfd
fix timelib.cmake
Shamzik 332366e
fixes
Shamzik ba50508
common define for runtimes
Shamzik 07fc8df
2026
Shamzik 837ca6d
fix gen_error_msg
Shamzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Compiler for PHP (aka KPHP) | ||
| // Copyright (c) 2020 LLC «V Kontakte» | ||
| // Distributed under the GPL v3 License, see LICENSE.notice.txt | ||
|
|
||
| #include "runtime-light/stdlib/time/dateinterval.h" | ||
|
|
||
| #include <format> | ||
| #include <iterator> | ||
|
|
||
| #include "common/containers/final_action.h" | ||
| #include "runtime-common/core/allocator/script-allocator.h" | ||
| #include "runtime-common/core/runtime-core.h" | ||
| #include "runtime-light/stdlib/diagnostics/exception-functions.h" | ||
| #include "runtime-light/stdlib/diagnostics/logs.h" | ||
|
|
||
| class_instance<C$DateInterval> f$DateInterval$$__construct(const class_instance<C$DateInterval>& self, const string& duration) noexcept { | ||
| auto expected_rel_time{kphp::timelib::parse_interval({duration.c_str(), duration.size()})}; | ||
| if (!expected_rel_time.has_value()) [[unlikely]] { | ||
| string err_msg{"DateInterval::__construct(): "}; | ||
| format_to(std::back_inserter(err_msg), expected_rel_time.error(), duration.c_str()); | ||
| THROW_EXCEPTION(kphp::exception::make_throwable<C$Exception>(err_msg)); | ||
| return {}; | ||
| } | ||
| self->rel_time = std::move(*expected_rel_time); | ||
| return self; | ||
| } | ||
|
|
||
| class_instance<C$DateInterval> f$DateInterval$$createFromDateString(const string& datetime) noexcept { | ||
| auto [time, errors]{kphp::timelib::parse_time({datetime.c_str(), datetime.size()})}; | ||
| if (time == nullptr) [[unlikely]] { | ||
| kphp::log::warning("DateInterval::createFromDateString(): Unknown or bad format ({}) {}", datetime.c_str(), errors); | ||
| return {}; | ||
| } | ||
| class_instance<C$DateInterval> date_interval; | ||
apolyakov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| date_interval.alloc(); | ||
| date_interval->rel_time = kphp::timelib::clone(time->relative); | ||
| return date_interval; | ||
| } | ||
|
|
||
| string f$DateInterval$$format(const class_instance<C$DateInterval>& self, const string& format) noexcept { | ||
| string str; | ||
| kphp::timelib::format_to(std::back_inserter(str), {format.c_str(), format.size()}, *self->rel_time); | ||
| return str; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Compiler for PHP (aka KPHP) | ||
| // Copyright (c) 2022 LLC «V Kontakte» | ||
| // Distributed under the GPL v3 License, see LICENSE.notice.txt | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string_view> | ||
|
|
||
| #include "common/algorithms/hashes.h" | ||
| #include "runtime-common/core/class-instance/refcountable-php-classes.h" | ||
| #include "runtime-common/core/runtime-core.h" | ||
| #include "runtime-common/stdlib/visitors/dummy-visitor-methods.h" | ||
| #include "runtime-light/stdlib/time/timelib-functions.h" | ||
|
|
||
| struct C$DateInterval : public refcountable_polymorphic_php_classes_virt<>, private DummyVisitorMethods { | ||
| using DummyVisitorMethods::accept; | ||
|
|
||
| kphp::timelib::rel_time_t rel_time{nullptr}; | ||
|
|
||
| virtual const char* get_class() const noexcept { | ||
| return R"(DateInterval)"; | ||
| } | ||
|
|
||
| virtual int32_t get_hash() const noexcept { | ||
| std::string_view name_view{C$DateInterval::get_class()}; | ||
| return static_cast<int32_t>(vk::murmur_hash<uint32_t>(name_view.data(), name_view.size())); | ||
| } | ||
| }; | ||
|
|
||
| class_instance<C$DateInterval> f$DateInterval$$__construct(const class_instance<C$DateInterval>& self, const string& duration) noexcept; | ||
|
|
||
| class_instance<C$DateInterval> f$DateInterval$$createFromDateString(const string& datetime) noexcept; | ||
|
|
||
| string f$DateInterval$$format(const class_instance<C$DateInterval>& self, const string& format) noexcept; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.