Ical: add some kind of better parsing when date/time of event is in specified timezone, it sucks before the iCal SPEC is huge and i just cannot implement it all correctly for purpose in rssguard
This commit is contained in:
parent
6479805799
commit
143f24c1b6
@ -109,15 +109,15 @@ QString IcalParser::objMessageDescription(const QVariant& msg_element) const {
|
|||||||
const IcalendarComponent& comp_base = msg_element.value<IcalendarComponent>();
|
const IcalendarComponent& comp_base = msg_element.value<IcalendarComponent>();
|
||||||
const EventComponent& comp = static_cast<const EventComponent&>(comp_base);
|
const EventComponent& comp = static_cast<const EventComponent&>(comp_base);
|
||||||
|
|
||||||
auto son = comp.startsOn(m_iCalendar.m_tzs);
|
bool has_dt;
|
||||||
auto soff = comp.endsOn(m_iCalendar.m_tzs);
|
auto son = comp.startsOn(m_iCalendar.m_tzs, &has_dt).toLocalTime();
|
||||||
|
|
||||||
QString formaton = son.time().hour() > 0 || son.time().minute() > 0 || son.time().second() > 0
|
QString formaton = has_dt ? QLocale().dateTimeFormat(QLocale::FormatType::LongFormat)
|
||||||
? QLocale().dateTimeFormat(QLocale::FormatType::LongFormat)
|
: QLocale().dateFormat(QLocale::FormatType::LongFormat);
|
||||||
: QLocale().dateFormat(QLocale::FormatType::LongFormat);
|
|
||||||
QString formatoff = soff.time().hour() > 0 || soff.time().minute() > 0 || soff.time().second() > 0
|
auto soff = comp.endsOn(m_iCalendar.m_tzs, &has_dt).toLocalTime();
|
||||||
? QLocale().dateTimeFormat(QLocale::FormatType::LongFormat)
|
QString formatoff = has_dt ? QLocale().dateTimeFormat(QLocale::FormatType::LongFormat)
|
||||||
: QLocale().dateFormat(QLocale::FormatType::LongFormat);
|
: QLocale().dateFormat(QLocale::FormatType::LongFormat);
|
||||||
|
|
||||||
QString body = QSL("Start date/time: %2<br/>"
|
QString body = QSL("Start date/time: %2<br/>"
|
||||||
"End date/time: %3<br/>"
|
"End date/time: %3<br/>"
|
||||||
@ -309,7 +309,8 @@ QVariant IcalendarComponent::getPropertyValue(const QString& property_name, QStr
|
|||||||
QDateTime IcalendarComponent::fixupDate(QDateTime dat,
|
QDateTime IcalendarComponent::fixupDate(QDateTime dat,
|
||||||
const QString& dt_format,
|
const QString& dt_format,
|
||||||
const QMap<QString, QTimeZone>& time_zones,
|
const QMap<QString, QTimeZone>& time_zones,
|
||||||
const QString& modifiers) const {
|
const QString& modifiers,
|
||||||
|
bool* has_dt) const {
|
||||||
// dat.setTimeSpec(Qt::TimeSpec::LocalTime);
|
// dat.setTimeSpec(Qt::TimeSpec::LocalTime);
|
||||||
|
|
||||||
// auto xx = dat.toUTC().toString();
|
// auto xx = dat.toUTC().toString();
|
||||||
@ -317,7 +318,11 @@ QDateTime IcalendarComponent::fixupDate(QDateTime dat,
|
|||||||
bool time_initialized = dt_format.contains('T');
|
bool time_initialized = dt_format.contains('T');
|
||||||
QStringList spl = modifiers.split('=');
|
QStringList spl = modifiers.split('=');
|
||||||
|
|
||||||
if (time_initialized && time_zones.contains(spl.at(1))) {
|
if (has_dt != nullptr) {
|
||||||
|
*has_dt = time_initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time_initialized && spl.size() == 2 && time_zones.contains(spl.at(1))) {
|
||||||
QTimeZone tz = time_zones.value(spl.at(1));
|
QTimeZone tz = time_zones.value(spl.at(1));
|
||||||
|
|
||||||
dat.setTimeSpec(Qt::TimeSpec::TimeZone);
|
dat.setTimeSpec(Qt::TimeSpec::TimeZone);
|
||||||
@ -335,20 +340,34 @@ QDateTime IcalendarComponent::fixupDate(QDateTime dat,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime EventComponent::startsOn(const QMap<QString, QTimeZone>& time_zones) const {
|
QDateTime EventComponent::startsOn(const QMap<QString, QTimeZone>& time_zones, bool* had_dt) const {
|
||||||
QString modifiers;
|
QString modifiers;
|
||||||
QString dt_format;
|
QString dt_format;
|
||||||
|
bool has_dt;
|
||||||
QDateTime dat = TextFactory::parseDateTime(getPropertyValue(QSL("DTSTART"), modifiers).toString(), &dt_format);
|
QDateTime dat = TextFactory::parseDateTime(getPropertyValue(QSL("DTSTART"), modifiers).toString(), &dt_format);
|
||||||
|
|
||||||
return fixupDate(dat, dt_format, time_zones, modifiers);
|
dat = fixupDate(dat, dt_format, time_zones, modifiers, &has_dt);
|
||||||
|
|
||||||
|
if (had_dt != nullptr) {
|
||||||
|
*had_dt = has_dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dat;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime EventComponent::endsOn(const QMap<QString, QTimeZone>& time_zones) const {
|
QDateTime EventComponent::endsOn(const QMap<QString, QTimeZone>& time_zones, bool *had_dt) const {
|
||||||
QString modifiers;
|
QString modifiers;
|
||||||
QString dt_format;
|
QString dt_format;
|
||||||
|
bool has_dt;
|
||||||
QDateTime dat = TextFactory::parseDateTime(getPropertyValue(QSL("DTEND"), modifiers).toString(), &dt_format);
|
QDateTime dat = TextFactory::parseDateTime(getPropertyValue(QSL("DTEND"), modifiers).toString(), &dt_format);
|
||||||
|
|
||||||
return fixupDate(dat, dt_format, time_zones, modifiers);
|
dat = fixupDate(dat, dt_format, time_zones, modifiers, &has_dt);
|
||||||
|
|
||||||
|
if (had_dt != nullptr) {
|
||||||
|
*had_dt = has_dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dat;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString EventComponent::title() const {
|
QString EventComponent::title() const {
|
||||||
|
@ -21,7 +21,8 @@ class IcalendarComponent {
|
|||||||
QDateTime fixupDate(QDateTime dat,
|
QDateTime fixupDate(QDateTime dat,
|
||||||
const QString& dt_format,
|
const QString& dt_format,
|
||||||
const QMap<QString, QTimeZone>& time_zones,
|
const QMap<QString, QTimeZone>& time_zones,
|
||||||
const QString& modifiers) const;
|
const QString& modifiers,
|
||||||
|
bool* has_dt = nullptr) const;
|
||||||
|
|
||||||
QVariantMap m_properties;
|
QVariantMap m_properties;
|
||||||
};
|
};
|
||||||
@ -30,8 +31,8 @@ Q_DECLARE_METATYPE(IcalendarComponent)
|
|||||||
|
|
||||||
class EventComponent : public IcalendarComponent {
|
class EventComponent : public IcalendarComponent {
|
||||||
public:
|
public:
|
||||||
QDateTime startsOn(const QMap<QString, QTimeZone>& time_zones = {}) const;
|
QDateTime startsOn(const QMap<QString, QTimeZone>& time_zones = {}, bool* had_dt = nullptr) const;
|
||||||
QDateTime endsOn(const QMap<QString, QTimeZone>& time_zones = {}) const;
|
QDateTime endsOn(const QMap<QString, QTimeZone>& time_zones = {}, bool* had_dt = nullptr) const;
|
||||||
QString title() const;
|
QString title() const;
|
||||||
QString url() const;
|
QString url() const;
|
||||||
QString organizer() const;
|
QString organizer() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user