Skip to content

Commit

Permalink
rename MythFormatTime to MythDate::formatTime
Browse files Browse the repository at this point in the history
Signed-off-by: David Hampton <mythtv@love2code.net>
  • Loading branch information
ulmus-scott authored and linuxdude42 committed Dec 28, 2021
1 parent 8d0db23 commit f70050c
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 57 deletions.
3 changes: 2 additions & 1 deletion mythplugins/mytharchive/mytharchive/thumbfinder.cpp
Expand Up @@ -47,6 +47,7 @@
#include <mythdialogbox.h>
#include <mythdirs.h>
#include <mythmiscutil.h>
#include <mythdate.h>
#include <mythuitext.h>
#include <mythuibutton.h>
#include <mythuiimage.h>
Expand Down Expand Up @@ -403,7 +404,7 @@ QString ThumbFinder::frameToTime(int64_t frame, bool addFrame) const
int sec = (int) (frame / m_fps);
frame = frame - (int) (sec * m_fps);

QString str = MythFormatTime(std::chrono::seconds(sec), "HH:mm:ss");
QString str = MythDate::formatTime(std::chrono::seconds(sec), "HH:mm:ss");
if (addFrame)
str += QString(".%1").arg(frame,10,2,QChar('0'));
return str;
Expand Down
4 changes: 2 additions & 2 deletions mythplugins/mythmusic/mythmusic/cdrip.cpp
Expand Up @@ -30,7 +30,7 @@
#include <lcddevice.h>
#include <mythmediamonitor.h>
#include <mythdirs.h>
#include <mythmiscutil.h>
#include <mythdate.h>

// MythUI
#include <mythdialogbox.h>
Expand Down Expand Up @@ -1224,7 +1224,7 @@ void Ripper::updateTrackList(void)

if (track->length >= 1s)
{
item->SetText(MythFormatTime(track->length, "mm:ss"), "length");
item->SetText(MythDate::formatTime(track->length, "mm:ss"), "length");
}
else
item->SetText("", "length");
Expand Down
5 changes: 3 additions & 2 deletions mythplugins/mythmusic/mythmusic/musiccommon.cpp
Expand Up @@ -24,6 +24,7 @@
#include <compat.h>
#include <lcddevice.h>
#include <musicmetadata.h>
#include <mythdate.h>

// MythMusic includes
#include "musicdata.h"
Expand Down Expand Up @@ -2140,11 +2141,11 @@ void MusicCommon::updatePlaylistStats(void)
QString MusicCommon::getTimeString(std::chrono::seconds exTime, std::chrono::seconds maxTime)
{
if (maxTime <= 0ms)
return MythFormatTime(exTime,
return MythDate::formatTime(exTime,
(exTime >= 1h) ? "H:mm:ss" : "mm:ss");

QString fmt = (maxTime >= 1h) ? "H:mm:ss" : "mm:ss";
return MythFormatTime(exTime, fmt) + " / " + MythFormatTime(maxTime, fmt);
return MythDate::formatTime(exTime, fmt) + " / " + MythDate::formatTime(maxTime, fmt);
}

void MusicCommon::searchButtonList(void)
Expand Down
21 changes: 20 additions & 1 deletion mythtv/libs/libmythbase/mythdate.h
Expand Up @@ -60,6 +60,25 @@ MBASE_PUBLIC std::chrono::milliseconds currentMSecsSinceEpochAsDuration(void);
MBASE_PUBLIC std::chrono::seconds secsInPast (const QDateTime& past);
MBASE_PUBLIC std::chrono::seconds secsInFuture (const QDateTime& future);

};
/**
* \brief Format a milliseconds time value
*
* Convert a millisecond time value into a textual representation of the value.
*
* \param msecs The time value in milliseconds. Since the type of this
* field is std::chrono::duration, any duration of a larger
* interval can be passed to this function and the compiler will
* convert it to milliseconds.
*
* \param fmt A formatting string specifying how to output the time.
* See QTime::toString for the a definition fo valid formatting
* characters.
*/
inline MBASE_PUBLIC QString formatTime(std::chrono::milliseconds msecs, const QString& fmt)
{
return QTime::fromMSecsSinceStartOfDay(msecs.count()).toString(fmt);
}

} // namespace MythDate

