Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 4 additions & 2 deletions core/libs/prx/libc/src/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ void addNumber(FormatBuffer& buffer, std::int64_t value, int modulus, const char
}

const char* tableName(int index, const char* const* names, const char* const* shortNames, int count) {
if (index < 0) return shortNames[0];
return index < count ? names[index] : "";
const auto field = static_cast<std::int32_t>(static_cast<std::uint32_t>(index) * 2u + (names == shortNames ? 0u : 1u));
if (field < 0) return shortNames[0];
if (field >= 2 * count) return "";
return field % 2 == 0 ? shortNames[field / 2] : names[field / 2];
}

int twoDigitYear(std::int64_t year) {
Expand Down
17 changes: 17 additions & 0 deletions core/libs/tests/GuestStrftime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ int main() {
Check(name, time, "%a|%A|%b|%B|%m|%u|%w", expected[value + 3]);
}

struct WrappedName {
int value;
const char* expected;
};
constexpr WrappedName wrapped[] = {
{-2147483647 - 1, "Sun|Sunday|Jan|January"}, {-1884104312, "|||"}, {-1073741825, "|||"}, {-1073741824, "Sun|Sun|Jan|Jan"},
{536870912, "|||"}, {1073741823, "|||"}, {1073741824, "Sun|Sun|Jan|Jan"}, {1526330116, "Sun|Sun|Jan|Jan"}, {2147483647, "Sun|Sun|Jan|Jan"},
};
for (const auto& item : wrapped) {
GuestTm time = base;
time.tm_wday = item.value;
time.tm_mon = item.value;
char name[32];
std::snprintf(name, sizeof(name), "wrapped index %d", item.value);
Check(name, time, "%a|%A|%b|%B", item.expected);
}

struct Field {
int value;
const char* expected;
Expand Down
Loading