Skip to content

Commit 29e2ddf

Browse files
committed
fix: correct argument extraction order in FormatDateTime and enhance class name parsing in CallConstructor
1 parent a76ca06 commit 29e2ddf

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/execution_tree/BytecodeCommands.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,8 @@ std::expected<ExecutionResult, std::runtime_error> CallConstructor(PassedExecuti
12011201
if (first_underscore != std::string::npos && second_underscore != std::string::npos &&
12021202
second_underscore > first_underscore + 1) {
12031203
class_name = constructor_name.substr(first_underscore + 1, second_underscore - first_underscore - 1);
1204+
} else if (first_underscore != std::string::npos) {
1205+
class_name = constructor_name.substr(first_underscore + 1);
12041206
} else {
12051207
class_name = constructor_name;
12061208
}
@@ -1575,15 +1577,15 @@ std::expected<ExecutionResult, std::runtime_error> NanoTime(PassedExecutionData&
15751577
}
15761578

15771579
std::expected<ExecutionResult, std::runtime_error> FormatDateTime(PassedExecutionData& data) {
1578-
auto arguments = TryExtractTwoArguments<void*, int64_t>(data, "FormatDateTime");
1580+
auto arguments = TryExtractTwoArguments<int64_t, void*>(data, "FormatDateTime");
15791581

15801582
if (!arguments) {
15811583
return std::unexpected(arguments.error());
15821584
}
15831585

1584-
auto timestamp_var = arguments.value().second;
1586+
auto timestamp_var = arguments.value().first;
15851587

1586-
void* string_obj1 = arguments.value().first;
1588+
void* string_obj1 = arguments.value().second;
15871589
auto* format_str_ptr = runtime::GetDataPointer<std::string>(string_obj1);
15881590

15891591
try {

tests/bytecode_commands_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ TEST_F(BuiltinTestSuite, TimeCommands) {
10531053
constexpr int64_t kSleepMs = 1;
10541054
constexpr int64_t kEpochSeconds = 0;
10551055
constexpr std::string_view kYearFormat = "%Y";
1056+
constexpr std::string_view kFormatString = "%Y-%m-%d %H:%M:%S.%f";
10561057
constexpr std::string_view kDateFormat = "%Y-%m-%d";
10571058
constexpr std::string_view kEpochDate = "1970-01-01";
10581059
constexpr int64_t kPositiveThreshold = 0;
@@ -1085,9 +1086,9 @@ TEST_F(BuiltinTestSuite, TimeCommands) {
10851086
auto nano_val = PopInt();
10861087
EXPECT_GT(nano_val, kPositiveThreshold);
10871088

1088-
auto format_str = MakeString(std::string{kYearFormat});
1089-
PushInt(kEpochSeconds);
1089+
auto format_str = MakeString(std::string{kFormatString});
10901090
PushObject(format_str);
1091+
PushInt(second);
10911092
auto format_cmd = MakeSimple("FormatDateTime");
10921093
ASSERT_TRUE(format_cmd);
10931094
EXPECT_TRUE(format_cmd->Execute(data_).has_value());

0 commit comments

Comments
 (0)