#endif // MYTH_DATE_H
5 changes: 0 additions & 5 deletions mythtv/libs/libmythbase/mythmiscutil.cpp
Expand Up @@ -1235,11 +1235,6 @@ int naturalCompare(const QString &_a, const QString &_b, Qt::CaseSensitivity cas
return currA->isNull() ? -1 : + 1;
}

QString MythFormatTime(std::chrono::milliseconds msecs, const QString& fmt)
{
return QTime::fromMSecsSinceStartOfDay(msecs.count()).toString(fmt);
}

/*
* States for the command line parser.
*/
Expand Down
16 changes: 0 additions & 16 deletions mythtv/libs/libmythbase/mythmiscutil.h
Expand Up @@ -105,22 +105,6 @@ MBASE_PUBLIC void setHttpProxy(void);
MBASE_PUBLIC int naturalCompare(const QString &_a, const QString &_b,
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);

/**
* \brief Format a milliseconds time value
*
* Convert a millisecond time value into a textual representation of the value.
*
* \param msecs The time value in milliseconds. Since the type of this
* field is std::chrono::duration, any duration of a larger
* interval can be passed to this function and the compiler will
* convert it to milliseconds.
*
* \param fmt A formatting string specifying how to output the time.
* See QTime::toString for the a definition fo valid formatting
* characters.
*/
MBASE_PUBLIC QString MythFormatTime(std::chrono::milliseconds msecs, const QString& fmt);

// CPU Tick timing function
#ifdef MMX
#ifdef _WIN32
Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythmetadata/lyricsdata.h
Expand Up @@ -12,7 +12,7 @@
#include "mythmetaexp.h"
#include "mythcorecontext.h"
#include "musicmetadata.h"
#include "mythmiscutil.h"
#include "mythdate.h"

class LyricsData;
class TestLyrics;
Expand All @@ -38,7 +38,7 @@ class META_PUBLIC LyricsLine
private:
QString formatTime(void) const
{
QString timestr = MythFormatTime(m_time,"mm:ss.zzz");
QString timestr = MythDate::formatTime(m_time,"mm:ss.zzz");
timestr.chop(1); // Chop 1 to return hundredths
return QString("[%1]").arg(timestr);
}
Expand Down
3 changes: 1 addition & 2 deletions mythtv/libs/libmythmetadata/musicmetadata.cpp
Expand Up @@ -21,7 +21,6 @@
#include "storagegroup.h"
#include "mythsystem.h"
#include "mythcoreutil.h"
#include "mythmiscutil.h"

// mythbase
#include "mythsorthelper.h"
Expand Down Expand Up @@ -1116,7 +1115,7 @@ void MusicMetadata::toMap(InfoMap &metadataMap, const QString &prefix)
metadataMap[prefix + "year"] = (m_year > 0 ? QString("%1").arg(m_year) : "");

QString fmt = (m_length >= 1h) ? "H:mm:ss" : "mm:ss";
metadataMap[prefix + "length"] = MythFormatTime(m_length, fmt);
metadataMap[prefix + "length"] = MythDate::formatTime(m_length, fmt);

