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