Ver código fonte

Merge pull request #103939 from aaronp64/time_vformat

Remove outdated `vformat` comments/workarounds in `time.cpp`
Thaddeus Crews 6 meses atrás
pai
commit
7893202fba
1 arquivos alterados com 6 adições e 26 exclusões
  1. 6 26
      core/os/time.cpp

+ 6 - 26
core/os/time.cpp

@@ -233,15 +233,8 @@ Dictionary Time::get_time_dict_from_unix_time(int64_t p_unix_time_val) const {
 String Time::get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space) const {
 	UNIX_TIME_TO_HMS
 	UNIX_TIME_TO_YMD
-	// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
-	String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
-	if (p_use_space) {
-		timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second);
-	} else {
-		timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second);
-	}
-
-	return timestamp;
+	const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
+	return vformat(format_string, year, (uint8_t)month, day, hour, minute, second);
 }
 
 String Time::get_date_string_from_unix_time(int64_t p_unix_time_val) const {
@@ -277,14 +270,8 @@ String Time::get_datetime_string_from_datetime_dict(const Dictionary &p_datetime
 	ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty.");
 	EXTRACT_FROM_DICTIONARY
 	VALIDATE_YMDHMS("")
-	// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
-	String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
-	if (p_use_space) {
-		timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second);
-	} else {
-		timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second);
-	}
-	return timestamp;
+	const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
+	return vformat(format_string, year, (uint8_t)month, day, hour, minute, second);
 }
 
 int64_t Time::get_unix_time_from_datetime_dict(const Dictionary &p_datetime) const {
@@ -352,15 +339,8 @@ Dictionary Time::get_time_dict_from_system(bool p_utc) const {
 
 String Time::get_datetime_string_from_system(bool p_utc, bool p_use_space) const {
 	OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
-	// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
-	String timestamp = vformat("%04d-%02d-%02d", dt.year, (uint8_t)dt.month, dt.day);
-	if (p_use_space) {
-		timestamp = vformat("%s %02d:%02d:%02d", timestamp, dt.hour, dt.minute, dt.second);
-	} else {
-		timestamp = vformat("%sT%02d:%02d:%02d", timestamp, dt.hour, dt.minute, dt.second);
-	}
-
-	return timestamp;
+	const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
+	return vformat(format_string, dt.year, (uint8_t)dt.month, dt.day, dt.hour, dt.minute, dt.second);
 }
 
 String Time::get_date_string_from_system(bool p_utc) const {