Commit 4dc5d28c authored by Charles Lindsay's avatar Charles Lindsay

Fix wrong internaldate_time_t column

We had a bug in our DateTime to time_t conversion logic where all
time_ts would end up in the year 3800.  This fixes that, and repopulates
the internaldate_time_t column with the new, correct time_t values.

Closes: bgo #724335
parent aca1e539
...@@ -17,3 +17,4 @@ install(FILES version-014.sql DESTINATION ${SQL_DEST}) ...@@ -17,3 +17,4 @@ install(FILES version-014.sql DESTINATION ${SQL_DEST})
install(FILES version-015.sql DESTINATION ${SQL_DEST}) install(FILES version-015.sql DESTINATION ${SQL_DEST})
install(FILES version-016.sql DESTINATION ${SQL_DEST}) install(FILES version-016.sql DESTINATION ${SQL_DEST})
install(FILES version-017.sql DESTINATION ${SQL_DEST}) install(FILES version-017.sql DESTINATION ${SQL_DEST})
install(FILES version-018.sql DESTINATION ${SQL_DEST})
--
-- Nuke the internaldate_time_t column, because it had the wrong values. It'll
-- be repopulated in code, in imap-db-database.vala.
--
UPDATE MessageTable SET internaldate_time_t = NULL;
...@@ -93,6 +93,10 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase { ...@@ -93,6 +93,10 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
case 15: case 15:
post_upgrade_fix_localized_internaldates(); post_upgrade_fix_localized_internaldates();
break; break;
case 18:
post_upgrade_populate_internal_date_time_t();
break;
} }
} }
...@@ -202,7 +206,7 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase { ...@@ -202,7 +206,7 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
return "english"; return "english";
} }
// Version 12. // Versions 12 and 18.
private void post_upgrade_populate_internal_date_time_t() { private void post_upgrade_populate_internal_date_time_t() {
try { try {
exec_transaction(Db.TransactionType.RW, (cx) => { exec_transaction(Db.TransactionType.RW, (cx) => {
......
...@@ -21,7 +21,7 @@ public time_t datetime_to_time_t(DateTime datetime) { ...@@ -21,7 +21,7 @@ public time_t datetime_to_time_t(DateTime datetime) {
// month is 1-based in DateTime // month is 1-based in DateTime
tm.month = Numeric.int_floor(datetime.get_month() - 1, 0); tm.month = Numeric.int_floor(datetime.get_month() - 1, 0);
// Time's year is number of years after 1900 // Time's year is number of years after 1900
tm.year = Numeric.int_floor(datetime.get_year() - 1900, 1900); tm.year = Numeric.int_floor(datetime.get_year() - 1900, 0);
tm.isdst = datetime.is_daylight_savings() ? 1 : 0; tm.isdst = datetime.is_daylight_savings() ? 1 : 0;
return tm.mktime(); return tm.mktime();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment