Use joda time formatting, update joda to 2.8.1

pull/321/head
Alex Baker 9 years ago
parent 973ab556a8
commit b7db45d23c

@ -91,7 +91,7 @@ dependencies {
compile group: 'com.android.support', name: 'design', version: '22.2.0'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7'
compile group: 'joda-time', name: 'joda-time', version: '2.6', transitive: false
compile group: 'joda-time', name: 'joda-time', version: '2.8.1', transitive: false
compile group: 'com.rubiconproject.oss', name: 'jchronic', version: '0.2.6', transitive: false
compile group: 'org.scala-saddle', name: 'google-rfc-2445', version: '20110304', transitive: false

@ -16,7 +16,6 @@ import java.util.Date;
import java.util.Locale;
import static com.todoroo.andlib.utility.DateUtilities.addCalendarMonthsToUnixtime;
import static com.todoroo.andlib.utility.DateUtilities.clearTime;
import static com.todoroo.andlib.utility.DateUtilities.getDateString;
import static com.todoroo.andlib.utility.DateUtilities.getDateStringHideYear;
import static com.todoroo.andlib.utility.DateUtilities.getStartOfDay;
@ -26,7 +25,6 @@ import static com.todoroo.andlib.utility.DateUtilities.getWeekdayShort;
import static com.todoroo.andlib.utility.DateUtilities.isEndOfMonth;
import static com.todoroo.andlib.utility.DateUtilities.oneMonthFromNow;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.TestUtilities.newDateTime;
import static org.tasks.date.DateTimeUtils.newDate;
public class DateUtilitiesTest extends AndroidTestCase {
@ -70,13 +68,13 @@ public class DateUtilitiesTest extends AndroidTestCase {
DateUtilities.is24HourOverride = false;
for (int i = 0; i < 24; i++) {
d.setHours(i);
DateUtilities.getTimeString(getContext(), d);
getTimeString(getContext(), new DateTime(d));
}
DateUtilities.is24HourOverride = true;
for (int i = 0; i < 24; i++) {
d.setHours(i);
DateUtilities.getTimeString(getContext(), d);
getTimeString(getContext(), new DateTime(d));
}
}
});
@ -97,23 +95,23 @@ public class DateUtilitiesTest extends AndroidTestCase {
public void testGet24HourTime() {
DateUtilities.is24HourOverride = true;
assertEquals("09:05", getTimeString(null, newDateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("13:00", getTimeString(null, newDateTime(2014, 1, 4, 13, 0, 1)));
assertEquals("09:05", getTimeString(null, new DateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("13:00", getTimeString(null, new DateTime(2014, 1, 4, 13, 0, 1)));
}
public void testGetTime() {
DateUtilities.is24HourOverride = false;
assertEquals("9:05 AM", getTimeString(null, newDateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("1:05 PM", getTimeString(null, newDateTime(2014, 1, 4, 13, 5, 36)));
assertEquals("9:05 AM", getTimeString(null, new DateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("1:05 PM", getTimeString(null, new DateTime(2014, 1, 4, 13, 5, 36)));
}
public void testGetTimeWithNoMinutes() {
DateUtilities.is24HourOverride = false;
assertEquals("1 PM", getTimeString(null, newDateTime(2014, 1, 4, 13, 0, 59))); // derp?
assertEquals("1 PM", getTimeString(null, new DateTime(2014, 1, 4, 13, 0, 59))); // derp?
}
public void testGetDateStringWithYear() {
assertEquals("Jan 4, 2014", getDateString(newDateTime(2014, 1, 4, 0, 0, 0)));
assertEquals("Jan 4, 2014", getDateString(new DateTime(2014, 1, 4, 0, 0, 0).toDate()));
}
public void testGetDateStringHidingYear() {
@ -173,13 +171,6 @@ public class DateUtilitiesTest extends AndroidTestCase {
}});
}
public void testClearTimeFromDate() {
DateTime now = new DateTime(2014, 1, 3, 10, 34, 32, 98);
assertEquals(
now.withMillisOfDay(0).getMillis(),
clearTime(new Date(now.getMillis())));
}
public void testShouldGetStartOfDay() {
DateTime now = new DateTime(2014, 1, 3, 10, 41, 41, 520);
assertEquals(

@ -14,12 +14,13 @@ import com.google.ical.values.WeekdayNum;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import org.joda.time.DateTime;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import static org.tasks.TestUtilities.newDateTime;
import static org.tasks.date.DateTimeUtils.newDate;
public class AdvancedRepeatTest extends AndroidTestCase {
@ -46,7 +47,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
buildRRule(1, Frequency.DAILY);
// test specific day & time
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(2010, 8, 1, 10, 4, 0).getTime());
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, new DateTime(2010, 8, 1, 10, 4, 0).getMillis());
task.setDueDate(dayWithTime);
long nextDayWithTime = dayWithTime + DateUtilities.ONE_DAY;
@ -58,7 +59,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
buildRRule(1, Frequency.DAILY);
// test specific day & time
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(2010, 8, 1, 10, 4, 0).getTime());
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, new DateTime(2010, 8, 1, 10, 4, 0).getMillis());
task.setDueDate(dayWithTime);
Date todayWithTime = newDate();

@ -14,8 +14,4 @@ public class TestUtilities {
mockitoInitialized = true;
}
}
public static Date newDateTime(int year, int month, int day, int hour, int minute, int second) {
return new Date(year - 1900, month - 1, day, hour, minute, second);
}
}

@ -9,7 +9,6 @@ import org.tasks.Snippet;
import java.util.Date;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.TestUtilities.newDateTime;
import static org.tasks.date.DateTimeUtils.currentTimeMillis;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateUtc;
@ -36,7 +35,7 @@ public class DateTimeUtilsTest extends AndroidTestCase {
}
public void testCreateNewDateTime() {
assertEquals(new Date(114, 0, 1, 15, 17, 53), newDateTime(2014, 1, 1, 15, 17, 53));
assertEquals(new Date(114, 0, 1, 15, 17, 53), new DateTime(2014, 1, 1, 15, 17, 53).toDate());
}
public void testCreateNewUtcDate() {

@ -80,21 +80,20 @@ public class DateUtilities {
return DateFormat.is24HourFormat(context);
}
/**
* @param context android context
* @param date time to format
* @return time, with hours and minutes
*/
public static String getTimeString(Context context, Date date) {
public static String getTimeString(Context context, long timestamp) {
return getTimeString(context, newDateTime(timestamp));
}
public static String getTimeString(Context context, DateTime date) {
String value;
if (is24HourFormat(context)) {
value = "HH:mm";
} else if (date.getMinutes() == 0){
} else if (date.getMinuteOfHour() == 0){
value = "h a";
} else {
value = "h:mm a";
}
return new SimpleDateFormat(value).format(date);
return date.toString(value);
}
/* Returns true if search string is in sortedValues */
@ -189,19 +188,20 @@ public class DateUtilities {
return new SimpleDateFormat("EEE").format(date);
}
/**
* @return date with time at the end
*/
public static String getDateStringWithTime(Context context, Date date) {
return getDateString(date) + " " + getTimeString(context, date);
public static String getDateStringWithTime(Context context, long timestamp) {
return getDateStringWithTime(context, newDateTime(timestamp));
}
public static String getDateStringWithTime(Context context, DateTime date) {
return getDateString(date.toDate()) + " " + getTimeString(context, date);
}
/**
* @return yesterday, today, tomorrow, or null
*/
public static String getRelativeDay(Context context, long date, boolean abbreviated) {
long today = clearTime(newDate());
long input = clearTime(newDate(date));
long today = getStartOfDay(currentTimeMillis());
long input = getStartOfDay(date);
if(today == input) {
return context.getString(R.string.today);
@ -229,12 +229,4 @@ public class DateUtilities {
public static long getStartOfDay(long time) {
return newDateTime(time).withMillisOfDay(0).getMillis();
}
static long clearTime(Date date) {
date.setTime(date.getTime() / 1000L * 1000);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
return date.getTime();
}
}

@ -6,10 +6,8 @@
package com.todoroo.astrid.adapter;
import android.app.Activity;
import android.app.Dialog;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Paint;
@ -22,7 +20,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.CursorAdapter;
@ -62,9 +59,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastGingerbread;
import static org.tasks.date.DateTimeUtils.newDate;
/**
* Adapter for displaying a user's tasks as a list
*
@ -480,7 +474,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
String string = DateUtilities.getRelativeDay(fragment.getActivity(), date, true);
if(Task.hasDueTime(date)) {
string = String.format(formatString, string, //$NON-NLS-1$
DateUtilities.getTimeString(fragment.getActivity(), newDate(date)));
DateUtilities.getTimeString(fragment.getActivity(), date));
}
dateCache.put(date, string);

@ -53,7 +53,7 @@ public class GtasksPreferences extends InjectingPreferenceActivity {
if (gtasksPreferenceService.getLastSyncDate() > 0) {
gtaskPreference.setSummary(getString(R.string.sync_status_success,
DateUtilities.getDateStringWithTime(GtasksPreferences.this,
newDate(gtasksPreferenceService.getLastSyncDate()))));
gtasksPreferenceService.getLastSyncDate())));
}
findPreference(getString(R.string.sync_SPr_forget_key)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override

@ -62,6 +62,7 @@ import java.util.LinkedList;
import java.util.List;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateTime;
import static org.tasks.files.FileHelper.getPathFromUri;
import static org.tasks.files.ImageHelper.sampleBitmap;
@ -468,7 +469,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
public void timerStarted(Task t) {
addComment(String.format("%s %s", //$NON-NLS-1$
getContext().getString(R.string.TEA_timer_comment_started),
DateUtilities.getTimeString(getContext(), newDate())),
DateUtilities.getTimeString(getContext(), newDateTime())),
UserActivity.ACTION_TASK_COMMENT,
t.getUuid(),
false);
@ -479,7 +480,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
String elapsedTime = DateUtils.formatElapsedTime(t.getElapsedSeconds());
addComment(String.format("%s %s\n%s %s", //$NON-NLS-1$
getContext().getString(R.string.TEA_timer_comment_stopped),
DateUtilities.getTimeString(getContext(), newDate()),
DateUtilities.getTimeString(getContext(), newDateTime()),
getContext().getString(R.string.TEA_timer_comment_spent),
elapsedTime), UserActivity.ACTION_TASK_COMMENT,
t.getUuid(),

@ -480,7 +480,7 @@ public class RepeatControlSet extends PopupControlSet {
displayString.append(DateUtilities.getDateStringHideYear(d));
if (Task.hasDueTime(repeatUntilValue)) {
displayString.append(", "); //$NON-NLS-1$ //$NON-NLS-2$
displayString.append(DateUtilities.getTimeString(activity, d));
displayString.append(DateUtilities.getTimeString(activity, repeatUntilValue));
}
}
return displayString.toString();

@ -26,6 +26,7 @@ import org.tasks.activities.DateAndTimePickerActivity;
import java.util.Date;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateTime;
/**
* Control set for specifying when a task should be hidden
@ -104,7 +105,7 @@ public class HideUntilControlSet extends TaskEditControlSetBase implements OnIte
Task.HIDE_UNTIL_SPECIFIC_DAY, specificDate);
existingDate = specificDate;
} else {
updated[0] = new HideUntilValue(DateUtilities.getDateStringWithTime(activity, newDate(specificDate)),
updated[0] = new HideUntilValue(DateUtilities.getDateStringWithTime(activity, newDateTime(specificDate)),
Task.HIDE_UNTIL_SPECIFIC_DAY_TIME, specificDate);
existingDate = specificDate;
}

@ -365,7 +365,7 @@ public class ReminderControlSet extends TaskEditControlSetBase implements Adapte
return (dateTime.getYear() == newDateTime().getYear()
? DateUtilities.getLongDateStringHideYear(d)
: DateUtilities.getLongDateString(d)) +
", " + DateUtilities.getTimeString(activity, d);
", " + DateUtilities.getTimeString(activity, dateTime);
}
@Override

@ -96,7 +96,7 @@ public class RepeatConfirmationReceiver extends InjectingBroadcastReceiver {
if (Task.hasDueTime(date)) {
// TODO: localize this
dueString = String.format("%s at %s", dueString, //$NON-NLS-1$
DateUtilities.getTimeString(context, newDate(date)));
DateUtilities.getTimeString(context, date));
}
return dueString;
}

@ -35,7 +35,7 @@ public class SnoozeDialog extends InjectingDialogFragment {
private List<String> items = new ArrayList<>();
private void add(int resId, DateTime dateTime) {
items.add(String.format("%s (%s)", getString(resId), getTimeString(context, dateTime.toDate())));
items.add(String.format("%s (%s)", getString(resId), getTimeString(context, dateTime)));
snoozeTimes.add(dateTime.getMillis());
}

@ -102,7 +102,7 @@ public class DeadlineControlSet extends TaskEditControlSetBase {
private String getTimeHint(int millisOfDay) {
DateTime dateTime = newDateTime().withMillisOfDay(millisOfDay);
return DateUtilities.getTimeString(activity, dateTime.toDate());
return DateUtilities.getTimeString(activity, dateTime);
}
private void refreshDisplayView() {
@ -150,7 +150,7 @@ public class DeadlineControlSet extends TaskEditControlSetBase {
} else if (compareTime == dateShortcutNight) {
dueTimeOptions.set(0, nightString);
} else {
dueTimeOptions.set(0, DateUtilities.getTimeString(activity, newDateTime().withMillisOfDay(time).toDate()));
dueTimeOptions.set(0, DateUtilities.getTimeString(activity, newDateTime().withMillisOfDay(time)));
}
}
dueTimeAdapter.notifyDataSetChanged();

@ -51,7 +51,7 @@ public class DueDateFormatter {
String string = DateUtilities.getRelativeDay(context, date, false);
if (Task.hasDueTime(date)) {
string = String.format(formatString, string, //$NON-NLS-1$
DateUtilities.getTimeString(context, newDate(date)));
DateUtilities.getTimeString(context, date));
}
dateCache.put(date, string);

Loading…
Cancel
Save