Skip to content

Commit

Permalink
Merge pull request #162 from marcgurevitx/fix-dateStr-bignums
Browse files Browse the repository at this point in the history
Fix date str bignums
  • Loading branch information
JoeStrout authored Jul 28, 2024
2 parents daabb9a + f4a13e0 commit 2ced9d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions MiniScript-cpp/src/DateTimeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

#if _WIN32 || _WIN64
struct tm *localtime_r( const time_t *timer, struct tm *buf ) {
*buf = *_localtime64(timer);
struct tm *newtime = _localtime64(timer);
if (newtime == nullptr) return nullptr;
*buf = *newtime;
return buf;
}
#endif
Expand All @@ -31,7 +33,8 @@ static bool Match(const String s, size_t *posB, const String match) {

String FormatDate(time_t t, String formatSpec) {
tm dateTime;
localtime_r(&t, &dateTime);
struct tm *newtime = localtime_r(&t, &dateTime);
if (newtime == nullptr) return ""; // arg t too large

const int BUFSIZE = 128;
char buffer[BUFSIZE];
Expand Down
8 changes: 8 additions & 0 deletions MiniScript-cpp/tests/testDateTimeDateStr.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "qa"

testDateTimeDateStr = function
qa.assertEqual _dateStr(0), "2000-01-01 00:00:00"
qa.assertEqual _dateStr(1e20), ""
end function

if refEquals(locals, globals) then testDateTimeDateStr

0 comments on commit 2ced9d8

Please sign in to comment.