Skip to content

Commit 34e4b0d

Browse files
committed
Locale fix, use local time format on welcome panel
1 parent 228271d commit 34e4b0d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Source/Components/WelcomePanel.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class WelcomePanel : public Component
1414
, public NVGComponent
1515
, public AsyncUpdater
1616
{
17-
18-
1917
class ContentComponent : public Component
2018
{
2119
WelcomePanel& panel;
@@ -585,6 +583,24 @@ class WelcomePanel : public Component
585583

586584
triggerAsyncUpdate();
587585
}
586+
587+
String getSystemLocalTime(uint64 timestamp) {
588+
StackArray<char, 100> buffer;
589+
std::time_t now = static_cast<std::time_t>(timestamp / 1000);
590+
std::tm* localTime = std::localtime(&now);
591+
592+
// Format the time using the current locale
593+
std::strftime(buffer.data(), buffer.size(), "%X", localTime);
594+
595+
auto result = String::fromUTF8(buffer.data());
596+
597+
// Remove seconds from system time format
598+
auto secondsStart = result.lastIndexOfChar(':');
599+
auto secondsEnd = result.indexOfChar(secondsStart, ' ');
600+
if(secondsEnd < 0) secondsEnd = result.length();
601+
602+
return result.substring(0, secondsStart) + result.substring(secondsEnd);
603+
}
588604

589605
void handleAsyncUpdate() override
590606
{
@@ -632,7 +648,8 @@ class WelcomePanel : public Component
632648
}
633649
}
634650

635-
auto openTime = Time(static_cast<int64>(subTree.getProperty("Time")));
651+
auto openTimestamp = static_cast<int64>(subTree.getProperty("Time"));
652+
auto openTime = Time(openTimestamp);
636653
auto diff = Time::getCurrentTime() - openTime;
637654
String date;
638655
if (diff.inDays() == 0)
@@ -641,7 +658,8 @@ class WelcomePanel : public Component
641658
date = "Yesterday";
642659
else
643660
date = openTime.toString(true, false);
644-
String time = openTime.toString(false, true, false, true);
661+
662+
String time = getSystemLocalTime(openTimestamp);
645663
String timeDescription = date + ", " + time;
646664

647665
auto* tile = recentlyOpenedTiles.add(new WelcomePanelTile(*this, patchFile.getFileNameWithoutExtension(), timeDescription, silhoutteSvg, snapshotColour, 1.0f, favourited, thumbImage));

Source/PluginProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ PluginProcessor::PluginProcessor()
9191
, hostInfoUpdater(this)
9292
{
9393
// Make sure to use dots for decimal numbers, pd requires that
94-
std::setlocale(LC_ALL, "C");
94+
std::setlocale(LC_NUMERIC, "C");
9595

9696
{
9797
MessageManagerLock const mmLock; // Do we need this? Isn't this already on the messageManager?

0 commit comments

Comments
 (0)