diff --git a/astrid/common-src/com/todoroo/andlib/utility/DateUtilities.java b/astrid/common-src/com/todoroo/andlib/utility/DateUtilities.java index 2e1e4162a..3eaea0b76 100644 --- a/astrid/common-src/com/todoroo/andlib/utility/DateUtilities.java +++ b/astrid/common-src/com/todoroo/andlib/utility/DateUtilities.java @@ -6,11 +6,13 @@ package com.todoroo.andlib.utility; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.Locale; import android.content.Context; import android.content.res.Resources; +import android.text.format.DateUtils; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; @@ -107,26 +109,18 @@ public class DateUtilities { return b24; } - /** - * @return time format (hours and minutes) - */ - public static SimpleDateFormat getTimeFormat(Context context) { - String value = getTimeFormatString(context); - return new SimpleDateFormat(value); - } - /** * @return string used for time formatting */ @SuppressWarnings("nls") - private static String getTimeFormatString(Context context) { + public static String getTimeString(Context context, Date date) { String value; if (is24HourFormat(context)) { value = "H:mm"; } else { value = "h:mm a"; } - return value; + return new SimpleDateFormat(value).format(date); } /** @@ -134,75 +128,45 @@ public class DateUtilities { * @return string used for date formatting */ @SuppressWarnings("nls") - private static String getDateFormatString(Context context) { + public static String getDateString(Context context, Date date) { + String month = "'" + DateUtils.getMonthString(date.getMonth() + + Calendar.JANUARY, DateUtils.LENGTH_MEDIUM) + "'"; String value; // united states, you are special if (Locale.US.equals(Locale.getDefault()) || Locale.CANADA.equals(Locale.getDefault())) - value = "MMM d yyyy"; + value = month + " d yyyy"; else - value = "d MMM yyyy"; - return value; - } - - /** - * @return date format (month, day, year) - */ - @SuppressWarnings("nls") - public static SimpleDateFormat getDateFormat(Context context) { - try { - return new SimpleDateFormat(getDateFormatString(context)); - } catch (Exception e) { - return new SimpleDateFormat("d MMM yyyy"); - } + value = "d " + month + " yyyy"; + return new SimpleDateFormat(value).format(date); } /** * @return date format as getDateFormat with weekday */ @SuppressWarnings("nls") - public static SimpleDateFormat getDateFormatWithWeekday(Context context) { - try { - return new SimpleDateFormat("EEEE, " + getDateFormatString(context)); - } catch (Exception e) { - return new SimpleDateFormat("EEEE, d MMM yyyy"); - } + public static String getDateStringWithWeekday(Context context, Date date) { + String weekday = DateUtils.getDayOfWeekString(date.getDay() + Calendar.SUNDAY, + DateUtils.LENGTH_LONG); + return weekday + ", " + getDateString(context, date); } /** * @return date format as getDateFormat with weekday */ @SuppressWarnings("nls") - public static SimpleDateFormat getDateWithTimeAndWeekday(Context context) { - try { - return new SimpleDateFormat("EEEE, " + getDateFormatString(context) - + " " + getTimeFormatString(context)); - } catch (Exception e) { - return new SimpleDateFormat("EEEE, d MMM yyyy H:mm"); - } + public static String getDateStringWithTimeAndWeekday(Context context, Date date) { + return getDateStringWithWeekday(context, date) + " " + getTimeString(context, date); } /** * @return date with time at the end */ @SuppressWarnings("nls") - public static SimpleDateFormat getDateWithTimeFormat(Context context) { - try { - return new SimpleDateFormat(getDateFormatString(context) + " " + - getTimeFormatString(context)); - } catch (Exception e) { - return new SimpleDateFormat("d MMM yyyy H:mm"); - } + public static String getDateStringWithTime(Context context, Date date) { + return getDateString(context, date) + " " + getTimeString(context, date); } - /** - * @return formatted date (will contain month, day, year) - */ - public static String getFormattedDate(Context context, Date date) { - return getDateFormat(context).format(date); - } - - /* ====================================================================== * ============================================================= duration * ====================================================================== */ diff --git a/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java b/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java index 00a3f5de6..edde100e4 100644 --- a/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/backup/BackupPreferences.java @@ -121,8 +121,8 @@ public class BackupPreferences extends TodorooPreferences { }); } else if(last > 0) { status = r.getString(R.string.backup_status_success, - DateUtilities.getDateWithTimeFormat(BackupPreferences.this). - format(new Date(last))); + DateUtilities.getDateStringWithTime(BackupPreferences.this, + new Date(last))); statusColor = Color.rgb(0, 100, 0); preference.setOnPreferenceClickListener(null); } else { diff --git a/astrid/plugin-src/com/todoroo/astrid/backup/TasksXmlImporter.java b/astrid/plugin-src/com/todoroo/astrid/backup/TasksXmlImporter.java index dc9839dce..da8dea146 100644 --- a/astrid/plugin-src/com/todoroo/astrid/backup/TasksXmlImporter.java +++ b/astrid/plugin-src/com/todoroo/astrid/backup/TasksXmlImporter.java @@ -24,8 +24,8 @@ import com.google.ical.values.RRule; import com.timsu.astrid.R; import com.todoroo.andlib.data.AbstractModel; import com.todoroo.andlib.data.Property; -import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.data.TodorooCursor; +import com.todoroo.andlib.data.Property.PropertyVisitor; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ExceptionService; import com.todoroo.andlib.sql.Criterion; @@ -34,8 +34,8 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.legacy.LegacyImportance; import com.todoroo.astrid.legacy.LegacyRepeatInfo; -import com.todoroo.astrid.legacy.LegacyRepeatInfo.LegacyRepeatInterval; import com.todoroo.astrid.legacy.LegacyTaskModel; +import com.todoroo.astrid.legacy.LegacyRepeatInfo.LegacyRepeatInterval; import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Task; import com.todoroo.astrid.rmilk.data.MilkTask; @@ -499,7 +499,7 @@ public class TasksXmlImporter { if(preferred != null) { Date preferredDate = BackupDateUtilities.getDateFromIso8601String(value); upgradeNotes = "Goal Deadline: " + - DateUtilities.getFormattedDate(ContextManager.getContext(), + DateUtilities.getDateString(ContextManager.getContext(), preferredDate); } task.setValue(Task.DUE_DATE, diff --git a/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkPreferences.java b/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkPreferences.java index 1f0dc5724..fff43d9d1 100644 --- a/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/rmilk/MilkPreferences.java @@ -114,12 +114,12 @@ public class MilkPreferences extends TodorooPreferences { // last sync was error else if(MilkUtilities.getLastAttemptedSyncDate() != 0) { status = r.getString(R.string.rmilk_status_failed, - DateUtilities.getDateWithTimeFormat(MilkPreferences.this). - format(new Date(MilkUtilities.getLastAttemptedSyncDate()))); + DateUtilities.getDateStringWithTime(MilkPreferences.this, + new Date(MilkUtilities.getLastAttemptedSyncDate()))); if(MilkUtilities.getLastSyncDate() > 0) { subtitle = r.getString(R.string.rmilk_status_failed_subtitle, - DateUtilities.getDateWithTimeFormat(MilkPreferences.this). - format(new Date(MilkUtilities.getLastSyncDate()))); + DateUtilities.getDateStringWithTime(MilkPreferences.this, + new Date(MilkUtilities.getLastSyncDate()))); } statusColor = Color.rgb(100, 0, 0); preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @@ -132,8 +132,8 @@ public class MilkPreferences extends TodorooPreferences { }); } else if(MilkUtilities.getLastSyncDate() > 0) { status = r.getString(R.string.rmilk_status_success, - DateUtilities.getDateWithTimeFormat(MilkPreferences.this). - format(new Date(MilkUtilities.getLastSyncDate()))); + DateUtilities.getDateStringWithTime(MilkPreferences.this, + new Date(MilkUtilities.getLastSyncDate()))); statusColor = Color.rgb(0, 100, 0); } else { status = r.getString(R.string.rmilk_status_never); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java index f93858a93..eac621235 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditActivity.java @@ -27,14 +27,14 @@ import java.util.List; import android.app.AlertDialog; import android.app.DatePickerDialog; -import android.app.DatePickerDialog.OnDateSetListener; import android.app.TabActivity; +import android.app.DatePickerDialog.OnDateSetListener; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; -import android.content.DialogInterface.OnCancelListener; import android.content.Intent; import android.content.IntentFilter; +import android.content.DialogInterface.OnCancelListener; import android.content.res.Resources; import android.graphics.Color; import android.os.Bundle; @@ -45,7 +45,6 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; @@ -60,6 +59,7 @@ import android.widget.TabHost; import android.widget.TimePicker; import android.widget.Toast; import android.widget.ToggleButton; +import android.widget.AdapterView.OnItemSelectedListener; import com.flurry.android.FlurryAgent; import com.timsu.astrid.R; @@ -758,12 +758,10 @@ public final class TaskEditActivity extends TabActivity { for(int i = 0; i < labels.length; i++) updated[i+1] = urgencyValues[i]; if(Task.hasDueTime(dueDate)) { - SimpleDateFormat format = DateUtilities.getDateWithTimeFormat(TaskEditActivity.this); - updated[0] = new UrgencyValue(format.format(new Date(dueDate)), + updated[0] = new UrgencyValue(DateUtilities.getDateStringWithTime(TaskEditActivity.this, new Date(dueDate)), Task.URGENCY_SPECIFIC_DAY_TIME, dueDate); } else { - SimpleDateFormat format = DateUtilities.getDateFormat(TaskEditActivity.this); - updated[0] = new UrgencyValue(format.format(new Date(dueDate)), + updated[0] = new UrgencyValue(DateUtilities.getDateString(TaskEditActivity.this, new Date(dueDate)), Task.URGENCY_SPECIFIC_DAY, dueDate); } selection = 0; @@ -923,8 +921,7 @@ public final class TaskEditActivity extends TabActivity { HideUntilValue[] updated = new HideUntilValue[values.length + 1]; for(int i = 0; i < values.length; i++) updated[i+1] = values[i]; - SimpleDateFormat format = DateUtilities.getDateFormat(TaskEditActivity.this); - updated[0] = new HideUntilValue(format.format(new Date(specificDate)), + updated[0] = new HideUntilValue(DateUtilities.getDateString(TaskEditActivity.this, new Date(specificDate)), Task.HIDE_UNTIL_SPECIFIC_DAY, specificDate); values = updated; } diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java index 33d5c4176..2cd21d17a 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskAdapter.java @@ -282,14 +282,15 @@ public class TaskAdapter extends CursorAdapter implements Filterable { String dateValue; Date dueDateAsDate = DateUtilities.unixtimeToDate(dueDate); if (task.hasDueTime()) { - dateValue = DateUtilities.getDateWithTimeAndWeekday(activity).format(dueDateAsDate); + dateValue = DateUtilities.getDateStringWithTimeAndWeekday(activity, dueDateAsDate); } else { - dateValue = DateUtilities.getDateFormatWithWeekday(activity).format(dueDateAsDate); + dateValue = DateUtilities.getDateStringWithWeekday(activity, dueDateAsDate); } dueDateView.setText(dateValue); setVisibility(dueDateView); } else if(task.isCompleted()) { - String dateValue = DateUtilities.getDateFormatWithWeekday(activity).format(task.getValue(Task.COMPLETION_DATE)); + String dateValue = DateUtilities.getDateStringWithWeekday(activity, + new Date(task.getValue(Task.COMPLETION_DATE))); dueDateView.setText(r.getString(R.string.TAd_completed, dateValue)); dueDateView.setTextAppearance(activity, R.style.TextAppearance_TAd_ItemDetails); setVisibility(dueDateView); diff --git a/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java b/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java index fe5ce8381..199f94af7 100644 --- a/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java +++ b/astrid/src/com/todoroo/astrid/service/Astrid2To3UpgradeHelper.java @@ -273,7 +273,7 @@ public class Astrid2To3UpgradeHelper { if(data.upgradeNotes == null) data.upgradeNotes = new StringBuilder(); data.upgradeNotes.append("Goal Deadline: " + - DateUtilities.getFormattedDate(ContextManager.getContext(), + DateUtilities.getDateString(ContextManager.getContext(), new Date(preferredDueDate))); } } else if(property == Task.REMINDER_PERIOD) {