Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date str bignums #162

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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