Skip to content

Commit 7893202

Browse files
committed
Merge pull request #103939 from aaronp64/time_vformat
Remove outdated `vformat` comments/workarounds in `time.cpp`
2 parents 1aefcf7 + a7d0724 commit 7893202

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

core/os/time.cpp

+6-26
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,8 @@ Dictionary Time::get_time_dict_from_unix_time(int64_t p_unix_time_val) const {
233233
String Time::get_datetime_string_from_unix_time(int64_t p_unix_time_val, bool p_use_space) const {
234234
UNIX_TIME_TO_HMS
235235
UNIX_TIME_TO_YMD
236-
// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
237-
String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
238-
if (p_use_space) {
239-
timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second);
240-
} else {
241-
timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second);
242-
}
243-
244-
return timestamp;
236+
const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
237+
return vformat(format_string, year, (uint8_t)month, day, hour, minute, second);
245238
}
246239

247240
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
277270
ERR_FAIL_COND_V_MSG(p_datetime.is_empty(), "", "Invalid datetime Dictionary: Dictionary is empty.");
278271
EXTRACT_FROM_DICTIONARY
279272
VALIDATE_YMDHMS("")
280-
// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
281-
String timestamp = vformat("%04d-%02d-%02d", year, (uint8_t)month, day);
282-
if (p_use_space) {
283-
timestamp = vformat("%s %02d:%02d:%02d", timestamp, hour, minute, second);
284-
} else {
285-
timestamp = vformat("%sT%02d:%02d:%02d", timestamp, hour, minute, second);
286-
}
287-
return timestamp;
273+
const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
274+
return vformat(format_string, year, (uint8_t)month, day, hour, minute, second);
288275
}
289276

290277
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 {
352339

353340
String Time::get_datetime_string_from_system(bool p_utc, bool p_use_space) const {
354341
OS::DateTime dt = OS::get_singleton()->get_datetime(p_utc);
355-
// vformat only supports up to 6 arguments, so we need to split this up into 2 parts.
356-
String timestamp = vformat("%04d-%02d-%02d", dt.year, (uint8_t)dt.month, dt.day);
357-
if (p_use_space) {
358-
timestamp = vformat("%s %02d:%02d:%02d", timestamp, dt.hour, dt.minute, dt.second);
359-
} else {
360-
timestamp = vformat("%sT%02d:%02d:%02d", timestamp, dt.hour, dt.minute, dt.second);
361-
}
362-
363-
return timestamp;
342+
const String format_string = p_use_space ? "%04d-%02d-%02d %02d:%02d:%02d" : "%04d-%02d-%02dT%02d:%02d:%02d";
343+
return vformat(format_string, dt.year, (uint8_t)dt.month, dt.day, dt.hour, dt.minute, dt.second);
364344
}
365345

366346
String Time::get_date_string_from_system(bool p_utc) const {

0 commit comments

Comments
 (0)