Skip to content

Commit

Permalink
[buteo-sync-plugins-social] Enforce C locale when generating timestam…
Browse files Browse the repository at this point in the history
…p strings. Contributes to MER#1536

When generating timestamps for consumption by remote servers, the
server will expect the timestamps to be formatted as RFC-compliant
datetime strings. Those invariably require Latin1 alphanumeric
characters.

This commit ensures that we use the C locale when generating such
strings, to avoid non-Latin1 number-characters from being used.

Contributes to MER#1536
  • Loading branch information
Chris Adams committed Mar 4, 2016
1 parent a5c2a22 commit 9a0b2a8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Expand Up @@ -367,8 +367,8 @@ void FacebookCalendarSyncAdaptor::finishedHandler()
// if a date-only event lasts only one day, set isAllDay to true, but don't set an end date.
// if a date-only event lasts multiple days, set isAllDay to true, and set an end date.
// Use ClockTime format, so that it doesn't get offset according to timezone.
parsedEvent.m_startTime = KDateTime(QDate::fromString(startTimeString, "yyyy-MM-dd"), QTime(), KDateTime::ClockTime);
parsedEvent.m_endTime = KDateTime(QDate::fromString(endTimeString, "yyyy-MM-dd"), QTime(), KDateTime::ClockTime);
parsedEvent.m_startTime = KDateTime(QLocale::c().toDate(startTimeString, QLatin1String("yyyy-MM-dd")), QTime(), KDateTime::ClockTime);
parsedEvent.m_endTime = KDateTime(QLocale::c().toDate(endTimeString, QLatin1String("yyyy-MM-dd")), QTime(), KDateTime::ClockTime);
if (parsedEvent.m_endTime == parsedEvent.m_startTime) {
parsedEvent.m_endExists = false; // single-day all day event; don't set endDt.
}
Expand Down
Expand Up @@ -371,7 +371,7 @@ QContact FacebookContactSyncAdaptor::parseContactDetails(const QJsonObject &blob
if (!birthday.isValid()) {
// manually parse the birthday. It's usually in MM/DD/YYYY format,
// but sometimes MM/DD format - which we ignore.
birthday = QDateTime::fromString(birthdayStr, "MM/dd/yyyy");
birthday = QLocale::c().toDateTime(birthdayStr, "MM/dd/yyyy");
}
QString bio = blobDetails.value(QLatin1String("bio")).toString();
QString gender = blobDetails.value(QLatin1String("gender")).toString();
Expand Down
28 changes: 14 additions & 14 deletions src/google/google-calendars/googlecalendarsyncadaptor.cpp
Expand Up @@ -145,8 +145,8 @@ KDateTime datetimeFromUpdateStr(const QString &update)
// date format directly.
bool tzIncluded = update.endsWith('Z');
QDateTime qdt = tzIncluded
? QDateTime::fromString(update, RFC3339_QDATE_FORMAT_MS)
: QDateTime::fromString(update, RFC3339_QDATE_FORMAT_MS_NTZC);
? QLocale::c().toDateTime(update, RFC3339_QDATE_FORMAT_MS)
: QLocale::c().toDateTime(update, RFC3339_QDATE_FORMAT_MS_NTZC);
if (tzIncluded) {
qdt.setTimeSpec(Qt::UTC);
}
Expand Down Expand Up @@ -198,7 +198,7 @@ QList<KDateTime> datetimesFromExRDateStr(const QString &exrdatestr, bool *isDate
str.remove(0, 5);
QStringList dts = str.split(',');
Q_FOREACH(const QString &dstr, dts) {
QDate date = QDate::fromString(dstr, RFC5545_QDATE_FORMAT);
QDate date = QLocale::c().toDate(dstr, RFC5545_QDATE_FORMAT);
KDateTime kdt(date, KDateTime::Spec::ClockTime());
retn.append(kdt);
}
Expand Down Expand Up @@ -296,7 +296,7 @@ QJsonArray recurrenceArray(KCalCore::Event::Ptr event, KCalCore::ICalFormat &ica
// RDATE (date)
QString rdates;
Q_FOREACH (const QDate &rdate, kcalRecurrence->rDates()) {
rdates.append(rdate.toString(RFC5545_QDATE_FORMAT));
rdates.append(QLocale::c().toString(rdate, RFC5545_QDATE_FORMAT));
rdates.append(',');
}
if (rdates.size()) {
Expand All @@ -322,7 +322,7 @@ QJsonArray recurrenceArray(KCalCore::Event::Ptr event, KCalCore::ICalFormat &ica
// EXDATE (date)
QString exdates;
Q_FOREACH (const QDate &exdate, kcalRecurrence->exDates()) {
exdates.append(exdate.toString(RFC5545_QDATE_FORMAT));
exdates.append(QLocale::c().toString(exdate, RFC5545_QDATE_FORMAT));
exdates.append(',');
}
if (exdates.size()) {
Expand Down Expand Up @@ -367,14 +367,14 @@ QJsonObject kCalToJson(KCalCore::Event::Ptr event, KCalCore::ICalFormat &icalFor
// insert the date/time and timeZone information into the Json object.
// note that timeZone is required for recurring events, for some reason.
if (event->dtStart().isDateOnly() || (event->allDay() && event->dtStart().time() == QTime(0,0,0))) {
start.insert(QLatin1String("date"), event->dtStart().date().toString(QDATEONLY_FORMAT));
start.insert(QLatin1String("date"), QLocale::c().toString(event->dtStart().date(), QDATEONLY_FORMAT));
} else {
start.insert(QLatin1String("dateTime"), event->dtStart().toString(RFC3339_FORMAT));
start.insert(QLatin1String("timeZone"), QJsonValue(event->dtStart().toString(KLONGTZ_FORMAT)));
}
if (event->dtEnd().isDateOnly() || (event->allDay() && event->dtEnd().time() == QTime(0,0,0))) {
// note: for iCal spec, allDay events need to have an end date of real-end-date+1 as end date is exclusive.
end.insert(QLatin1String("date"), event->dateEnd().addDays(1).toString(QDATEONLY_FORMAT));
end.insert(QLatin1String("date"), QLocale::c().toString(event->dateEnd().addDays(1), QDATEONLY_FORMAT));
} else {
end.insert(QLatin1String("dateTime"), event->dtEnd().toString(RFC3339_FORMAT));
end.insert(QLatin1String("timeZone"), QJsonValue(event->dtEnd().toString(KLONGTZ_FORMAT)));
Expand Down Expand Up @@ -465,7 +465,7 @@ void extractStartAndEnd(const QJsonObject &eventData,

*start = parsedStartTime.toLocalZone();
} else {
*start = KDateTime(QDate::fromString(startTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
*start = KDateTime(QLocale::c().toDate(startTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
start->setDateOnly(true);
}
}
Expand All @@ -485,13 +485,13 @@ void extractStartAndEnd(const QJsonObject &eventData,
} else {
// Special handling for all-day events is required.
if (*startExists && *startIsDateOnly) {
if (QDate::fromString(startTimeString, QDATEONLY_FORMAT)
== QDate::fromString(endTimeString, QDATEONLY_FORMAT)) {
if (QLocale::c().toDate(startTimeString, QDATEONLY_FORMAT)
== QLocale::c().toDate(endTimeString, QDATEONLY_FORMAT)) {
// single-day all-day event
*endExists = false;
*isAllDay = true;
} else if (QDate::fromString(startTimeString, QDATEONLY_FORMAT)
== QDate::fromString(endTimeString, QDATEONLY_FORMAT).addDays(-1)) {
} else if (QLocale::c().toDate(startTimeString, QDATEONLY_FORMAT)
== QLocale::c().toDate(endTimeString, QDATEONLY_FORMAT).addDays(-1)) {
// Google will send a single-day all-day event has having an end-date
// of startDate+1 to conform to iCal spec. Hence, this is actually
// a single-day all-day event, despite the difference in end-date.
Expand All @@ -501,12 +501,12 @@ void extractStartAndEnd(const QJsonObject &eventData,
// multi-day all-day event.
// as noted above, Google will send all-day events as having an end-date
// of real-end-date+1 in order to conform to iCal spec (exclusive end dt).
*end = KDateTime(QDate::fromString(endTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
*end = KDateTime(QLocale::c().toDate(endTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
end->setDateOnly(true);
*isAllDay = true;
}
} else {
*end = KDateTime(QDate::fromString(endTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
*end = KDateTime(QLocale::c().toDate(endTimeString, QDATEONLY_FORMAT), QTime(), KDateTime::ClockTime);
end->setDateOnly(true);
*isAllDay = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/google/google-contacts/googlecontactstream.cpp
Expand Up @@ -847,7 +847,7 @@ void GoogleContactStream::encodeUpdatedTimestamp(const QContact &qContact)
updatedTimestamp = QDateTime::currentDateTimeUtc();
}

QString updatedStr = updatedTimestamp.toString(QStringLiteral("yyyy-MM-ddThh:mm:ss.zzzZ"));
QString updatedStr = QLocale::c().toString(updatedTimestamp, QStringLiteral("yyyy-MM-ddThh:mm:ss.zzzZ"));
mXmlWriter->writeTextElement("updated", updatedStr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vk/vk-contacts/vkcontactsyncadaptor.cpp
Expand Up @@ -662,7 +662,7 @@ QList<QContact> VKContactSyncAdaptor::parseContacts(const QJsonArray &json, int
if (!obj.value("bdate").toString().isEmpty() && obj.value("bdate").toString().length() > 5) {
// DD.MM.YYYY form, we ignore DD.MM (yearless) form response.
QContactBirthday birthday;
birthday.setDateTime(QDateTime::fromString(obj.value("bdate").toString(), "dd.MM.yyyy"));
birthday.setDateTime(QLocale::c().toDateTime(obj.value("bdate").toString(), "dd.MM.yyyy"));
saveNonexportableDetail(c, birthday);
}

Expand Down

0 comments on commit 9a0b2a8

Please sign in to comment.