summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2022-10-20 16:54:39 -0500
committerAaron Franke <arnfranke@yahoo.com>2022-12-26 15:16:25 -0600
commit8d7d1b0bb29c5603ffd02d1c82247c59d6b90917 (patch)
treecfcf4632cbbb80aa4a62865d4df4eb0b0400b567
parentb6e06038f8a373f7fb8d26e92d5f06887e459598 (diff)
Remove duplicate Month and Weekday enums
Well, they were duplicately-exposed, but triplicately-defined.
-rw-r--r--core/core_bind.cpp21
-rw-r--r--core/core_bind.h29
-rw-r--r--core/os/os.h28
-rw-r--r--core/os/time.cpp4
-rw-r--r--core/os/time.h28
-rw-r--r--core/os/time_enums.h63
-rw-r--r--doc/classes/OS.xml57
-rw-r--r--tests/core/test_time.h8
8 files changed, 71 insertions, 167 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp
index 9503bd2575..58b2bc0492 100644
--- a/core/core_bind.cpp
+++ b/core/core_bind.cpp
@@ -613,27 +613,6 @@ void OS::_bind_methods() {
BIND_ENUM_CONSTANT(RENDERING_DRIVER_VULKAN);
BIND_ENUM_CONSTANT(RENDERING_DRIVER_OPENGL3);
- BIND_ENUM_CONSTANT(DAY_SUNDAY);
- BIND_ENUM_CONSTANT(DAY_MONDAY);
- BIND_ENUM_CONSTANT(DAY_TUESDAY);
- BIND_ENUM_CONSTANT(DAY_WEDNESDAY);
- BIND_ENUM_CONSTANT(DAY_THURSDAY);
- BIND_ENUM_CONSTANT(DAY_FRIDAY);
- BIND_ENUM_CONSTANT(DAY_SATURDAY);
-
- BIND_ENUM_CONSTANT(MONTH_JANUARY);
- BIND_ENUM_CONSTANT(MONTH_FEBRUARY);
- BIND_ENUM_CONSTANT(MONTH_MARCH);
- BIND_ENUM_CONSTANT(MONTH_APRIL);
- BIND_ENUM_CONSTANT(MONTH_MAY);
- BIND_ENUM_CONSTANT(MONTH_JUNE);
- BIND_ENUM_CONSTANT(MONTH_JULY);
- BIND_ENUM_CONSTANT(MONTH_AUGUST);
- BIND_ENUM_CONSTANT(MONTH_SEPTEMBER);
- BIND_ENUM_CONSTANT(MONTH_OCTOBER);
- BIND_ENUM_CONSTANT(MONTH_NOVEMBER);
- BIND_ENUM_CONSTANT(MONTH_DECEMBER);
-
BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
diff --git a/core/core_bind.h b/core/core_bind.h
index c863a8094c..e556b1878f 100644
--- a/core/core_bind.h
+++ b/core/core_bind.h
@@ -129,33 +129,6 @@ public:
RENDERING_DRIVER_OPENGL3,
};
- enum Weekday {
- DAY_SUNDAY,
- DAY_MONDAY,
- DAY_TUESDAY,
- DAY_WEDNESDAY,
- DAY_THURSDAY,
- DAY_FRIDAY,
- DAY_SATURDAY
- };
-
- enum Month {
- // Start at 1 to follow Windows SYSTEMTIME structure
- // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
- MONTH_JANUARY = 1,
- MONTH_FEBRUARY,
- MONTH_MARCH,
- MONTH_APRIL,
- MONTH_MAY,
- MONTH_JUNE,
- MONTH_JULY,
- MONTH_AUGUST,
- MONTH_SEPTEMBER,
- MONTH_OCTOBER,
- MONTH_NOVEMBER,
- MONTH_DECEMBER
- };
-
virtual PackedStringArray get_connected_midi_inputs();
virtual void open_midi_inputs();
virtual void close_midi_inputs();
@@ -583,8 +556,6 @@ VARIANT_ENUM_CAST(core_bind::ResourceLoader::CacheMode);
VARIANT_BITFIELD_CAST(core_bind::ResourceSaver::SaverFlags);
VARIANT_ENUM_CAST(core_bind::OS::RenderingDriver);
-VARIANT_ENUM_CAST(core_bind::OS::Weekday);
-VARIANT_ENUM_CAST(core_bind::OS::Month);
VARIANT_ENUM_CAST(core_bind::OS::SystemDir);
VARIANT_ENUM_CAST(core_bind::Geometry2D::PolyBooleanOperation);
diff --git a/core/os/os.h b/core/os/os.h
index 07e9020a51..a5885b1aaa 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -34,6 +34,7 @@
#include "core/config/engine.h"
#include "core/io/image.h"
#include "core/io/logger.h"
+#include "core/os/time_enums.h"
#include "core/string/ustring.h"
#include "core/templates/list.h"
#include "core/templates/vector.h"
@@ -185,33 +186,6 @@ public:
virtual void yield();
- enum Weekday : uint8_t {
- WEEKDAY_SUNDAY,
- WEEKDAY_MONDAY,
- WEEKDAY_TUESDAY,
- WEEKDAY_WEDNESDAY,
- WEEKDAY_THURSDAY,
- WEEKDAY_FRIDAY,
- WEEKDAY_SATURDAY,
- };
-
- enum Month : uint8_t {
- /// Start at 1 to follow Windows SYSTEMTIME structure
- /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
- MONTH_JANUARY = 1,
- MONTH_FEBRUARY,
- MONTH_MARCH,
- MONTH_APRIL,
- MONTH_MAY,
- MONTH_JUNE,
- MONTH_JULY,
- MONTH_AUGUST,
- MONTH_SEPTEMBER,
- MONTH_OCTOBER,
- MONTH_NOVEMBER,
- MONTH_DECEMBER,
- };
-
struct DateTime {
int64_t year;
Month month;
diff --git a/core/os/time.cpp b/core/os/time.cpp
index a3c2c99b4c..3fc831d124 100644
--- a/core/os/time.cpp
+++ b/core/os/time.cpp
@@ -52,8 +52,8 @@ static const uint8_t MONTH_DAYS_TABLE[2][12] = {
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
-VARIANT_ENUM_CAST(Time::Month);
-VARIANT_ENUM_CAST(Time::Weekday);
+VARIANT_ENUM_CAST(Month);
+VARIANT_ENUM_CAST(Weekday);
#define UNIX_TIME_TO_HMS \
uint8_t hour, minute, second; \
diff --git a/core/os/time.h b/core/os/time.h
index 4b4ce3526a..379a224f34 100644
--- a/core/os/time.h
+++ b/core/os/time.h
@@ -32,6 +32,7 @@
#define TIME_H
#include "core/object/class_db.h"
+#include "time_enums.h"
// This Time class conforms with as many of the ISO 8601 standards as possible.
// * As per ISO 8601:2004 4.3.2.1, all dates follow the Proleptic Gregorian
@@ -51,33 +52,6 @@ class Time : public Object {
public:
static Time *get_singleton();
- enum Month {
- /// Start at 1 to follow Windows SYSTEMTIME structure
- /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
- MONTH_JANUARY = 1,
- MONTH_FEBRUARY,
- MONTH_MARCH,
- MONTH_APRIL,
- MONTH_MAY,
- MONTH_JUNE,
- MONTH_JULY,
- MONTH_AUGUST,
- MONTH_SEPTEMBER,
- MONTH_OCTOBER,
- MONTH_NOVEMBER,
- MONTH_DECEMBER,
- };
-
- enum Weekday : uint8_t {
- WEEKDAY_SUNDAY,
- WEEKDAY_MONDAY,
- WEEKDAY_TUESDAY,
- WEEKDAY_WEDNESDAY,
- WEEKDAY_THURSDAY,
- WEEKDAY_FRIDAY,
- WEEKDAY_SATURDAY,
- };
-
// Methods that convert times.
Dictionary get_datetime_dict_from_unix_time(int64_t p_unix_time_val) const;
Dictionary get_date_dict_from_unix_time(int64_t p_unix_time_val) const;
diff --git a/core/os/time_enums.h b/core/os/time_enums.h
new file mode 100644
index 0000000000..aa2d97a308
--- /dev/null
+++ b/core/os/time_enums.h
@@ -0,0 +1,63 @@
+/*************************************************************************/
+/* time_enums.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef TIME_ENUMS_H
+#define TIME_ENUMS_H
+
+#include <cstdint>
+
+enum Month {
+ /// Start at 1 to follow Windows SYSTEMTIME structure
+ /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
+ MONTH_JANUARY = 1,
+ MONTH_FEBRUARY,
+ MONTH_MARCH,
+ MONTH_APRIL,
+ MONTH_MAY,
+ MONTH_JUNE,
+ MONTH_JULY,
+ MONTH_AUGUST,
+ MONTH_SEPTEMBER,
+ MONTH_OCTOBER,
+ MONTH_NOVEMBER,
+ MONTH_DECEMBER,
+};
+
+enum Weekday : uint8_t {
+ WEEKDAY_SUNDAY,
+ WEEKDAY_MONDAY,
+ WEEKDAY_TUESDAY,
+ WEEKDAY_WEDNESDAY,
+ WEEKDAY_THURSDAY,
+ WEEKDAY_FRIDAY,
+ WEEKDAY_SATURDAY,
+};
+
+#endif // TIME_ENUMS_H
diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml
index 0efc6ab399..ff4982e2fb 100644
--- a/doc/classes/OS.xml
+++ b/doc/classes/OS.xml
@@ -654,63 +654,6 @@
<constant name="RENDERING_DRIVER_OPENGL3" value="1" enum="RenderingDriver">
The OpenGL 3 rendering driver. It uses OpenGL 3.3 Core Profile on desktop platforms, OpenGL ES 3.0 on mobile devices, and WebGL 2.0 on Web.
</constant>
- <constant name="DAY_SUNDAY" value="0" enum="Weekday">
- Sunday.
- </constant>
- <constant name="DAY_MONDAY" value="1" enum="Weekday">
- Monday.
- </constant>
- <constant name="DAY_TUESDAY" value="2" enum="Weekday">
- Tuesday.
- </constant>
- <constant name="DAY_WEDNESDAY" value="3" enum="Weekday">
- Wednesday.
- </constant>
- <constant name="DAY_THURSDAY" value="4" enum="Weekday">
- Thursday.
- </constant>
- <constant name="DAY_FRIDAY" value="5" enum="Weekday">
- Friday.
- </constant>
- <constant name="DAY_SATURDAY" value="6" enum="Weekday">
- Saturday.
- </constant>
- <constant name="MONTH_JANUARY" value="1" enum="Month">
- January.
- </constant>
- <constant name="MONTH_FEBRUARY" value="2" enum="Month">
- February.
- </constant>
- <constant name="MONTH_MARCH" value="3" enum="Month">
- March.
- </constant>
- <constant name="MONTH_APRIL" value="4" enum="Month">
- April.
- </constant>
- <constant name="MONTH_MAY" value="5" enum="Month">
- May.
- </constant>
- <constant name="MONTH_JUNE" value="6" enum="Month">
- June.
- </constant>
- <constant name="MONTH_JULY" value="7" enum="Month">
- July.
- </constant>
- <constant name="MONTH_AUGUST" value="8" enum="Month">
- August.
- </constant>
- <constant name="MONTH_SEPTEMBER" value="9" enum="Month">
- September.
- </constant>
- <constant name="MONTH_OCTOBER" value="10" enum="Month">
- October.
- </constant>
- <constant name="MONTH_NOVEMBER" value="11" enum="Month">
- November.
- </constant>
- <constant name="MONTH_DECEMBER" value="12" enum="Month">
- December.
- </constant>
<constant name="SYSTEM_DIR_DESKTOP" value="0" enum="SystemDir">
Desktop directory path.
</constant>
diff --git a/tests/core/test_time.h b/tests/core/test_time.h
index 177512c832..ae3d624fe8 100644
--- a/tests/core/test_time.h
+++ b/tests/core/test_time.h
@@ -91,7 +91,7 @@ TEST_CASE("[Time] Datetime dictionary conversion methods") {
datetime[YEAR_KEY] = 2014;
datetime[MONTH_KEY] = 2;
datetime[DAY_KEY] = 9;
- datetime[WEEKDAY_KEY] = Time::Weekday::WEEKDAY_SUNDAY;
+ datetime[WEEKDAY_KEY] = Weekday::WEEKDAY_SUNDAY;
datetime[HOUR_KEY] = 22;
datetime[MINUTE_KEY] = 10;
datetime[SECOND_KEY] = 30;
@@ -100,7 +100,7 @@ TEST_CASE("[Time] Datetime dictionary conversion methods") {
date_only[YEAR_KEY] = 2014;
date_only[MONTH_KEY] = 2;
date_only[DAY_KEY] = 9;
- date_only[WEEKDAY_KEY] = Time::Weekday::WEEKDAY_SUNDAY;
+ date_only[WEEKDAY_KEY] = Weekday::WEEKDAY_SUNDAY;
Dictionary time_only;
time_only[HOUR_KEY] = 22;
@@ -115,8 +115,8 @@ TEST_CASE("[Time] Datetime dictionary conversion methods") {
CHECK_MESSAGE(time->get_date_dict_from_unix_time(1391904000).hash() == date_only.hash(), "Time get_date_dict_from_unix_time: The date timestamp for GODOT IS OPEN SOURCE is converted to a dictionary as expected.");
CHECK_MESSAGE(time->get_time_dict_from_unix_time(79830).hash() == time_only.hash(), "Time get_time_dict_from_unix_time: The time timestamp for GODOT IS OPEN SOURCE is converted to a dictionary as expected.");
- CHECK_MESSAGE((Time::Weekday)(int)time->get_datetime_dict_from_unix_time(0)[WEEKDAY_KEY] == Time::Weekday::WEEKDAY_THURSDAY, "Time get_datetime_dict_from_unix_time: The weekday for the Unix epoch is a Thursday as expected.");
- CHECK_MESSAGE((Time::Weekday)(int)time->get_datetime_dict_from_unix_time(1391983830)[WEEKDAY_KEY] == Time::Weekday::WEEKDAY_SUNDAY, "Time get_datetime_dict_from_unix_time: The weekday for GODOT IS OPEN SOURCE is a Sunday as expected.");
+ CHECK_MESSAGE((Weekday)(int)time->get_datetime_dict_from_unix_time(0)[WEEKDAY_KEY] == Weekday::WEEKDAY_THURSDAY, "Time get_datetime_dict_from_unix_time: The weekday for the Unix epoch is a Thursday as expected.");
+ CHECK_MESSAGE((Weekday)(int)time->get_datetime_dict_from_unix_time(1391983830)[WEEKDAY_KEY] == Weekday::WEEKDAY_SUNDAY, "Time get_datetime_dict_from_unix_time: The weekday for GODOT IS OPEN SOURCE is a Sunday as expected.");
CHECK_MESSAGE(time->get_datetime_dict_from_datetime_string("2014-02-09T22:10:30").hash() == datetime.hash(), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE works as expected.");
CHECK_MESSAGE(!time->get_datetime_dict_from_datetime_string("2014-02-09T22:10:30", false).has(WEEKDAY_KEY), "Time get_datetime_dict_from_string: The dictionary from string for GODOT IS OPEN SOURCE without weekday doesn't contain the weekday key as expected.");