From d3488416d053dbc742a34fde056cb72a67544c78 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 18 Jan 2013 13:56:59 -0800 Subject: [PATCH] Fixes to date parsing and reading of null fields --- api/src/com/todoroo/andlib/utility/DateUtilities.java | 8 ++++++-- .../astrid/actfm/sync/messages/ChangesHappened.java | 11 ----------- .../sync/messages/JSONChangeToPropertyVisitor.java | 4 +++- .../todoroo/astrid/actfm/sync/messages/NameMaps.java | 4 ++-- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/api/src/com/todoroo/andlib/utility/DateUtilities.java b/api/src/com/todoroo/andlib/utility/DateUtilities.java index 4faea254b..d5482b619 100644 --- a/api/src/com/todoroo/andlib/utility/DateUtilities.java +++ b/api/src/com/todoroo/andlib/utility/DateUtilities.java @@ -272,7 +272,9 @@ public class DateUtilities { return iso8601String.length() > 12; } - public static Date parseIso8601(String iso8601String) throws ParseException { + public static long parseIso8601(String iso8601String) throws ParseException { + if (iso8601String == null) + return 0; String formatString; if (isoStringHasTime(iso8601String)) { // Time exists iso8601String = iso8601String.replace("Z", "+00:00"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -288,10 +290,12 @@ public class DateUtilities { } Date result = new SimpleDateFormat(formatString).parse(iso8601String); - return result; + return result.getTime(); } public static String timeToIso8601(long time, boolean includeTime) { + if (time == 0) + return null; Date date = new Date(time); String formatString = "yyyy-MM-dd'T'HH:mm:ssZ"; //$NON-NLS-1$ if (!includeTime) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index 784011b20..1078a810d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -106,17 +106,6 @@ public class ChangesHappened 0) { - try { - JSONObject proofText = new JSONObject(); - proofText.put("id", -1); - proofText.put("column", "proof_text"); - proofText.put("value", "proofy"); - array.put(proofText); - } catch (JSONException e) { - Log.e(ERROR_TAG, "Error writing change to JSON", e); - } - } return array; } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/JSONChangeToPropertyVisitor.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/JSONChangeToPropertyVisitor.java index e2f7cd646..586b6708f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/JSONChangeToPropertyVisitor.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/JSONChangeToPropertyVisitor.java @@ -50,7 +50,7 @@ public class JSONChangeToPropertyVisitor implements PropertyVisitor property, String key) { try { String value = data.getString(key); + if ("null".equals(value)) + value = ""; model.setValue((StringProperty) property, value); } catch (JSONException e) { try { diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java index 1e383a7c7..8cac8670d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/NameMaps.java @@ -80,7 +80,7 @@ public class NameMaps { putPropertyToServerName(Task.IMPORTANCE, "importance", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false); putPropertyToServerName(Task.DUE_DATE, "due", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false); putPropertyToServerName(Task.HIDE_UNTIL, "hide_until", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, true); - putPropertyToServerName(Task.CREATION_DATE, "created_at", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false); + putPropertyToServerName(Task.CREATION_DATE, "created_at", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, true); putPropertyToServerName(Task.COMPLETION_DATE, "completed_at", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false); putPropertyToServerName(Task.RECURRENCE, "repeat", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false); putPropertyToServerName(Task.DELETION_DATE, "deleted_at", TASK_PROPERTIES_LOCAL_TO_SERVER, TASK_COLUMN_NAMES_TO_PROPERTIES, TASK_COLUMNS_LOCAL_TO_SERVER, TASK_PROPERTIES_EXCLUDED, false); @@ -113,7 +113,7 @@ public class NameMaps { putPropertyToServerName(TagData.NAME, "name", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, false); putPropertyToServerName(TagData.PICTURE, "picture_id", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, false); //TODO: NOT CORRECT putPropertyToServerName(TagData.MEMBERS, "members", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, false); //TODO: NOT CORRECT - putPropertyToServerName(TagData.CREATION_DATE, "created_at", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, false); + putPropertyToServerName(TagData.CREATION_DATE, "created_at", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, true); putPropertyToServerName(TagData.DELETION_DATE, "deleted_at", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, false); putPropertyToServerName(TagData.UUID, "uuid", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, true); putPropertyToServerName(TagData.TAG_ORDERING, "tag_ordering", TAG_DATA_PROPERTIES_LOCAL_TO_SERVER, TAG_DATA_COLUMN_NAMES_TO_PROPERTIES, TAG_DATA_COLUMNS_LOCAL_TO_SERVER, TAG_PROPERTIES_EXCLUDED, false); //TODO: NOT CORRECT