From 2b7645357363253e6293d091456661e637232b9f Mon Sep 17 00:00:00 2001 From: Djack Donovan Date: Tue, 4 Oct 2022 15:26:33 +0200 Subject: [PATCH] Script: to_date accepts "now" as an argument indentation fix --- doc/function/to_date.txt | 2 ++ src/script/functions/basic.cpp | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/function/to_date.txt b/doc/function/to_date.txt index 8b29d7b9c..8fdd8700c 100644 --- a/doc/function/to_date.txt +++ b/doc/function/to_date.txt @@ -14,6 +14,8 @@ Convert a string value to a [[type:date]]. --Examples-- > to_date("2008-12-31 23:59:59") > to_date("today midnight") +> to_date("today noon") +> to_date("now") --See also-- | [[fun:to_string]] Convert dates to strings diff --git a/src/script/functions/basic.cpp b/src/script/functions/basic.cpp index c898f5922..751b77de9 100644 --- a/src/script/functions/basic.cpp +++ b/src/script/functions/basic.cpp @@ -216,9 +216,16 @@ SCRIPT_FUNCTION(to_color) { SCRIPT_FUNCTION(to_date) { try { - SCRIPT_PARAM_C(wxDateTime, input); - SCRIPT_RETURN(input); - } catch (const ScriptError& e) { + SCRIPT_PARAM_C(String, input); + if (input == "now") { + SCRIPT_RETURN(wxDateTime::Now()); + } + else { + SCRIPT_PARAM_C(wxDateTime, input); + SCRIPT_RETURN(input); + } + } + catch (const ScriptError& e) { return delay_error(e); } }