本文整理汇总了C++中CDateTimeSpan类的典型用法代码示例。如果您正苦于以下问题:C++ CDateTimeSpan类的具体用法?C++ CDateTimeSpan怎么用?C++ CDateTimeSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CDateTimeSpan类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetTotalSeconds
static int GetTotalSeconds(const CDateTimeSpan& ts)
{
int hours = ts.GetHours() + ts.GetDays() * 24;
int minutes = ts.GetMinutes() + hours * 60;
return ts.GetSeconds() + minutes * 60;
}
示例2: Reset
void CGUIEPGGridContainerModel::Refresh(const std::unique_ptr<CFileItemList> &items, const CDateTime &gridStart, const CDateTime &gridEnd, int iRulerUnit, int iBlocksPerPage, float fBlockSize)
{
Reset();
////////////////////////////////////////////////////////////////////////
// Create programme & channel items
m_programmeItems.reserve(items->Size());
CFileItemPtr fileItem;
int iLastChannelID = -1;
ItemsPtr itemsPointer;
itemsPointer.start = 0;
CPVRChannelPtr channel;
int j = 0;
for (int i = 0; i < items->Size(); ++i)
{
fileItem = items->Get(i);
if (!fileItem->HasEPGInfoTag() || !fileItem->GetEPGInfoTag()->HasPVRChannel())
continue;
m_programmeItems.emplace_back(fileItem);
channel = fileItem->GetEPGInfoTag()->ChannelTag();
if (!channel)
continue;
int iCurrentChannelID = channel->ChannelID();
if (iCurrentChannelID != iLastChannelID)
{
if (j > 0)
{
itemsPointer.stop = j - 1;
m_epgItemsPtr.emplace_back(itemsPointer);
itemsPointer.start = j;
}
iLastChannelID = iCurrentChannelID;
m_channelItems.emplace_back(CFileItemPtr(new CFileItem(channel)));
}
++j;
}
if (!m_programmeItems.empty())
{
itemsPointer.stop = m_programmeItems.size() - 1;
m_epgItemsPtr.emplace_back(itemsPointer);
}
/* check for invalid start and end time */
if (gridStart >= gridEnd)
{
// default to start "now minus 30 minutes" and end "start plus one page".
m_gridStart = CDateTime::GetCurrentDateTime().GetAsUTCDateTime() - CDateTimeSpan(0, 0, 30, 0);
m_gridEnd = m_gridStart + CDateTimeSpan(0, 0, iBlocksPerPage * MINSPERBLOCK, 0);
}
else
{
m_gridStart = CDateTime(gridStart.GetYear(), gridStart.GetMonth(), gridStart.GetDay(), gridStart.GetHour(), gridStart.GetMinute() >= 30 ? 30 : 0, 0);
m_gridEnd = CDateTime(gridEnd.GetYear(), gridEnd.GetMonth(), gridEnd.GetDay(), gridEnd.GetHour(), gridEnd.GetMinute() >= 30 ? 30 : 0, 0);
}
////////////////////////////////////////////////////////////////////////
// Create ruler items
CDateTime ruler;
ruler.SetFromUTCDateTime(m_gridStart);
CDateTime rulerEnd;
rulerEnd.SetFromUTCDateTime(m_gridEnd);
CFileItemPtr rulerItem(new CFileItem(ruler.GetAsLocalizedDate(true)));
rulerItem->SetProperty("DateLabel", true);
m_rulerItems.emplace_back(rulerItem);
const CDateTimeSpan unit(0, 0, iRulerUnit * MINSPERBLOCK, 0);
for (; ruler < rulerEnd; ruler += unit)
{
rulerItem.reset(new CFileItem(ruler.GetAsLocalizedTime("", false)));
rulerItem->SetLabel2(ruler.GetAsLocalizedDate(true));
m_rulerItems.emplace_back(rulerItem);
}
FreeItemsMemory();
////////////////////////////////////////////////////////////////////////
// Create epg grid
const CDateTimeSpan blockDuration(0, 0, MINSPERBLOCK, 0);
const CDateTimeSpan gridDuration(m_gridEnd - m_gridStart);
m_blocks = (gridDuration.GetDays() * 24 * 60 + gridDuration.GetHours() * 60 + gridDuration.GetMinutes()) / MINSPERBLOCK;
if (m_blocks >= MAXBLOCKS)
m_blocks = MAXBLOCKS;
m_gridIndex.reserve(m_channelItems.size());
const std::vector<GridItem> blocks(m_blocks);
for (size_t channel = 0; channel < m_channelItems.size(); ++channel)
{
m_gridIndex.emplace_back(blocks);
CDateTime gridCursor(m_gridStart); //reset cursor for new channel
unsigned long progIdx = m_epgItemsPtr[channel].start;
unsigned long lastIdx = m_epgItemsPtr[channel].stop;
int iEpgId = m_programmeItems[progIdx]->GetEPGInfoTag()->EpgID();
int itemSize = 1; // size of the programme in blocks
int savedBlock = 0;
CFileItemPtr item;
//.........这里部分代码省略.........
示例3: time
bool CMythDirectory::GetGuideForChannel(const CStdString& base, CFileItemList &items, int channelNumber)
{
cmyth_database_t database = m_session->GetDatabase();
if (!database)
{
CLog::Log(LOGERROR, "%s - Could not get database", __FUNCTION__);
return false;
}
time_t now;
time(&now);
time_t end = now + (24 * 60 * 60); // How many seconds of EPG from now we should grab, 24 hours in seconds
cmyth_program_t *program = NULL;
// TODO: See if there is a way to just get the entries for the chosen channel rather than ALL
int count = m_dll->mysql_get_guide(database, &program, now, end);
CLog::Log(LOGDEBUG, "%s - %i entries in guide data", __FUNCTION__, count);
if (count <= 0)
return false;
for (int i = 0; i < count; i++)
{
if (program[i].channum == channelNumber)
{
CFileItemPtr item(new CFileItem("", false)); // No path for guide entries
/*
* Set the FileItem meta data.
*/
CStdString title = program[i].title; // e.g. Mythbusters
CStdString subtitle = program[i].subtitle; // e.g. The Pirate Special
CDateTime localstart;
if (program[i].starttime)
localstart = CTimeUtils::GetLocalTime(program[i].starttime);
item->m_strTitle.Format("%s - %s", localstart.GetAsLocalizedTime("HH:mm", false), title); // e.g. 20:30 - Mythbusters
if (!subtitle.IsEmpty())
item->m_strTitle += " - \"" + subtitle + "\""; // e.g. 20:30 - Mythbusters - "The Pirate Special"
item->m_dateTime = localstart;
/*
* Set the VideoInfoTag meta data so it matches the FileItem meta data where possible.
*/
CVideoInfoTag* tag = item->GetVideoInfoTag();
tag->m_strTitle = title;
if (!subtitle.IsEmpty())
tag->m_strTitle += " - \"" + subtitle + "\""; // e.g. Mythbusters - "The Pirate Special"
tag->m_strShowTitle = title;
tag->m_strOriginalTitle = title;
tag->m_strPlotOutline = subtitle;
tag->m_strPlot = program[i].description;
// TODO: Strip out the subtitle from the description if it is present at the start?
// TODO: Do we need to add the subtitle to the start of the plot if not already as it used to? Seems strange, should be handled by skin?
tag->m_genre = StringUtils::Split(program[i].category, g_advancedSettings.m_videoItemSeparator); // e.g. Sports
tag->m_strAlbum = program[i].callsign; // e.g. TV3
CDateTime start(program[i].starttime);
CDateTime end(program[i].endtime);
CDateTimeSpan runtime = end - start;
tag->m_duration = runtime.GetSeconds() + runtime.GetMinutes() * 60 + runtime.GetHours() * 3600;
tag->m_iSeason = 0; // So XBMC treats the content as an episode and displays tag information.
tag->m_iEpisode = 0;
items.Add(item);
}
}
/*
* Items are sorted as added to the list (in ascending date order). Specifying sorting by date can
* result in the guide being shown in the wrong order for skins that sort by date in descending
* order by default with no option to change to ascending, e.g. Confluence.
*/
items.AddSortMethod(SORT_METHOD_NONE, 552 /* Date */, LABEL_MASKS("%K", "%J")); // Still leave the date label
m_dll->ref_release(program);
return true;
}
示例4: time
bool CCMythDirectory::GetGuideForChannel(const CStdString& base, CFileItemList &items, int channelNumber)
{
cmyth_database_t database = m_session->GetDatabase();
if (!database)
{
CLog::Log(LOGERROR, "%s - Could not get database", __FUNCTION__);
return false;
}
time_t now;
time(&now);
// this sets how many seconds of EPG from now we should grab
time_t end = now + (1 * 24 * 60 * 60);
cmyth_program_t *program = NULL;
int count = m_dll->mysql_get_guide(database, &program, now, end);
CLog::Log(LOGDEBUG, "%s - %i entries of guide data", __FUNCTION__, count);
if (count <= 0)
return false;
for (int i = 0; i < count; i++)
{
if (program[i].channum == channelNumber)
{
CStdString path;
path.Format("%s%s", base.c_str(), program[i].title);
CDateTime starttime(program[i].starttime);
CDateTime endtime(program[i].endtime);
CStdString title;
title.Format("%s - %s", starttime.GetAsLocalizedTime("HH:mm", false), program[i].title);
CFileItemPtr item(new CFileItem(title, false));
item->SetLabel(title);
item->m_dateTime = starttime;
CVideoInfoTag* tag = item->GetVideoInfoTag();
tag->m_strAlbum = GetValue(program[i].callsign);
tag->m_strShowTitle = GetValue(program[i].title);
tag->m_strPlotOutline = GetValue(program[i].subtitle);
tag->m_strPlot = GetValue(program[i].description);
tag->m_strGenre = GetValue(program[i].category);
if(tag->m_strPlot.Left(tag->m_strPlotOutline.length()) != tag->m_strPlotOutline && !tag->m_strPlotOutline.IsEmpty())
tag->m_strPlot = tag->m_strPlotOutline + '\n' + tag->m_strPlot;
tag->m_strOriginalTitle = tag->m_strShowTitle;
tag->m_strTitle = tag->m_strAlbum;
if(tag->m_strShowTitle.length() > 0)
tag->m_strTitle += " : " + tag->m_strShowTitle;
CDateTimeSpan runtime = endtime - starttime;
StringUtils::SecondsToTimeString( runtime.GetSeconds()
+ runtime.GetMinutes() * 60
+ runtime.GetHours() * 3600, tag->m_strRuntime);
tag->m_iSeason = 0; /* set this so xbmc knows it's a tv show */
tag->m_iEpisode = 0;
tag->m_strStatus = program[i].rec_status;
items.Add(item);
}
}
// Sort by date only.
items.AddSortMethod(SORT_METHOD_DATE, 552 /* Date */, LABEL_MASKS("%L", "%J", "%L", ""));
m_dll->ref_release(program);
return true;
}
示例5: bReturn
bool CPVRManager::CanSystemPowerdown(bool bAskUser /*= true*/) const
{
bool bReturn(true);
if (IsStarted())
{
CPVRTimerInfoTagPtr cause;
if (!AllLocalBackendsIdle(cause))
{
if (bAskUser)
{
std::string text;
if (cause)
{
if (cause->IsRecording())
{
text = StringUtils::Format(g_localizeStrings.Get(19691).c_str(), // "PVR is currently recording...."
cause->Title().c_str(),
cause->ChannelName().c_str());
}
else
{
// Next event is due to a local recording.
const CDateTime now(CDateTime::GetUTCDateTime());
const CDateTime start(cause->StartAsUTC());
const CDateTimeSpan prestart(0, 0, cause->MarginStart(), 0);
CDateTimeSpan diff(start - now);
diff -= prestart;
int mins = diff.GetSecondsTotal() / 60;
std::string dueStr;
if (mins > 1)
{
// "%d minutes"
dueStr = StringUtils::Format(g_localizeStrings.Get(19694).c_str(), mins);
}
else
{
// "about a minute"
dueStr = g_localizeStrings.Get(19695);
}
text = StringUtils::Format(g_localizeStrings.Get(19692).c_str(), // "PVR will start recording...."
cause->Title().c_str(),
cause->ChannelName().c_str(),
dueStr.c_str());
}
}
else
{
// Next event is due to automatic daily wakeup of PVR.
const CDateTime now(CDateTime::GetUTCDateTime());
CDateTime dailywakeuptime;
dailywakeuptime.SetFromDBTime(CSettings::GetInstance().GetString(CSettings::SETTING_PVRPOWERMANAGEMENT_DAILYWAKEUPTIME));
dailywakeuptime = dailywakeuptime.GetAsUTCDateTime();
const CDateTimeSpan diff(dailywakeuptime - now);
int mins = diff.GetSecondsTotal() / 60;
std::string dueStr;
if (mins > 1)
{
// "%d minutes"
dueStr = StringUtils::Format(g_localizeStrings.Get(19694).c_str(), mins);
}
else
{
// "about a minute"
dueStr = g_localizeStrings.Get(19695);
}
text = StringUtils::Format(g_localizeStrings.Get(19693).c_str(), // "Daily wakeup is due in...."
dueStr.c_str());
}
// Inform user about PVR being busy. Ask if user wants to powerdown anyway.
bReturn = HELPERS::DialogResponse::YES ==
HELPERS::ShowYesNoDialogText(CVariant{19685}, // "Confirm shutdown"
CVariant{text},
CVariant{222}, // "Shutdown anyway",
CVariant{19696}, // "Cancel"
10000); // timeout value before closing
}
else
bReturn = false; // do not powerdown (busy, but no user interaction requested).
}
}
return bReturn;
}
示例6: if
CStdString CSmartPlaylistRule::GetWhereClause(CDatabase &db, const CStdString& strType) const
{
SEARCH_OPERATOR op = m_operator;
if ((strType == "tvshows" || strType == "episodes") && m_field == FieldYear)
{ // special case for premiered which is a date rather than a year
// TODO: SMARTPLAYLISTS do we really need this, or should we just make this field the premiered date and request a date?
if (op == OPERATOR_EQUALS)
op = OPERATOR_CONTAINS;
else if (op == OPERATOR_DOES_NOT_EQUAL)
op = OPERATOR_DOES_NOT_CONTAIN;
}
CStdString operatorString, negate;
if (GetFieldType(m_field) == TEXTIN_FIELD)
{
if (op == OPERATOR_DOES_NOT_EQUAL)
negate = " NOT";
}
else
{
// the comparison piece
switch (op)
{
case OPERATOR_CONTAINS:
operatorString = " LIKE '%%%s%%'"; break;
case OPERATOR_DOES_NOT_CONTAIN:
negate = " NOT"; operatorString = " LIKE '%%%s%%'"; break;
case OPERATOR_EQUALS:
operatorString = " LIKE '%s'"; break;
case OPERATOR_DOES_NOT_EQUAL:
negate = " NOT"; operatorString = " LIKE '%s'"; break;
case OPERATOR_STARTS_WITH:
operatorString = " LIKE '%s%%'"; break;
case OPERATOR_ENDS_WITH:
operatorString = " LIKE '%%%s'"; break;
case OPERATOR_AFTER:
case OPERATOR_GREATER_THAN:
case OPERATOR_IN_THE_LAST:
operatorString = " > '%s'"; break;
case OPERATOR_BEFORE:
case OPERATOR_LESS_THAN:
case OPERATOR_NOT_IN_THE_LAST:
operatorString = " < '%s'"; break;
case OPERATOR_TRUE:
operatorString = " = 1"; break;
case OPERATOR_FALSE:
negate = " NOT "; operatorString = " = 0"; break;
default:
break;
}
}
// FieldInProgress does not have any values in m_parameter, it works on the operator
if (m_field == FieldInProgress && (strType == "movies" || strType == "episodes"))
return "idFile " + negate + " in (select idFile from bookmark where type = 1)";
// now the query parameter
CStdString wholeQuery;
for (vector<CStdString>::const_iterator it = m_parameter.begin(); it != m_parameter.end(); /* it++ is done further down */)
{
CStdString parameter;
if (GetFieldType(m_field) == TEXTIN_FIELD)
{
CStdStringArray split;
StringUtils::SplitString(*it, ",", split);
for (CStdStringArray::iterator itIn = split.begin(); itIn != split.end(); ++itIn)
{
if (!parameter.IsEmpty())
parameter += ",";
parameter += db.PrepareSQL("'%s'", (*itIn).Trim().c_str());
}
parameter = " IN (" + parameter + ")";
}
else
parameter = db.PrepareSQL(operatorString.c_str(), it->c_str());
if (GetFieldType(m_field) == DATE_FIELD)
{
if (m_operator == OPERATOR_IN_THE_LAST || m_operator == OPERATOR_NOT_IN_THE_LAST)
{ // translate time period
CDateTime date=CDateTime::GetCurrentDateTime();
CDateTimeSpan span;
span.SetFromPeriod(*it);
date-=span;
parameter = db.PrepareSQL(operatorString.c_str(), date.GetAsDBDate().c_str());
}
}
else if (m_field == FieldTime)
{ // translate time to seconds
CStdString seconds; seconds.Format("%i", StringUtils::TimeStringToSeconds(*it));
parameter = db.PrepareSQL(operatorString.c_str(), seconds.c_str());
}
CStdString query;
CStdString table;
if (strType == "songs")
{
table = "songview";
if (m_field == FieldGenre)
//.........这里部分代码省略.........
示例7:
CDateTime CDateTime::operator - (const CDateTimeSpan& dts) const
{
CDateTime dt;
dt.m_nDateTime = m_nDateTime - dts.GetDateTimeSpan();
return dt;
}