time.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /**************************************************************************/
  2. /* time.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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" // NOLINT(modernize-deprecated-headers) False positive with C-Header of the same name.
  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. static constexpr int64_t total_leap_days(int64_t p_year) {
  37. if (p_year > 0) {
  38. --p_year;
  39. return 1 + (p_year / 4 - p_year / 100 + p_year / 400);
  40. }
  41. return p_year / 4 - p_year / 100 + p_year / 400;
  42. }
  43. static constexpr int64_t year_to_days(int64_t p_year) {
  44. return p_year * 365 + total_leap_days(p_year);
  45. }
  46. static constexpr int64_t days_to_year(int64_t p_days) {
  47. int64_t year = 400 * p_days / year_to_days(400);
  48. if (year < 0) {
  49. --year;
  50. }
  51. if (year_to_days(year) > p_days) {
  52. --year;
  53. }
  54. if (year_to_days(year + 1) <= p_days) {
  55. ++year;
  56. }
  57. return year;
  58. }
  59. #define YEAR_KEY "year"
  60. #define MONTH_KEY "month"
  61. #define DAY_KEY "day"
  62. #define WEEKDAY_KEY "weekday"
  63. #define HOUR_KEY "hour"
  64. #define MINUTE_KEY "minute"
  65. #define SECOND_KEY "second"
  66. #define DST_KEY "dst"
  67. // Table of number of days in each month (for regular year and leap year).
  68. static const uint8_t MONTH_DAYS_TABLE[2][12] = {
  69. { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  70. { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  71. };
  72. #define UNIX_TIME_TO_HMS \
  73. uint8_t hour, minute, second; \
  74. { \
  75. /* The time of the day (in seconds since start of day). */ \
  76. uint32_t day_clock = Math::posmod(p_unix_time_val, SECONDS_PER_DAY); \
  77. /* On x86 these 4 lines can be optimized to only 2 divisions. */ \
  78. second = day_clock % 60; \
  79. day_clock /= 60; \
  80. minute = day_clock % 60; \
  81. hour = day_clock / 60; \
  82. }
  83. #define UNIX_TIME_TO_YMD \
  84. int64_t year; \
  85. Month month; \
  86. uint8_t day; \
  87. /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \
  88. int64_t day_number = Math::floor(p_unix_time_val / (double)SECONDS_PER_DAY); \
  89. { \
  90. int64_t day_number_copy = day_number; \
  91. day_number_copy += year_to_days(UNIX_EPOCH_YEAR_AD); \
  92. year = days_to_year(day_number_copy); \
  93. day_number_copy -= year_to_days(year); \
  94. uint8_t month_zero_index = 0; \
  95. /* After the above, day_number now represents the day of the year (0-index). */ \
  96. while (day_number_copy >= MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month_zero_index]) { \
  97. day_number_copy -= MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month_zero_index]; \
  98. month_zero_index++; \
  99. } \
  100. /* After the above, day_number now represents the day of the month (0-index). */ \
  101. month = (Month)(month_zero_index + 1); \
  102. day = day_number_copy + 1; \
  103. }
  104. #define VALIDATE_YMDHMS(ret) \
  105. 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."); \
  106. ERR_FAIL_COND_V_MSG(month < 0, ret, "Invalid month value of: " + itos(month) + "."); \
  107. ERR_FAIL_COND_V_MSG(month > 12, ret, "Invalid month value of: " + itos(month) + ". See the Time.Month enum for valid values."); \
  108. ERR_FAIL_COND_V_MSG(hour > 23, ret, "Invalid hour value of: " + itos(hour) + "."); \
  109. ERR_FAIL_COND_V_MSG(hour < 0, ret, "Invalid hour value of: " + itos(hour) + "."); \
  110. ERR_FAIL_COND_V_MSG(minute > 59, ret, "Invalid minute value of: " + itos(minute) + "."); \
  111. ERR_FAIL_COND_V_MSG(minute < 0, ret, "Invalid minute value of: " + itos(minute) + "."); \
  112. ERR_FAIL_COND_V_MSG(second > 59, ret, "Invalid second value of: " + itos(second) + " (leap seconds are not supported)."); \
  113. ERR_FAIL_COND_V_MSG(second < 0, ret, "Invalid second value of: " + itos(second) + "."); \
  114. ERR_FAIL_COND_V_MSG(day == 0, ret, "Invalid day value of: " + itos(day) + ", days are 1-indexed and cannot be 0."); \
  115. ERR_FAIL_COND_V_MSG(day < 0, ret, "Invalid day value of: " + itos(day) + "."); \
  116. /* Do this check after month is tested as valid. */ \
  117. uint8_t days_in_this_month = MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][month - 1]; \
  118. 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) + ".");
  119. #define YMD_TO_DAY_NUMBER \
  120. /* The day number since Unix epoch (0-index). Days before 1970 are negative. */ \
  121. int64_t day_number = day - 1; \
  122. /* Add the days in the months to day_number. */ \
  123. for (int i = 0; i < month - 1; i++) { \
  124. day_number += MONTH_DAYS_TABLE[IS_LEAP_YEAR(year)][i]; \
  125. } \
  126. /* Add the days in the years to day_number. */ \
  127. day_number += year_to_days(year); \
  128. day_number -= year_to_days(UNIX_EPOCH_YEAR_AD);
  129. #define PARSE_ISO8601_STRING(ret) \
  130. int64_t year = UNIX_EPOCH_YEAR_AD; \
  131. Month month = MONTH_JANUARY; \
  132. int day = 1; \
  133. int hour = 0; \
  134. int minute = 0; \
  135. int second = 0; \
  136. { \
  137. bool has_date = false, has_time = false; \
  138. String date, time; \
  139. if (p_datetime.find_char('T') > 0) { \
  140. has_date = has_time = true; \
  141. PackedStringArray array = p_datetime.split("T"); \
  142. ERR_FAIL_COND_V_MSG(array.size() < 2, ret, "Invalid ISO 8601 date/time string."); \
  143. date = array[0]; \
  144. time = array[1]; \
  145. } else if (p_datetime.find_char(' ') > 0) { \
  146. has_date = has_time = true; \
  147. PackedStringArray array = p_datetime.split(" "); \
  148. ERR_FAIL_COND_V_MSG(array.size() < 2, ret, "Invalid ISO 8601 date/time string."); \
  149. date = array[0]; \
  150. time = array[1]; \
  151. } else if (p_datetime.find_char('-', 1) > 0) { \
  152. has_date = true; \
  153. date = p_datetime; \
  154. } else if (p_datetime.find_char(':') > 0) { \
  155. has_time = true; \
  156. time = p_datetime; \
  157. } \
  158. /* Set the variables from the contents of the string. */ \
  159. if (has_date) { \
  160. PackedInt32Array array = date.split_ints("-", false); \
  161. ERR_FAIL_COND_V_MSG(array.size() < 3, ret, "Invalid ISO 8601 date string."); \
  162. year = array[0]; \
  163. month = (Month)array[1]; \
  164. day = array[2]; \
  165. /* Handle negative years. */ \
  166. if (p_datetime.find_char('-') == 0) { \
  167. year *= -1; \
  168. } \
  169. } \
  170. if (has_time) { \
  171. PackedInt32Array array = time.split_ints(":", false); \
  172. ERR_FAIL_COND_V_MSG(array.size() < 3, ret, "Invalid ISO 8601 time string."); \
  173. hour = array[0]; \
  174. minute = array[1]; \
  175. second = array[2]; \
  176. } \
  177. }
  178. #define EXTRACT_FROM_DICTIONARY \
  179. /* Get all time values from the dictionary. If it doesn't exist, set the */ \
  180. /* values to the default values for Unix epoch (1970-01-01 00:00:00). */ \
  181. int64_t year = p_datetime.has(YEAR_KEY) ? int64_t(p_datetime[YEAR_KEY]) : UNIX_EPOCH_YEAR_AD; \
  182. Month month = Month((p_datetime.has(MONTH_KEY)) ? int(p_datetime[MONTH_KEY]) : 1); \
  183. int day = p_datetime.has(DAY_KEY) ? int(p_datetime[DAY_KEY]) : 1; \
  184. int hour = p_datetime.has(HOUR_KEY) ? int(p_datetime[HOUR_KEY]) : 0; \
  185. int minute = p_datetime.has(MINUTE_KEY) ? int(p_datetime[MINUTE_KEY]) : 0; \
  186. int second = p_datetime.has(SECOND_KEY) ? int(p_datetime[SECOND_KEY]) : 0;
  187. Time *Time::singleton = nullptr;
  188. Time *Time::get_singleton() {
  189. return singleton;
  190. }
  191. Dictionary Time::get_datetime_dict_from_unix_time(int64_t p_unix_time_val) const {
  192. UNIX_TIME_TO_HMS
  193. UNIX_TIME_TO_YMD
  194. Dictionary datetime;
  195. datetime[YEAR_KEY] = year;
  196. datetime[MONTH_KEY] = (uint8_t)month;
  197. datetime[DAY_KEY] = day;
  198. // Unix epoch was a Thursday (day 0 aka 1970-01-01).
  199. datetime[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7);
  200. datetime[HOUR_KEY] = hour;
  201. datetime[MINUTE_KEY] = minute;
  202. datetime[SECOND_KEY] = second;
  203. return datetime;
  204. }
  205. Dictionary Time::get_date_dict_from_unix_time(int64_t p_unix_time_val) const {
  206. UNIX_TIME_TO_YMD
  207. Dictionary datetime;
  208. datetime[YEAR_KEY] = year;
  209. datetime[MONTH_KEY] = (uint8_t)month;
  210. datetime[DAY_KEY] = day;
  211. // Unix epoch was a Thursday (day 0 aka 1970-01-01).
  212. datetime[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7);
  213. return datetime;
  214. }
  215. Dictionary Time::get_time_dict_from_unix_time(int64_t p_unix_time_val) const {
  216. UNIX_TIME_TO_HMS
  217. Dictionary datetime;
  218. datetime[HOUR_KEY] = hour;
  219. datetime[MINUTE_KEY] = minute;
  220. datetime[SECOND_KEY] = second;
  221. return datetime;
  222. }
  223. String Time::get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space) const {
  224. UNIX_TIME_TO_HMS
  225. UNIX_TIME_TO_YMD
  226. const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
  227. return vformat(format_string, year, (uint8_t)month, day, hour, minute, second);
  228. }
  229. String Time::get_date_string_from_unix_time(int64_t p_unix_time_val) const {
  230. UNIX_TIME_TO_YMD
  231. // Android is picky about the types passed to make Variant, so we need a cast.
  232. return vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
  233. }
  234. String Time::get_time_string_from_unix_time(int64_t p_unix_time_val) const {
  235. UNIX_TIME_TO_HMS
  236. return vformat("%02d:%02d:%02d", hour, minute, second);
  237. }
  238. Dictionary Time::get_datetime_dict_from_datetime_string(const String &p_datetime, bool p_weekday) const {
  239. PARSE_ISO8601_STRING(Dictionary())
  240. Dictionary dict;
  241. dict[YEAR_KEY] = year;
  242. dict[MONTH_KEY] = (uint8_t)month;
  243. dict[DAY_KEY] = day;
  244. if (p_weekday) {
  245. YMD_TO_DAY_NUMBER
  246. // Unix epoch was a Thursday (day 0 aka 1970-01-01).
  247. dict[WEEKDAY_KEY] = Math::posmod(day_number + WEEKDAY_THURSDAY, 7);
  248. }
  249. dict[HOUR_KEY] = hour;
  250. dict[MINUTE_KEY] = minute;
  251. dict[SECOND_KEY] = second;
  252. return dict;
  253. }
  254. String Time::get_datetime_string_from_datetime_dict(const Dictionary &p_datetime, bool p_use_space) const {
  255. ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty.");
  256. EXTRACT_FROM_DICTIONARY
  257. VALIDATE_YMDHMS("")
  258. const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
  259. return vformat(format_string, year, (uint8_t)month, day, hour, minute, second);
  260. }
  261. int64_t Time::get_unix_time_from_datetime_dict(const Dictionary &p_datetime) const {
  262. ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), 0, "Invalid datetime Dictionary: Dictionary is empty");
  263. EXTRACT_FROM_DICTIONARY
  264. VALIDATE_YMDHMS(0)
  265. YMD_TO_DAY_NUMBER
  266. return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second;
  267. }
  268. int64_t Time::get_unix_time_from_datetime_string(const String &p_datetime) const {
  269. PARSE_ISO8601_STRING(-1)
  270. VALIDATE_YMDHMS(0)
  271. YMD_TO_DAY_NUMBER
  272. return day_number * SECONDS_PER_DAY + hour * 3600 + minute * 60 + second;
  273. }
  274. String Time::get_offset_string_from_offset_minutes(int64_t p_offset_minutes) const {
  275. String sign;
  276. if (p_offset_minutes < 0) {
  277. sign = "-";
  278. p_offset_minutes = -p_offset_minutes;
  279. } else {
  280. sign = "+";
  281. }
  282. // These two lines can be optimized to one instruction on x86 and others.
  283. // Note that % is acceptable here only because we ensure it's positive.
  284. int64_t offset_hours = p_offset_minutes / 60;
  285. int64_t offset_minutes = p_offset_minutes % 60;
  286. return vformat("%s%02d:%02d", sign, offset_hours, offset_minutes);
  287. }
  288. Dictionary Time::get_datetime_dict_from_system(bool p_utc) const {
  289. OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
  290. Dictionary datetime;
  291. datetime[YEAR_KEY] = dt.year;
  292. datetime[MONTH_KEY] = (uint8_t)dt.month;
  293. datetime[DAY_KEY] = dt.day;
  294. datetime[WEEKDAY_KEY] = (uint8_t)dt.weekday;
  295. datetime[HOUR_KEY] = dt.hour;
  296. datetime[MINUTE_KEY] = dt.minute;
  297. datetime[SECOND_KEY] = dt.second;
  298. datetime[DST_KEY] = dt.dst;
  299. return datetime;
  300. }
  301. Dictionary Time::get_date_dict_from_system(bool p_utc) const {
  302. OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
  303. Dictionary date_dictionary;
  304. date_dictionary[YEAR_KEY] = dt.year;
  305. date_dictionary[MONTH_KEY] = (uint8_t)dt.month;
  306. date_dictionary[DAY_KEY] = dt.day;
  307. date_dictionary[WEEKDAY_KEY] = (uint8_t)dt.weekday;
  308. return date_dictionary;
  309. }
  310. Dictionary Time::get_time_dict_from_system(bool p_utc) const {
  311. OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
  312. Dictionary time_dictionary;
  313. time_dictionary[HOUR_KEY] = dt.hour;
  314. time_dictionary[MINUTE_KEY] = dt.minute;
  315. time_dictionary[SECOND_KEY] = dt.second;
  316. return time_dictionary;
  317. }
  318. String Time::get_datetime_string_from_system(bool p_utc, bool p_use_space) const {
  319. OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
  320. const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
  321. return vformat(format_string, dt.year, (uint8_t)dt.month, dt.day, dt.hour, dt.minute, dt.second);
  322. }
  323. String Time::get_date_string_from_system(bool p_utc) const {
  324. OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
  325. // Android is picky about the types passed to make Variant, so we need a cast.
  326. return vformat("%04d-%02d-%02d", dt.year, (uint8_t)dt.month, dt.day);
  327. }
  328. String Time::get_time_string_from_system(bool p_utc) const {
  329. OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
  330. return vformat("%02d:%02d:%02d", dt.hour, dt.minute, dt.second);
  331. }
  332. Dictionary Time::get_time_zone_from_system() const {
  333. OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
  334. Dictionary ret_timezone;
  335. ret_timezone["bias"] = info.bias;
  336. ret_timezone["name"] = info.name;
  337. return ret_timezone;
  338. }
  339. double Time::get_unix_time_from_system() const {
  340. return OS::get_singleton()->get_unix_time();
  341. }
  342. uint64_t Time::get_ticks_msec() const {
  343. return OS::get_singleton()->get_ticks_msec();
  344. }
  345. uint64_t Time::get_ticks_usec() const {
  346. return OS::get_singleton()->get_ticks_usec();
  347. }
  348. void Time::_bind_methods() {
  349. ClassDB::bind_method(D_METHOD("get_datetime_dict_from_unix_time", "unix_time_val"), &Time::get_datetime_dict_from_unix_time);
  350. ClassDB::bind_method(D_METHOD("get_date_dict_from_unix_time", "unix_time_val"), &Time::get_date_dict_from_unix_time);
  351. ClassDB::bind_method(D_METHOD("get_time_dict_from_unix_time", "unix_time_val"), &Time::get_time_dict_from_unix_time);
  352. 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));
  353. ClassDB::bind_method(D_METHOD("get_date_string_from_unix_time", "unix_time_val"), &Time::get_date_string_from_unix_time);
  354. ClassDB::bind_method(D_METHOD("get_time_string_from_unix_time", "unix_time_val"), &Time::get_time_string_from_unix_time);
  355. ClassDB::bind_method(D_METHOD("get_datetime_dict_from_datetime_string", "datetime", "weekday"), &Time::get_datetime_dict_from_datetime_string);
  356. ClassDB::bind_method(D_METHOD("get_datetime_string_from_datetime_dict", "datetime", "use_space"), &Time::get_datetime_string_from_datetime_dict);
  357. ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_dict", "datetime"), &Time::get_unix_time_from_datetime_dict);
  358. ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime_string", "datetime"), &Time::get_unix_time_from_datetime_string);
  359. ClassDB::bind_method(D_METHOD("get_offset_string_from_offset_minutes", "offset_minutes"), &Time::get_offset_string_from_offset_minutes);
  360. ClassDB::bind_method(D_METHOD("get_datetime_dict_from_system", "utc"), &Time::get_datetime_dict_from_system, DEFVAL(false));
  361. ClassDB::bind_method(D_METHOD("get_date_dict_from_system", "utc"), &Time::get_date_dict_from_system, DEFVAL(false));
  362. ClassDB::bind_method(D_METHOD("get_time_dict_from_system", "utc"), &Time::get_time_dict_from_system, DEFVAL(false));
  363. ClassDB::bind_method(D_METHOD("get_datetime_string_from_system", "utc", "use_space"), &Time::get_datetime_string_from_system, DEFVAL(false), DEFVAL(false));
  364. ClassDB::bind_method(D_METHOD("get_date_string_from_system", "utc"), &Time::get_date_string_from_system, DEFVAL(false));
  365. ClassDB::bind_method(D_METHOD("get_time_string_from_system", "utc"), &Time::get_time_string_from_system, DEFVAL(false));
  366. ClassDB::bind_method(D_METHOD("get_time_zone_from_system"), &Time::get_time_zone_from_system);
  367. ClassDB::bind_method(D_METHOD("get_unix_time_from_system"), &Time::get_unix_time_from_system);
  368. ClassDB::bind_method(D_METHOD("get_ticks_msec"), &Time::get_ticks_msec);
  369. ClassDB::bind_method(D_METHOD("get_ticks_usec"), &Time::get_ticks_usec);
  370. BIND_ENUM_CONSTANT(MONTH_JANUARY);
  371. BIND_ENUM_CONSTANT(MONTH_FEBRUARY);
  372. BIND_ENUM_CONSTANT(MONTH_MARCH);
  373. BIND_ENUM_CONSTANT(MONTH_APRIL);
  374. BIND_ENUM_CONSTANT(MONTH_MAY);
  375. BIND_ENUM_CONSTANT(MONTH_JUNE);
  376. BIND_ENUM_CONSTANT(MONTH_JULY);
  377. BIND_ENUM_CONSTANT(MONTH_AUGUST);
  378. BIND_ENUM_CONSTANT(MONTH_SEPTEMBER);
  379. BIND_ENUM_CONSTANT(MONTH_OCTOBER);
  380. BIND_ENUM_CONSTANT(MONTH_NOVEMBER);
  381. BIND_ENUM_CONSTANT(MONTH_DECEMBER);
  382. BIND_ENUM_CONSTANT(WEEKDAY_SUNDAY);
  383. BIND_ENUM_CONSTANT(WEEKDAY_MONDAY);
  384. BIND_ENUM_CONSTANT(WEEKDAY_TUESDAY);
  385. BIND_ENUM_CONSTANT(WEEKDAY_WEDNESDAY);
  386. BIND_ENUM_CONSTANT(WEEKDAY_THURSDAY);
  387. BIND_ENUM_CONSTANT(WEEKDAY_FRIDAY);
  388. BIND_ENUM_CONSTANT(WEEKDAY_SATURDAY);
  389. }
  390. Time::Time() {
  391. ERR_FAIL_COND_MSG(singleton, "Singleton for Time already exists.");
  392. singleton = this;
  393. }
  394. Time::~Time() {
  395. singleton = nullptr;
  396. }