Skip to content

Commit

Permalink
Optimize stack usage
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoe8967 committed Jun 19, 2016
1 parent a72cc05 commit afc3b90
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions sming/sming/core/DateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,24 @@ time_t DateTime::toUnixTime()

String DateTime::toShortDateString()
{
char buf[64];
char* buf = new char[64];
sprintf(buf, "%02d.%02d.%d", Day, Month + 1, Year);
return String(buf);
auto result = String(buf);
delete buf;
return result;
}

String DateTime::toShortTimeString(bool includeSeconds /* = false*/)
{
char buf[64];
char* buf = new char[64];
if (includeSeconds)
sprintf(buf, "%02d:%02d:%02d", Hour, Minute, Second);
else
sprintf(buf, "%02d:%02d", Hour, Minute);

return String(buf);
auto result = String(buf);
delete buf;
return result;
}

String DateTime::toFullDateTimeString()
Expand All @@ -142,9 +146,11 @@ String DateTime::toFullDateTimeString()
}

String DateTime::toISO8601() {
char buf[21];
char* buf = new char[21];
sprintf(buf, "%02d-%02d-%02dT%02d:%02d:%02dZ",Year,Month+1,Day,Hour,Minute,Second);
return String(buf);
auto result = String(buf);
delete buf;
return result;
}

void DateTime::addMilliseconds(long add)
Expand Down

0 comments on commit afc3b90

Please sign in to comment.