diff --git a/CMakeLists.txt b/CMakeLists.txt index b3feb38..8148ac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ add_definitions( -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_UNCAUGHT_EXCEPTION_DEPRECATION_WARNING -DUSE_SYSTEM_TZ_DB=ON + -DONLY_C_LOCALE=1 ) set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/test/plugins) diff --git a/pawn.json b/pawn.json index 72e90d9..fdd338e 100644 --- a/pawn.json +++ b/pawn.json @@ -1,23 +1,33 @@ { - "user": "Southclaws", - "repo": "pawn-chrono", - "entry": "test.pwn", - "output": "test/gamemodes/test.amx", - "dependencies": ["Southclaws/samp-stdlib"], - "dev_dependencies": ["pawn-lang/YSI-Includes"], - "runtime": { - "plugins": ["Southclaws/pawn-chrono"] - }, - "resources": [ - { - "name": "chrono.so", - "archive": false, - "platform": "linux" - }, - { - "name": "chrono.dll", - "archive": false, - "platform": "windows" - } - ] -} + "user": "Southclaws", + "repo": "pawn-chrono", + "tag": "1.1.0", + "entry": "test.pwn", + "output": "test/gamemodes/test.amx", + "dependencies": [ + "Southclaws/samp-stdlib" + ], + "dev_dependencies": [ + "pawn-lang/YSI-Includes", + "oscar-broman/strlib" + ], + "runtime": { + "version": "0.3.7", + "mode": "server", + "plugins": [ + "Southclaws/pawn-chrono" + ], + "rcon_password": "password", + "port": 7777 + }, + "resources": [ + { + "name": "chrono.so", + "platform": "linux" + }, + { + "name": "chrono.dll", + "platform": "windows" + } + ] +} \ No newline at end of file diff --git a/src/natives.cpp b/src/natives.cpp index 1e8be7a..aa9388c 100644 --- a/src/natives.cpp +++ b/src/natives.cpp @@ -37,7 +37,14 @@ cell Natives::TimeParse(AMX* amx, cell* params) std::istringstream is(string); date::sys_seconds d; - date::from_stream(is, fmt.c_str(), d); + try { + if (date::from_stream(is, fmt.c_str(), d).fail()) { + return 1; + } + } catch (std::exception& e) { + logprintf("ERROR: date::from_stream failed: %s", e.what()); + return 1; + } *output = static_cast(d.time_since_epoch().count()); diff --git a/test.pwn b/test.pwn index 397a9e4..7d3942c 100644 --- a/test.pwn +++ b/test.pwn @@ -3,6 +3,7 @@ #include "chrono.inc" #include +#include #include @@ -479,6 +480,22 @@ Test:TimeParse_ISO6801_FULL_UTC() { ASSERT(ts == Timestamp:1527929232); } +Test:TimeParse_Invalid() { + new + year = 1997, + month = 3, + day = 2, + ret, + Timestamp:seconds, + Seconds:agetime; + + TimeParse(sprintf("%i%i%i", year, month, day), "%Y%m%d", seconds); + agetime = Now() - seconds; + + printf("- output: %d: %d agetime: %d", ret, _:seconds, _:agetime); + ASSERT(seconds == Timestamp:0); +} + Test:TimestampDifference() { new Timestamp:future = Timestamp:1527932832,