MCPcopy Create free account
hub / github.com/derceg/explorerplusplus / CreateFriendlySystemTimeString

Function CreateFriendlySystemTimeString

Explorer++/Helper/Helper.cpp:70–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70BOOL CreateFriendlySystemTimeString(const SYSTEMTIME *localSystemTime,
71 TCHAR *szBuffer, size_t cchMax)
72{
73 using namespace boost::gregorian;
74 using namespace boost::posix_time;
75
76 FILETIME localFileTime;
77 BOOL ret = SystemTimeToFileTime(localSystemTime, &localFileTime);
78
79 if (!ret)
80 {
81 return FALSE;
82 }
83
84 TCHAR dateComponent[512];
85 bool dateComponentSet = false;
86
87 auto inputPosixTime = from_ftime<ptime>(localFileTime);
88 date inputDate = inputPosixTime.date();
89
90 date today = day_clock::local_day();
91 date yesterday = today - days(1);
92
93 if (inputDate == today)
94 {
95 StringCchCopy(dateComponent, SIZEOF_ARRAY(dateComponent), _T("Today"));
96 dateComponentSet = true;
97 }
98 else if (inputDate == yesterday)
99 {
100 StringCchCopy(dateComponent, SIZEOF_ARRAY(dateComponent), _T("Yesterday"));
101 dateComponentSet = true;
102 }
103
104 if (!dateComponentSet)
105 {
106 return FALSE;
107 }
108
109 TCHAR timeComponent[512];
110 int timeFormatted = GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_USE_CP_ACP, localSystemTime,
111 NULL, timeComponent, SIZEOF_ARRAY(timeComponent));
112
113 if (timeFormatted == 0)
114 {
115 return FALSE;
116 }
117
118 HRESULT hr = StringCchPrintf(szBuffer, cchMax, _T("%s, %s"), dateComponent, timeComponent);
119
120 if (SUCCEEDED(hr))
121 {
122 return TRUE;
123 }
124
125 return FALSE;
126}
127

Callers 1

CreateSystemTimeStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected