MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / getDisplayString

Method getDisplayString

src/server/gui/core/components/DateTimeComponent.cpp:48–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48std::string DateTimeComponent::getDisplayString() const
49{
50 if (mDisplayRelative) {
51 //relative time
52 if(mTime.getTime() == 0)
53 return "never";
54
55 Utils::Time::DateTime now(Utils::Time::now());
56 Utils::Time::Duration dur(now.getTime() - mTime.getTime());
57
58 char buf[64];
59
60 if(dur.getDays() > 0)
61 sprintf(buf, "%d day%s ago", dur.getDays(), (dur.getDays() > 1) ? "s" : "");
62 else if(dur.getHours() > 0)
63 sprintf(buf, "%d hour%s ago", dur.getHours(), (dur.getHours() > 1) ? "s" : "");
64 else if(dur.getMinutes() > 0)
65 sprintf(buf, "%d minute%s ago", dur.getMinutes(), (dur.getMinutes() > 1) ? "s" : "");
66 else
67 sprintf(buf, "%d second%s ago", dur.getSeconds(), (dur.getSeconds() > 1) ? "s" : "");
68
69 return std::string(buf);
70 }
71
72 if(mTime.getTime() == 0)
73 return "unknown";
74
75 return Utils::Time::timeToString(mTime.getTime(), mFormat);
76}
77
78void DateTimeComponent::render(const Transform4x4f& parentTrans)
79{

Callers

nothing calls this directly

Calls 7

nowFunction · 0.85
timeToStringFunction · 0.85
getTimeMethod · 0.80
getDaysMethod · 0.80
getHoursMethod · 0.80
getMinutesMethod · 0.80
getSecondsMethod · 0.80

Tested by

no test coverage detected