CString CSPTimeSpan::Format(LPCTSTR pFormat) const // formatting timespans is a little trickier than formatting CSPTimes // * we are only interested in relative time formats, ie. it is illegal // to format anything dealing with absolute time (i.e. years, months, // day of week, day of year, timezones, ...) // * the only valid formats: // %D - # of days -- NEW !!! // %H - hour in 24 hour format // %M - minute (0-59) // %S - seconds (0-59) // %% - percent sign { TCHAR szBuffer[maxTimeBufferSize]; TCHAR ch; LPTSTR pch = szBuffer; while ((ch = *pFormat++) != '\0') { ASSERT(pch < &szBuffer[maxTimeBufferSize]); if (ch == '%') { switch (ch = *pFormat++) { default: ASSERT(FALSE); // probably a bad format character case '%': *pch++ = ch; break; case 'D': pch += wsprintf(pch, _T("%ld"), GetDays()); break; case 'H': pch += wsprintf(pch, _T("%02d"), GetHours()); break; case 'M': pch += wsprintf(pch, _T("%02d"), GetMinutes()); break; case 'S': pch += wsprintf(pch, _T("%02d"), GetSeconds()); break; } } else { *pch++ = ch; if (_istlead(ch)) { ASSERT(pch < &szBuffer[maxTimeBufferSize]); *pch++ = *pFormat++; } } } *pch = '\0'; return szBuffer; }
FString FTimespan::ToString( const TCHAR* Format ) const { FString Result; while (*Format != TCHAR('\0')) { if ((*Format == TCHAR('%')) && (*++Format != TCHAR('\0'))) { switch (*Format) { case TCHAR('n'): if (Ticks < 0) Result += TCHAR('-'); break; case TCHAR('N'): Result += (Ticks < 0) ? TCHAR('-') : TCHAR('+'); break; case TCHAR('d'): Result += FString::Printf(TEXT("%i"), FMath::Abs(GetDays())); break; case TCHAR('h'): Result += FString::Printf(TEXT("%02i"), FMath::Abs(GetHours())); break; case TCHAR('m'): Result += FString::Printf(TEXT("%02i"), FMath::Abs(GetMinutes())); break; case TCHAR('s'): Result += FString::Printf(TEXT("%02i"), FMath::Abs(GetSeconds())); break; case TCHAR('f'): Result += FString::Printf(TEXT("%03i"), FMath::Abs(GetMilliseconds())); break; case TCHAR('D'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalDays())); break; case TCHAR('H'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalHours())); break; case TCHAR('M'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalMinutes())); break; case TCHAR('S'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalSeconds())); break; case TCHAR('F'): Result += FString::Printf(TEXT("%f"), FMath::Abs(GetTotalMilliseconds())); break; default: Result += *Format; } } else { Result += *Format; } ++Format; } return Result; }
void HourMinutes::SetDuration(TMinutes const duration) { SetHours(std::chrono::duration_cast<THours>(duration)); SetMinutes(duration - GetHours()); }