time.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /*************************************************************************/
  2. /* time.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "time.h"
  31. #include "core/os/os.h"
  32. #define UNIX_EPOCH_YEAR_AD 1970 // 1970
  33. #define SECONDS_PER_DAY (24 * 60 * 60) // 86400
  34. #define IS_LEAP_YEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
  35. #define YEAR_SIZE(year) (IS_LEAP_YEAR(year) ? 366 : 365)
  36. #define YEAR_KEY "year"
  37. #define MONTH_KEY "month"
  38. #define DAY_KEY "day"
  39. #define WEEKDAY_KEY "weekday"
  40. #define HOUR_KEY "hour"
  41. #define MINUTE_KEY "minute"
  42. #define SECOND_KEY "second"
  43. #define DST_KEY "dst"
  44. // Table of number of days in each month (for regular year and leap year).
  45. static const uint8_t MONTH_DAYS_TABLE[2][12] = {
  46. { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  47. { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  48. };
  49. VARIANT_ENUM_CAST(Time::Month);
  50. VARIANT_ENUM_CAST(Time::Weekday);
  51. #define UNIX_TIME_TO_HMS \
  52. uint8_t hour, minute, second; \
  53. { \
  54. /* The time of the day (in seconds since start of day). */ \
  55. uint32_t day_clock = Math::posmod(p_unix_time_val, SECONDS_PER_DAY); \
  56. /* On x86 these 4 lines can be optimized to only 2 divisions. */ \
  57. second = day_clock % 60; \
  58. day_clock /= 60; \
  59. minute = day_clock % 60; \
  60. hour = day_clock / 60; \
  61. }
  62. #define UNIX_TIME_TO_YMD \
  63. int64_t year; \
  64. Month month; \
  65. uint8_t day; \
  66. /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \
  67. int64_t day_number = Math::floor(p_unix_time_val / (double)SECONDS_PER_DAY); \
  68. { \
  69. int64_t day_number_copy = day_number; \
  70. year = UNIX_EPOCH_YEAR_AD; \
  71. uint8_t month_zero_index = 0; \
  72. while (day_number_copy >= YEAR_SIZE(year)) { \
  73. day_number_copy -= YEAR_SIZE(year); \
  74. year++; \
  75. } \
  76. while (day_number_copy < 0) { \
  77. year--; \
  78. day_number_copy += YEAR_SIZE(year); \
  79. } \
  80. /* After the above, day_number now represents the day of the year (0-index). */ \
  81. while (day_number_copy >= MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month_zero_index]) { \
  82. day_number_copy -= MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month_zero_index]; \
  83. month_zero_index++; \
  84. } \
  85. /* After the above, day_number now represents the day of the month (0-index). */ \
  86. month = (Month)(month_zero_index + 1); \
  87. day = day_number_copy + 1; \
  88. }
  89. #define VALIDATE_YMDHMS(ret) \
  90. ERR_FAIL_COND_V_MSG(month == 0, ret, "Invalid month value of: " + itos(month) + ", months are 1-indexed and cannot be 0. See the Time.Month enum for valid values."); \
  91. ERR_FAIL_COND_V_MSG(month > 12, ret, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \
  92. ERR_FAIL_COND_V_MSG(hour > 23, ret, "Invalid hour value of: " + itos(hour) + "."); \
  93. ERR_FAIL_COND_V_MSG(minute > 59, ret, "Invalid minute value of: " + itos(minute) + "."); \
  94. ERR_FAIL_COND_V_MSG(second > 59, ret, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \
  95. /* Do this check after month is tested as valid. */ \
  96. ERR_FAIL_COND_V_MSG(day == 0, ret, "Invalid day value of: " + itos(month) + ", days are 1-indexed and cannot be 0."); \
  97. uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \
  98. ERR_FAIL_COND_V_MSG(day > days_in_this_month, ret, "Invalid day value of: " + itos(day) + " which is larger than the maximum for this month, " + itos(days_in_this_month) + ".");
  99. #define YMD_TO_DAY_NUMBER \
  100. /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \
  101. int64_t day_number = day - 1; \
  102. /* Add the days in the months to day_number. */ \
  103. for (int i = 0; i < month - 1; i++) { \
  104. day_number += MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][i]; \
  105. } \
  106. /* Add the days in the years to day_number. */ \
  107. if (year >= UNIX_EPOCH_YEAR_AD) { \
  108. for (int64_t iyear = UNIX_EPOCH_YEAR_AD; iyear < year; iyear++) { \
  109. day_number += YEAR_SIZE(iyear); \
  110. } \
  111. } else { \
  112. for (int64_t iyear = UNIX_EPOCH_YEAR_AD - 1; iyear >= year; iyear--) { \
  113. day_number -= YEAR_SIZE(iyear); \
  114. } \
  115. }
  116. #define PARSE_ISO8601_STRING \
  117. int64_t year = UNIX_EPOCH_YEAR_AD; \
  118. Month month = MONTH_JANUARY; \
  119. uint8_t day = 1; \
  120. uint8_t hour = 0; \
  121. uint8_t minute = 0; \
  122. uint8_t second = 0; \
  123. { \
  124. bool has_date = false, has_time = false; \
  125. String date, time; \
  126. if (p_datetime.find_char('T') > 0) { \
  127. has_date = has_time = true; \
  128. PackedStringArray array = p_datetime.split("T"); \
  129. date = array[0]; \
  130. time = array[1]; \
  131. } else if (p_datetime.find_char(' ') > 0) { \
  132. has_date = has_time = true; \
  133. PackedStringArray array = p_datetime.split(" "); \
  134. date = array[0]; \
  135. time = array[1]; \
  136. } else if (p_datetime.find_char('-', 1) > 0) { \
  137. has_date = true; \
  138. date = p_datetime; \
  139. } else if (p_datetime.find_char(':') > 0) { \
  140. has_time = true; \
  141. time = p_datetime; \
  142. } \
  143. /* Set the variables from the contents of the string. */ \
  144. if (has_date) { \
  145. PackedInt32Array array = date.split_ints("-", false); \
  146. year = array[0]; \
  147. month = (Month)array[1]; \
  148. day = array[2]; \
  149. /* Handle negative years. */ \
  150. if (p_datetime.find_char('-') == 0) { \
  151. year *= -1; \
  152. } \
  153. } \
  154. if (has_time) { \
  155. PackedInt32Array array = time.split_ints(":", false); \
  156. hour = array[0]; \
  157. minute = array[1]; \
  158. second = array[2]; \
  159. } \
  160. }
  161. #define EXTRACT_FROM_DICTIONARY \
  162. /* Get all time values from the dictionary. If it doesn't exist, set the */ \
  163. /* values to the default values for Unix epoch (1970-01-01 00:00:00). */ \
  164. int64_t year = p_datetime.has(YEAR_KEY) ? int64_t(p_datetime[YEAR_KEY]) : UNIX_EPOCH_YEAR_AD; \
  165. Month month = Month((p_datetime.has(MONTH_KEY)) ? uint8_t(p_datetime[MONTH_KEY]) : 1); \
  166. uint8_t day = p_datetime.has(DAY_KEY) ? uint8_t(p_datetime[DAY_KEY]) : 1; \
  167. uint8_t hour = p_datetime.has(HOUR_KEY) ? uint8_t(p_datetime[HOUR_KEY]) : 0; \
  168. uint8_t minute = p_datetime.has(MINUTE_KEY) ? uint8_t(p_datetime[MINUTE_KEY]) : 0; \
  169. uint8_t second = p_datetime.has(SECOND_KEY) ? uint8_t(p_datetime[SECOND_KEY]) : 0;
  170. Time *Time::singleton = nullptr;
  171. Time *Time::get_singleton() {
  172. if (!singleton) {
  173. memnew(Time);
  174. }
  175. return singleton;
  176. }
  177. Dictionary Time::get_datetime_dict_from_unix_time(int64_t p_unix_time_val) const {
  178. UNIX_TIME_TO_HMS
  179. UNIX_TIME_TO_YMD
  180. Dictionary datetime;
  181. datetime[YEAR_KEY] = year;
  182. datetime[MONTH_KEY] = (uint8_t)month;
  183. datetime[DAY_KEY] = day;
  184. // Unix epoch was a Thursday (day 0 aka 1970-01-01).
  185. datetime[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7);
  186. datetime[HOUR_KEY] = hour;
  187. datetime[MINUTE_KEY] = minute;
  188. datetime[SECOND_KEY] = second;
  189. return datetime;
  190. }
  191. Dictionary Time::get_date_dict_from_unix_time(int64_t p_unix_time_val) const {
  192. UNIX_TIME_TO_YMD
  193. Dictionary datetime;
  194. datetime[YEAR_KEY] = year;
  195. datetime[MONTH_KEY] = (uint8_t)month;
  196. datetime[DAY_KEY] = day;
  197. // Unix epoch was a Thursday (day 0 aka 1970-01-01).
  198. datetime[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7);
  199. return datetime;
  200. }
  201. Dictionary Time::get_time_dict_from_unix_time(int64_t p_unix_time_val) const {
  202. UNIX_TIME_TO_HMS
  203. Dictionary datetime;
  204. datetime[HOUR_KEY] = hour;
  205. datetime[MINUTE_KEY] = minute;
  206. datetime[SECOND_KEY] = second;
  207. return datetime;
  208. }
  209. String Time::get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space) const {
  210. UNIX_TIME_TO_HMS
  211. UNIX_TIME_TO_YMD
  212. // vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
  213. String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
  214. if (p_use_space) {
  215. timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second);
  216. } else {
  217. timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second);
  218. }
  219. return timestamp;
  220. }
  221. String Time::get_date_string_from_unix_time(int64_t p_unix_time_val) const {
  222. UNIX_TIME_TO_YMD
  223. // Android is picky about the types passed to make Variant, so we need a cast.
  224. return vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
  225. }
  226. String Time::get_time_string_from_unix_time(int64_t p_unix_time_val) const {
  227. UNIX_TIME_TO_HMS
  228. return vformat("%02d:%02d:%02d", hour, minute, second);
  229. }
  230. Dictionary Time::get_datetime_dict_from_string(String p_datetime, bool p_weekday) const {
  231. PARSE_ISO8601_STRING
  232. Dictionary dict;
  233. dict[YEAR_KEY] = year;
  234. dict[MONTH_KEY] = (uint8_t)month;
  235. dict[DAY_KEY] = day;
  236. if (p_weekday) {
  237. YMD_TO_DAY_NUMBER
  238. // Unix epoch was a Thursday (day 0 aka 1970-01-01).
  239. dict[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7);
  240. }
  241. dict[HOUR_KEY] = hour;
  242. dict[MINUTE_KEY] = minute;
  243. dict[SECOND_KEY] = second;
  244. return dict;
  245. }
  246. String Time::get_datetime_string_from_dict(const Dictionary p_datetime, bool p_use_space) const {
  247. ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty.");
  248. EXTRACT_FROM_DICTIONARY
  249. VALIDATE_YMDHMS("")
  250. // vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
  251. String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
  252. if (p_use_space) {
  253. timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second);
  254. } else {
  255. timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second);
  256. }
  257. return timestamp;
  258. }
  259. int64_t Time::get_unix_time_from_datetime_dict(const Dictionary p_datetime) const {
  260. ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty");
  261. EXTRACT_FROM_DICTIONARY
  262. VALIDATE_YMDHMS(0)
  263. YMD_TO_DAY_NUMBER
  264. return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second;
  265. }
  266. int64_t Time::get_unix_time_from_datetime_string(String p_datetime) const {
  267. PARSE_ISO8601_STRING
  268. VALIDATE_YMDHMS(0)
  269. YMD_TO_DAY_NUMBER
  270. return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second;
  271. }
  272. String Time::get_offset_string_from_offset_minutes(int64_t p_offset_minutes) const {
  273. String sign;
  274. if (p_offset_minutes < 0) {
  275. sign = "-";
  276. p_offset_minutes = -p_offset_minutes;
  277. } else {
  278. sign = "+";
  279. }
  280. // These two lines can be optimized to one instruction on x86 and others.
  281. // Note that % is acceptable here only because we ensure it's positive.
  282. int64_t offset_hours = p_offset_minutes / 60;
  283. int64_t offset_minutes = p_offset_minutes % 60;
  284. return vformat("%s%02d:%02d", sign, offset_hours, offset_minutes);
  285. }
  286. Dictionary Time::get_datetime_dict_from_system(bool p_utc) const {
  287. OS::Date date = OS::get_singleton()->get_date(p_utc);
  288. OS::Time time = OS::get_singleton()->get_time(p_utc);
  289. Dictionary datetime;
  290. datetime[YEAR_KEY] = date.year;
  291. datetime[MONTH_KEY] = (uint8_t)date.month;
  292. datetime[DAY_KEY] = date.day;
  293. datetime[WEEKDAY_KEY] = (uint8_t)date.weekday;
  294. datetime[DST_KEY] = date.dst;
  295. datetime[HOUR_KEY] = time.hour;
  296. datetime[MINUTE_KEY] = time.minute;
  297. datetime[SECOND_KEY] = time.second;
  298. return datetime;
  299. }
  300. Dictionary Time::get_date_dict_from_system(bool p_utc) const {
  301. OS::Date date = OS::get_singleton()->get_date(p_utc);
  302. Dictionary date_dictionary;
  303. date_dictionary[YEAR_KEY] = date.year;
  304. date_dictionary[MONTH_KEY] = (uint8_t)date.month;
  305. date_dictionary[DAY_KEY] = date.day;
  306. date_dictionary[WEEKDAY_KEY] = (uint8_t)date.weekday;
  307. date_dictionary[DST_KEY] = date.dst;
  308. return date_dictionary;
  309. }
  310. Dictionary Time::get_time_dict_from_system(bool p_utc) const {
  311. OS::Time time = OS::get_singleton()->get_time(p_utc);
  312. Dictionary time_dictionary;
  313. time_dictionary[HOUR_KEY] = time.hour;
  314. time_dictionary[MINUTE_KEY] = time.minute;
  315. time_dictionary[SECOND_KEY] = time.second;
  316. return time_dictionary;
  317. }
  318. String Time::get_datetime_string_from_system(bool p_utc, bool p_use_space) const {
  319. OS::Date date = OS::get_singleton()->get_date(p_utc);
  320. OS::Time time = OS::get_singleton()->get_time(p_utc);
  321. // vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
  322. String timestamp = vformat("%04d-%02d-%02d", date.year, (uint8_t)date.month, date.day);
  323. if (p_use_space) {
  324. timestamp = vformat("%s %02d:%02d:%02d", timestamp, time.hour, time.minute, time.second);
  325. } else {
  326. timestamp = vformat("%sT%02d:%02d:%02d", timestamp, time.hour, time.minute, time.second);
  327. }
  328. return timestamp;
  329. }
  330. String Time::get_date_string_from_system(bool p_utc) const {
  331. OS::Date date = OS::get_singleton()->get_date(p_utc);
  332. // Android is picky about the types passed to make Variant, so we need a cast.
  333. return vformat("%04d-%02d-%02d", date.year, (uint8_t)date.month, date.day);
  334. }
  335. String Time::get_time_string_from_system(bool p_utc) const {
  336. OS::Time time = OS::get_singleton()->get_time(p_utc);
  337. return vformat("%02d:%02d:%02d", time.hour, time.minute, time.second);
  338. }
  339. Dictionary Time::get_time_zone_from_system() const {
  340. OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
  341. Dictionary timezone;
  342. timezone["bias"] = info.bias;
  343. timezone["name"] = info.name;
  344. return timezone;
  345. }
  346. double Time::get_unix_time_from_system() const {
  347. return OS::get_singleton()->get_unix_time();
  348. }
  349. uint64_t Time::get_ticks_msec() const {
  350. return OS::get_singleton()->get_ticks_msec();
  351. }
  352. uint64_t Time::get_ticks_usec() const {
  353. return OS::get_singleton()->get_ticks_usec();
  354. }
  355. void Time::_bind_methods() {
  356. ClassDB::bind_method(D_METHOD("get_datetime_dict_from_unix_time", "unix_time_val"), &Time::get_datetime_dict_from_unix_time);
  357. ClassDB::bind_method(D_METHOD("get_date_dict_from_unix_time", "unix_time_val"), &Time::get_date_dict_from_unix_time);
  358. ClassDB::bind_method(D_METHOD("get_time_dict_from_unix_time", "unix_time_val"), &Time::get_time_dict_from_unix_time);
  359. ClassDB::bind_method(D_METHOD("get_datetime_string_from_unix_time", "unix_time_val", "use_space"), &Time::get_datetime_string_from_unix_time, DEFVAL(false));
  360. ClassDB::bind_method(D_METHOD("get_date_string_from_unix_time", "unix_time_val"), &Time::get_date_string_from_unix_time);
  361. ClassDB::bind_method(D_METHOD("get_time_string_from_unix_time", "unix_time_val"), &Time::get_time_string_from_unix_time);
  362. ClassDB::bind_method(D_METHOD("get_datetime_dict_from_string", "datetime", "weekday"), &Time::get_datetime_dict_from_string);
  363. ClassDB::bind_method(D_METHOD("get_datetime_string_from_dict", "datetime", "use_space"), &Time::get_datetime_string_from_dict);
  364. ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_dict", "datetime"), &Time::get_unix_time_from_datetime_dict);
  365. ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_string", "datetime"), &Time::get_unix_time_from_datetime_string);
  366. ClassDB::bind_method(D_METHOD("get_offset_string_from_offset_minutes", "offset_minutes"), &Time::get_offset_string_from_offset_minutes);
  367. ClassDB::bind_method(D_METHOD("get_datetime_dict_from_system", "utc"), &Time::get_datetime_dict_from_system, DEFVAL(false));
  368. ClassDB::bind_method(D_METHOD("get_date_dict_from_system", "utc"), &Time::get_date_dict_from_system, DEFVAL(false));
  369. ClassDB::bind_method(D_METHOD("get_time_dict_from_system", "utc"), &Time::get_time_dict_from_system, DEFVAL(false));
  370. ClassDB::bind_method(D_METHOD("get_datetime_string_from_system", "utc", "use_space"), &Time::get_datetime_string_from_system, DEFVAL(false), DEFVAL(false));
  371. ClassDB::bind_method(D_METHOD("get_date_string_from_system", "utc"), &Time::get_date_string_from_system, DEFVAL(false));
  372. ClassDB::bind_method(D_METHOD("get_time_string_from_system", "utc"), &Time::get_time_string_from_system, DEFVAL(false));
  373. ClassDB::bind_method(D_METHOD("get_time_zone_from_system"), &Time::get_time_zone_from_system);
  374. ClassDB::bind_method(D_METHOD("get_unix_time_from_system"), &Time::get_unix_time_from_system);
  375. ClassDB::bind_method(D_METHOD("get_ticks_msec"), &Time::get_ticks_msec);
  376. ClassDB::bind_method(D_METHOD("get_ticks_usec"), &Time::get_ticks_usec);
  377. BIND_ENUM_CONSTANT(MONTH_JANUARY);
  378. BIND_ENUM_CONSTANT(MONTH_FEBRUARY);
  379. BIND_ENUM_CONSTANT(MONTH_MARCH);
  380. BIND_ENUM_CONSTANT(MONTH_APRIL);
  381. BIND_ENUM_CONSTANT(MONTH_MAY);
  382. BIND_ENUM_CONSTANT(MONTH_JUNE);
  383. BIND_ENUM_CONSTANT(MONTH_JULY);
  384. BIND_ENUM_CONSTANT(MONTH_AUGUST);
  385. BIND_ENUM_CONSTANT(MONTH_SEPTEMBER);
  386. BIND_ENUM_CONSTANT(MONTH_OCTOBER);
  387. BIND_ENUM_CONSTANT(MONTH_NOVEMBER);
  388. BIND_ENUM_CONSTANT(MONTH_DECEMBER);
  389. BIND_ENUM_CONSTANT(WEEKDAY_SUNDAY);
  390. BIND_ENUM_CONSTANT(WEEKDAY_MONDAY);
  391. BIND_ENUM_CONSTANT(WEEKDAY_TUESDAY);
  392. BIND_ENUM_CONSTANT(WEEKDAY_WEDNESDAY);
  393. BIND_ENUM_CONSTANT(WEEKDAY_THURSDAY);
  394. BIND_ENUM_CONSTANT(WEEKDAY_FRIDAY);
  395. BIND_ENUM_CONSTANT(WEEKDAY_SATURDAY);
  396. }
  397. Time::Time() {
  398. ERR_FAIL_COND_MSG(singleton, "Singleton for Time already exists.");
  399. singleton = this;
  400. }
  401. Time::~Time() {
  402. singleton = nullptr;
  403. }