Skip to content

Conversation

@Shamzik
Copy link
Contributor

@Shamzik Shamzik commented Dec 8, 2025

This first part of implementing Date/Time classes. Here implemented:

  • DateInterval;
  • DateTimeZone;
  • DateTimeImmutable;
  • DateTime.

@Shamzik Shamzik marked this pull request as ready for review December 10, 2025 10:26
@Shamzik Shamzik self-assigned this Dec 10, 2025
@Shamzik Shamzik added the k2 k2 related label Dec 10, 2025
@Shamzik Shamzik added this to the next milestone Dec 10, 2025
@Shamzik Shamzik changed the title [k2] add Date/Time classes (except DateTime) to light runtime [k2] add Date/Time classes to light runtime Dec 10, 2025
class string {
public:
using size_type = string_size_type;
using value_type = char;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added to be able to use std::back_inserter

@Shamzik Shamzik requested a review from apolyakov December 12, 2025 11:44
@DrDet DrDet modified the milestones: 14.12.2025, next Dec 12, 2025
Copy link
Contributor

@apolyakov apolyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed and noted some comments. Please, take into account that these comments should be applied to whole PR, not only the places where I left those comments

inline constexpr std::string_view BACKSLASH_ = "\\";
inline constexpr std::string_view QUOTE_ = "\"";
inline constexpr std::string_view NEWLINE_ = "\n";
inline constexpr std::string_view NOW_ = "now";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the context for strings part of standard library. Let's move this to one specific for time functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


#include "kphp/timelib/timelib.h"

#include "common/containers/final_action.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove all the unused includes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


using error_container_t = std::unique_ptr<timelib_error_container, destructor>;
using rel_time_t = std::unique_ptr<timelib_rel_time, destructor>;
using time_t = std::unique_ptr<timelib_time, destructor>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we have a mix of raw timelib types and our own wrappers in the API. It doesn't look like a good solution.

Also, please refactor exisiting code that uses raw types in case you add wrappers. Mixing types is always bad

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed except clone function


time_offset_t construct_time_offset(timelib_time& t) noexcept;

std::pair<time_t, error_container_t> parse_time(std::string_view time_sv) noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for us to have both valid time_t and error_container_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error_container_t is always non-null here. time_t is null in case of an error.


std::pair<time_t, error_container_t> parse_time(std::string_view time_sv) noexcept;
std::pair<time_t, error_container_t> parse_time(std::string_view time_sv, const char* format) noexcept;
std::expected<rel_time_t, std::format_string<const char*>> parse_interval(std::string_view format) noexcept;
Copy link
Contributor

@apolyakov apolyakov Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it's not the best idea to return error format string instead of an error itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixed


time_t add(timelib_time& t, timelib_rel_time& interval) noexcept;

rel_time_t clone(timelib_rel_time& rt) noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to just create a wrapper class? As far as I see, it might be worth it since you already have clone and destruct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored the header to make it easier to read. This library isn't very friendly to creating wrapper classes around it.


void set_timestamp(timelib_time& t, int64_t timestamp) noexcept;

std::string_view english_suffix(timelib_sll number) noexcept;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it really be a part of public kphp::timelib API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hided in details namespace

@Shamzik Shamzik requested a review from apolyakov January 16, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

k2 k2 related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants