From 7e5020b2fa7be4afd1a79b24104a83744b10ffa0 Mon Sep 17 00:00:00 2001 From: Aitor Cereceto Date: Fri, 12 Mar 2021 08:12:43 +0100 Subject: [PATCH] [46188] fix: get unix from datetime when empty dict (cherry picked from commit 1e820b3d9db58b6d72ad3ba227cd5e401893c72a) --- core/bind/core_bind.cpp | 2 ++ doc/classes/OS.xml | 1 + 2 files changed, 3 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3443496ba9f..514a22fa6bc 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -798,6 +798,8 @@ Dictionary _OS::get_time(bool utc) const { * @return epoch calculated */ int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const { + // if datetime is an empty Dictionary throws an error + ERR_FAIL_COND_V_MSG(datetime.empty(), 0, "Invalid datetime Dictionary: Dictionary is empty"); // Bunch of conversion constants static const unsigned int SECONDS_PER_MINUTE = 60; diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 2278835f381..053a49acd40 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -549,6 +549,7 @@ Gets an epoch time value from a dictionary of time values. [code]datetime[/code] must be populated with the following keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], [code]second[/code]. + If the dictionary is empty [code]0[/code] is returned. You can pass the output from [method get_datetime_from_unix_time] directly into this function. Daylight Savings Time ([code]dst[/code]), if present, is ignored.