Skip to content

Commit fe42d2d

Browse files
committed
Add year to all 'long' form date strings from PI. After discussing it with Daniel in IRC it was decided not to wait until 0.26 to fix this properly. As implemented the year will only be added to the strings if the date falls outside the current year.
1 parent 0a57c46 commit fe42d2d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

mythtv/libs/libmyth/programinfo.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,11 +1405,11 @@ void ProgramInfo::ToMap(InfoMap &progMap,
14051405
else // if (IsRecording())
14061406
{
14071407
progMap["starttime"] = MythDateTimeToString(startts, kTime);
1408-
progMap["startdate"] = MythDateTimeToString(startts, kDateFull | kSimplify);
1408+
progMap["startdate"] = MythDateTimeToString(startts, kDateFull | kAddYear | kSimplify);
14091409
progMap["shortstartdate"] = MythDateTimeToString(startts, kDateShort);
14101410
progMap["startyear"] = startts.toString("yyyy");
14111411
progMap["endtime"] = MythDateTimeToString(endts, kTime);
1412-
progMap["enddate"] = MythDateTimeToString(endts, kDateFull | kSimplify);
1412+
progMap["enddate"] = MythDateTimeToString(endts, kDateFull | kAddYear | kSimplify);
14131413
progMap["shortenddate"] = MythDateTimeToString(endts, kDateShort);
14141414
progMap["endyear"] = endts.toString("yyyy");
14151415
progMap["recstarttime"] = MythDateTimeToString(recstartts, kTime);
@@ -1421,24 +1421,24 @@ void ProgramInfo::ToMap(InfoMap &progMap,
14211421
}
14221422

14231423
progMap["timedate"] = MythDateTimeToString(recstartts,
1424-
kDateTimeFull | kSimplify) + " - " +
1424+
kDateTimeFull | kAddYear | kSimplify) + " - " +
14251425
MythDateTimeToString(recendts, kTime);
14261426

14271427
progMap["shorttimedate"] = MythDateTimeToString(recstartts,
14281428
kDateTimeShort | kSimplify) + " - " +
14291429
MythDateTimeToString(recendts, kTime);
14301430

14311431
progMap["starttimedate"] = MythDateTimeToString(recstartts,
1432-
kDateTimeFull | kSimplify);
1432+
kDateTimeFull | kAddYear | kSimplify);
14331433

14341434
progMap["shortstarttimedate"] = MythDateTimeToString(recstartts,
14351435
kDateTimeShort | kSimplify);
14361436

14371437
progMap["lastmodifiedtime"] = MythDateTimeToString(lastmodified, kTime);
14381438
progMap["lastmodifieddate"] = MythDateTimeToString(lastmodified,
1439-
kDateFull | kSimplify);
1439+
kDateFull | kAddYear | kSimplify);
14401440
progMap["lastmodified"] = MythDateTimeToString(lastmodified,
1441-
kDateTimeFull | kSimplify);
1441+
kDateTimeFull | kAddYear | kSimplify);
14421442

14431443
progMap["channum"] = chanstr;
14441444
progMap["chanid"] = chanid;

mythtv/libs/libmythbase/util.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ QString MythDateTimeToString(const QDateTime& datetime, uint format)
104104
return result;
105105
}
106106

107+
static QRegExp stripYear("(\.|-|/)?(yyyy|yy)(\.|-|/)?");
108+
107109
/** \fn MythDateToString
108110
* \brief Returns a formatted QString based on the supplied QDate
109111
*
@@ -124,20 +126,27 @@ QString MythDateToString(const QDate& date, uint format)
124126
else
125127
stringformat = gCoreContext->GetSetting("DateFormat", "ddd d MMMM");
126128

127-
if (format & kAddYear)
129+
if ((format & kAddYear) && (format & ~kSimplify))
128130
{
129131
if (!stringformat.contains("yy")) // Matches both 2 or 4 digit year
130132
stringformat.append(" yyyy");
131133
}
132134

133-
if (format & ~kDateShort)
135+
if ((format & ~kDateShort) && (format & kSimplify))
134136
{
135-
if ((format & kSimplify) && (now == date))
137+
if (now == date)
136138
result = QObject::tr("Today");
137-
else if ((format & kSimplify) && (now.addDays(-1) == date))
139+
else if (now.addDays(-1) == date)
138140
result = QObject::tr("Yesterday");
139-
else if ((format & kSimplify) && (now.addDays(1) == date))
141+
else if (now.addDays(1) == date)
140142
result = QObject::tr("Tomorrow");
143+
else if ((now.year() == date.year()) && stringformat.contains("yy"))
144+
{
145+
// Best effort attempt to strip year when it was already
146+
// present in the string - maybe unnecessary if the user
147+
// explicitly chose a string containing the year?
148+
stringformat.replace(stripYear, "");
149+
}
141150
}
142151

143152
if (result.isEmpty())

0 commit comments

Comments
 (0)