if (m_lastPlay.isValid())
{
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/AirPlay/mythairplayserver.cpp
Expand Up @@ -18,6 +18,7 @@
#include <QUrlQuery>

#include "mthread.h"
#include "mythmiscutil.h"
#include "mythdate.h"
#include "mythlogging.h"
#include "mythcorecontext.h"
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/Bluray/mythbdbuffer.cpp
Expand Up @@ -11,7 +11,7 @@
#include "mythlogging.h"
#include "mythcorecontext.h"
#include "mythlocale.h"
#include "mythmiscutil.h"
#include "mythdate.h"
#include "mythdirs.h"
#include "libbluray/bluray.h"
#include "io/mythiowrapper.h"
Expand Down Expand Up @@ -718,7 +718,7 @@ bool MythBDBuffer::UpdateTitleInfo(void)
m_titlesize = bd_get_title_size(m_bdnav);
uint32_t chapter_count = GetNumChapters();
auto total_msecs = duration_cast<std::chrono::milliseconds>(m_currentTitleLength);
auto duration = MythFormatTime(total_msecs, "HH:mm:ss.zzz");
auto duration = MythDate::formatTime(total_msecs, "HH:mm:ss.zzz");
duration.chop(2); // Chop 2 to show tenths
LOG(VB_GENERAL, LOG_INFO, LOC + QString("New title info: Index %1 Playlist: %2 Duration: %3 ""Chapters: %5")
.arg(m_currentTitle).arg(m_currentTitleInfo->playlist).arg(duration).arg(chapter_count));
Expand All @@ -731,7 +731,7 @@ bool MythBDBuffer::UpdateTitleInfo(void)
uint64_t framenum = GetChapterStartFrame(i);
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Chapter %1 found @ [%2]->%3")
.arg(i + 1, 2, 10, QChar('0'))
.arg(MythFormatTime(GetChapterStartTimeMs(i), "HH:mm:ss.zzz"))
.arg(MythDate::formatTime(GetChapterStartTimeMs(i), "HH:mm:ss.zzz"))
.arg(framenum));
}

Expand Down
4 changes: 3 additions & 1 deletion mythtv/libs/libmythtv/Bluray/mythbdplayer.cpp
Expand Up @@ -4,6 +4,8 @@
#include "Bluray/mythbddecoder.h"
#include "Bluray/mythbdplayer.h"

#include "mythdate.h"

// Std
#include <unistd.h>

Expand Down Expand Up @@ -240,7 +242,7 @@ QString MythBDPlayer::GetTitleName(int Title) const
if (Title >= 0 && Title < GetNumTitles())
{
// BD doesn't provide title names, so show title number and duration
QString timestr = MythFormatTime(GetTitleDuration(Title), "HH:mm:ss");
QString timestr = MythDate::formatTime(GetTitleDuration(Title), "HH:mm:ss");
QString name = QString("%1 (%2)").arg(Title+1).arg(timestr);
return name;
}
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/commbreakmap.cpp
@@ -1,7 +1,7 @@
// MythTV
#include "commbreakmap.h"
#include "mythcontext.h"
#include "mythmiscutil.h"
#include "mythdate.h"
#include "programinfo.h"

