logic: Added weekday condition to news API
This commit is contained in:
@@ -49,6 +49,26 @@ std::string TimeStamp::getDDMMYYYYString() const
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string TimeStamp::dayOfWeek() const
|
||||
{
|
||||
switch (m_time.date().day_of_week())
|
||||
{
|
||||
case 0: return "Sunday";
|
||||
case 1: return "Monday";
|
||||
case 2: return "Tuesday";
|
||||
case 3: return "Wednesday";
|
||||
case 4: return "Thursday";
|
||||
case 5: return "Friday";
|
||||
case 6: return "Saturday";
|
||||
}
|
||||
return "none";
|
||||
}
|
||||
|
||||
std::string TimeStamp::dayOfWeekShort() const
|
||||
{
|
||||
return dayOfWeek().substr(0, 3);
|
||||
}
|
||||
|
||||
size_t TimeStamp::deltaMS(const TimeStamp& other) const
|
||||
{
|
||||
return abs((m_time - other.m_time).total_milliseconds());
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
|
||||
std::string toString() const;
|
||||
std::string getDDMMYYYYString() const;
|
||||
std::string dayOfWeek() const;
|
||||
std::string dayOfWeekShort() const;
|
||||
|
||||
inline bool operator==(const TimeStamp& rhs) { return m_time == rhs.m_time; }
|
||||
inline bool operator!=(const TimeStamp& rhs) { return m_time != rhs.m_time; }
|
||||
|
||||
@@ -54,6 +54,7 @@ syntax:
|
||||
"os": ["windows", "macOS", "linux"],
|
||||
"min_version": "2017.2.0",
|
||||
"max_version": "2018.4.2",
|
||||
"weekday": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
||||
}
|
||||
|
||||
// optional
|
||||
@@ -205,6 +206,20 @@ bool QtNewsWidget::checkConditions(const QJsonObject& conditions) const
|
||||
}
|
||||
}
|
||||
|
||||
// weekday
|
||||
{
|
||||
QJsonArray weekdayStrings = conditions.value("weekday").toArray();
|
||||
if (!weekdayStrings.isEmpty())
|
||||
{
|
||||
QString weekdayString = QString::fromStdString(TimeStamp::now().dayOfWeekShort());
|
||||
if (!weekdayStrings.contains(QJsonValue(weekdayString)))
|
||||
{
|
||||
LOG_INFO_STREAM(<< "Failed condition weekday.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user