Skip to content

Commit a012b8e

Browse files
committed
Fix deprecated CRT warnings on MSVC
1 parent 3a46e6e commit a012b8e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lib/source/pl/lib/std/time.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ namespace pl::lib::libstd::time {
6767
auto time = time_t(params[0].toUnsigned());
6868

6969
try {
70+
#ifdef _MSC_VER
71+
std::tm localTimeBuf{};
72+
if(localtime_s(&localTimeBuf, &time) != 0)
73+
return u128(0);
74+
auto localTime = &localTimeBuf;
75+
#else
7076
auto localTime = std::localtime(&time);
7177
if (localTime == nullptr) return u128(0);
78+
#endif // _MSC_VER
7279

7380
return { packTMValue(*localTime, runtime) };
7481
} catch (const fmt::format_error&) {
@@ -81,8 +88,15 @@ namespace pl::lib::libstd::time {
8188
auto time = time_t(params[0].toUnsigned());
8289

8390
try {
91+
#ifdef _MSC_VER
92+
std::tm gmTimeBuf{};
93+
if(gmtime_s(&gmTimeBuf, &time) != 0)
94+
return u128(0);
95+
auto gmTime = &gmTimeBuf;
96+
#else
8497
auto gmTime = std::gmtime(&time);
8598
if (gmTime == nullptr) return u128(0);
99+
#endif // _MSC_VER
86100

87101
return { packTMValue(*gmTime, runtime) };
88102
} catch (const fmt::format_error&) {

0 commit comments

Comments
 (0)