#define LOC QString("CommBreakMap: ")
Expand Down Expand Up @@ -215,7 +215,7 @@ bool CommBreakMap::AutoCommercialSkip(uint64_t &jumpToFrame,

auto skipped_seconds = std::chrono::seconds((int)((m_commBreakIter.key() -
framesPlayed) / video_frame_rate));
QString skipTime = MythFormatTime(skipped_seconds, "m:ss");
QString skipTime = MythDate::formatTime(skipped_seconds, "m:ss");
if (kCommSkipOn == m_autocommercialskip)
{
//: %1 is the skip time
Expand Down Expand Up @@ -335,7 +335,7 @@ bool CommBreakMap::DoSkipCommercials(uint64_t &jumpToFrame,
MergeShortCommercials(video_frame_rate);
int64_t framediff = m_commBreakIter.key() - framesPlayed;
auto skipped_seconds = std::chrono::seconds((int)(framediff / video_frame_rate));
QString skipTime = MythFormatTime(skipped_seconds, "m:ss");
QString skipTime = MythDate::formatTime(skipped_seconds, "m:ss");

if ((MythDate::secsInPast(m_lastIgnoredManualSkip) > 3s) &&
(abs(skipped_seconds) >= m_maxskip))
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Expand Up @@ -69,6 +69,7 @@ extern "C" {
#include "io/mythmediabuffer.h"
#include "mythframe.h"
#include "mythchrono.h"
#include "mythdate.h"
#include "remoteencoder.h"
#include "mythcorecontext.h"
#include "mythdbcon.h"
Expand Down Expand Up @@ -1264,7 +1265,7 @@ int AvFormatDecoder::OpenFile(MythMediaBuffer *Buffer, bool novideo,
LOG(VB_PLAYBACK, LOG_INFO, LOC +
QString("Chapter %1 found @ [%2]->%3")
.arg(i + 1, 2,10,QChar('0'))
.arg(MythFormatTime(msec, "HH:mm:ss.zzz"))
.arg(MythDate::formatTime(msec, "HH:mm:ss.zzz"))
.arg(framenum));
}

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/deletemap.cpp
Expand Up @@ -8,7 +8,7 @@
#include "mythplayer.h"
#include "programinfo.h"
#include "mythcorecontext.h" // for MythCoreContext, etc
#include "mythmiscutil.h"
#include "mythdate.h"
#include "mythtypes.h" // for InfoMap
#include "mythuiactions.h" // for ACTION_DOWN, ACTION_UP
#include "playercontext.h" // for PlayerContext
Expand Down Expand Up @@ -167,7 +167,7 @@ QString DeleteMap::CreateTimeString(uint64_t frame, bool use_cutlist,
QString fmt = (ms >= 1h) ? "H:mm:ss" : "mm:ss";
if (full_resolution)
fmt += ".zzz";
return MythFormatTime(ms, fmt);
return MythDate::formatTime(ms, fmt);
}

/**
Expand Down
16 changes: 9 additions & 7 deletions mythtv/libs/libmythtv/mythplayeroverlayui.cpp
Expand Up @@ -5,6 +5,8 @@
#include "livetvchain.h"
#include "mythplayeroverlayui.h"

#include "mythdate.h"

#define LOC QString("PlayerOverlay: ")

// N.B. Overlay is initialised without a player - it must be set before it can be used
Expand Down Expand Up @@ -208,20 +210,20 @@ void MythPlayerOverlayUI::UpdateSliderInfo(osdInfo &Info, bool PaddedFields)
QString text3;
if (PaddedFields)
{
text1 = MythFormatTime(secsplayed, "HH:mm:ss");
text2 = MythFormatTime(playbackLen, "HH:mm:ss");
text3 = MythFormatTime(secsbehind, "HH:mm:ss");
text1 = MythDate::formatTime(secsplayed, "HH:mm:ss");
text2 = MythDate::formatTime(playbackLen, "HH:mm:ss");
text3 = MythDate::formatTime(secsbehind, "HH:mm:ss");
}
else
{
QString fmt = (playbackLen >= 1h) ? "H:mm:ss" : "m:ss";
text1 = MythFormatTime(secsplayed, fmt);
text2 = MythFormatTime(playbackLen, fmt);
text1 = MythDate::formatTime(secsplayed, fmt);
text2 = MythDate::formatTime(playbackLen, fmt);

if (secsbehind >= 1h)
text3 = MythFormatTime(secsbehind, "H:mm:ss");
text3 = MythDate::formatTime(secsbehind, "H:mm:ss");
else if (secsbehind >= 1min)
text3 = MythFormatTime(secsbehind, "m:ss");
text3 = MythDate::formatTime(secsbehind, "m:ss");
else
text3 = tr("%n second(s)", "", static_cast<int>(secsbehind.count()));
}
Expand Down
5 changes: 3 additions & 2 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -23,6 +23,7 @@
#include "compat.h"
#include "mythdirs.h"
#include "mythmedia.h"
#include "mythdate.h"

// libmyth
#include "programinfo.h"
Expand Down Expand Up @@ -6644,7 +6645,7 @@ void TV::ShowLCDDVDInfo()
int totalParts = dvd->NumPartsInTitle();

mainStatus = tr("Title: %1 (%2)").arg(playingTitle)
.arg(MythFormatTime(dvd->GetTotalTimeOfTitle(), "HH:mm"));
.arg(MythDate::formatTime(dvd->GetTotalTimeOfTitle(), "HH:mm"));
subStatus = tr("Chapter: %1/%2").arg(playingPart).arg(totalParts);
}
if ((dvdName != m_lcdCallsign) || (mainStatus != m_lcdTitle) || (subStatus != m_lcdSubtitle))
Expand Down Expand Up @@ -8704,7 +8705,7 @@ bool TV::MenuItemDisplayPlayback(const MythTVMenuItemContext& Context, MythOSDDi
{
QString chapter1 = QString("%1").arg(i+1, size, 10, QChar(48));
QString chapter2 = QString("%1").arg(i+1, 3 , 10, QChar(48));
QString timestr = MythFormatTime(m_tvmChapterTimes[i], "HH:mm:ss");
QString timestr = MythDate::formatTime(m_tvmChapterTimes[i], "HH:mm:ss");
QString desc = chapter1 + QString(" (%1)").arg(timestr);
QString action = prefix + chapter2;
active = (m_tvmCurrentChapter == (i + 1));
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/tv_play.h
Expand Up @@ -34,7 +34,6 @@
#include "osd.h"
#include "playercontext.h"
#include "decoders/decoderbase.h"
#include "mythmiscutil.h"
#include "tvbrowsehelper.h"
#include "mythtvmenu.h"
#include "tvplaybackstate.h"
Expand Down
6 changes: 3 additions & 3 deletions mythtv/programs/mythcommflag/CommDetector2.cpp
Expand Up @@ -15,7 +15,7 @@
#include "compat.h"
#include "mythdb.h"
#include "mythlogging.h"
#include "mythmiscutil.h"
#include "mythdate.h"
#include "mythcommflagplayer.h"
#include "programinfo.h"
#include "channelutil.h"
Expand Down Expand Up @@ -252,13 +252,13 @@ QString frameToTimestamp(long long frameno, float fps)
{
auto ms = millisecondsFromFloat(frameno / fps * 1000);
auto secs = std::chrono::ceil<std::chrono::seconds>(ms);
return MythFormatTime(secs, "hh:mm:ss");
return MythDate::formatTime(secs, "hh:mm:ss");
}

QString frameToTimestampms(long long frameno, float fps)
{
auto ms = millisecondsFromFloat(frameno / fps * 1000);
QString timestr = MythFormatTime(ms, "mm:ss.zzz");
QString timestr = MythDate::formatTime(ms, "mm:ss.zzz");
timestr.chop(1); // Chop 1 to return hundredths
return timestr;
}
Expand Down
1 change: 1 addition & 0 deletions mythtv/programs/mythfrontend/playbackbox.cpp
Expand Up @@ -18,6 +18,7 @@
#include "mythuiprogressbar.h"
#include "mythuibuttonlist.h"
#include "mythcorecontext.h"
#include "mythmiscutil.h"
#include "mythmainwindow.h" // for GetMythMainWindow, etc
#include "mythscreenstack.h" // for MythScreenStack
#include "mythuistatetype.h"
Expand Down
6 changes: 3 additions & 3 deletions mythtv/programs/mythfrontend/statusbox.cpp
Expand Up @@ -19,7 +19,7 @@
#include "cardutil.h"
#include "recordinginfo.h"

#include "mythmiscutil.h"
#include "mythdate.h"
#include "mythuihelper.h"
#include "mythuibuttonlist.h"
#include "mythuitext.h"
Expand Down Expand Up @@ -1122,9 +1122,9 @@ static QString uptimeStr(std::chrono::seconds uptime)
{
astext = QString("%1, %2")
.arg(StatusBox::tr("%n day(s)", "", days.count()),
MythFormatTime(secs, "H:mm"));
MythDate::formatTime(secs, "H:mm"));
} else {
astext = MythFormatTime(secs, "H:mm:ss");
astext = MythDate::formatTime(secs, "H:mm:ss");
}
return str + astext;
}
Expand Down

0 comments on commit f70050c

Please sign in to comment.