Migrate old due time style from xml importer to new due time style

pull/14/head
Sam Bosley 13 years ago
parent dbf7d8b6ce
commit e2796db23b

@ -64,6 +64,20 @@ public class BackupDateUtilities {
} }
} }
public static Date getTaskDueDateFromIso8601String(String s) {
System.err.println("Importing date string: " + s);
Date date = getDateFromIso8601String(s);
System.err.println("Got date: " + date);
if (date != null) {
if (date.getHours() == 23 && date.getMinutes() == 59 && date.getSeconds() == 59) {
date.setHours(12);
date.setMinutes(0);
date.setSeconds(0);
}
}
return date;
}
/** /**
* Get current date and time as a string. Used for naming backup files. * Get current date and time as a string. Used for naming backup files.
*/ */

@ -260,6 +260,7 @@ public class TasksXmlImporter {
// else, make a new task model and add away. // else, make a new task model and add away.
deserializeModel(currentTask, Task.PROPERTIES); deserializeModel(currentTask, Task.PROPERTIES);
adjustDueDateScheme(currentTask);
currentTask.setId(Task.NO_ID); currentTask.setId(Task.NO_ID);
// Save the task to the database. // Save the task to the database.
@ -267,6 +268,19 @@ public class TasksXmlImporter {
importCount++; importCount++;
} }
private void adjustDueDateScheme(Task model) {
long dueDate = model.getValue(Task.DUE_DATE);
if (dueDate > 0) {
Date date = new Date(dueDate);
if (date.getHours() == 23 && date.getMinutes() == 59 && date.getSeconds() == 59) {
date.setHours(12);
date.setMinutes(0);
date.setSeconds(0);
}
model.setValue(Task.DUE_DATE, date.getTime());
}
}
private void parseMetadata() { private void parseMetadata() {
if(!currentTask.isSaved()) if(!currentTask.isSaved())
return; return;
@ -521,7 +535,7 @@ public class TasksXmlImporter {
preferredDate); preferredDate);
} }
task.setValue(Task.DUE_DATE, task.setValue(Task.DUE_DATE,
BackupDateUtilities.getDateFromIso8601String(value).getTime()); BackupDateUtilities.getTaskDueDateFromIso8601String(value).getTime());
} }
else if(field.equals(LegacyTaskModel.PREFERRED_DUE_DATE)) { else if(field.equals(LegacyTaskModel.PREFERRED_DUE_DATE)) {
String definite = xpp.getAttributeValue(null, LegacyTaskModel.DEFINITE_DUE_DATE); String definite = xpp.getAttributeValue(null, LegacyTaskModel.DEFINITE_DUE_DATE);
@ -529,7 +543,7 @@ public class TasksXmlImporter {
; // handled above ; // handled above
else else
task.setValue(Task.DUE_DATE, task.setValue(Task.DUE_DATE,
BackupDateUtilities.getDateFromIso8601String(value).getTime()); BackupDateUtilities.getTaskDueDateFromIso8601String(value).getTime());
} }
else if(field.equals(LegacyTaskModel.HIDDEN_UNTIL)) { else if(field.equals(LegacyTaskModel.HIDDEN_UNTIL)) {
task.setValue(Task.HIDE_UNTIL, task.setValue(Task.HIDE_UNTIL,

Loading…
Cancel
Save