Skip to content

Commit f021191

Browse files
authored
Merge pull request #908 from Automattic/update-date-format
Update Date Format
2 parents 8d850c7 + 4def9bc commit f021191

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

Simplenote/src/main/java/com/automattic/simplenote/HistoryBottomSheetDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
114114
mListener.onHistoryUpdateNote(revisedNote.getContent());
115115
}
116116

117-
mHistoryDate.setText(DateTimeUtils.getDateText(mFragment.getActivity(), noteDate));
117+
mHistoryDate.setText(DateTimeUtils.getDateText(requireContext(), noteDate));
118118
}
119119

120120
@Override
@@ -188,7 +188,7 @@ private void setProgressBar() {
188188
if (totalRevs > 0) {
189189
mHistorySeekBar.setMax(totalRevs);
190190
mHistorySeekBar.setProgress(totalRevs);
191-
mHistoryDate.setText(DateTimeUtils.getDateText(mFragment.getActivity(), mNote.getModificationDate()));
191+
mHistoryDate.setText(DateTimeUtils.getDateText(requireContext(), mNote.getModificationDate()));
192192
mLoadingView.setVisibility(View.GONE);
193193
mSliderView.setVisibility(View.VISIBLE);
194194
} else {

Simplenote/src/main/java/com/automattic/simplenote/InfoBottomSheetDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void show(FragmentManager manager, Note note) {
135135
if (mFragment.isAdded()) {
136136
showNow(manager, TAG);
137137

138-
String date = DateTimeUtils.getDateText(mFragment.getActivity(), note.getModificationDate());
138+
String date = DateTimeUtils.getDateText(requireContext(), note.getModificationDate());
139139
mInfoModifiedDate.setText(String.format(mFragment.getString(R.string.modified_time), date));
140140
mInfoPinSwitch.setChecked(note.isPinned());
141141
mInfoMarkdownSwitch.setChecked(note.isMarkdownEnabled());

Simplenote/src/main/java/com/automattic/simplenote/NoteListFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ public View getView(final int position, View view, ViewGroup parent) {
10391039
mCursor.moveToPosition(position);
10401040
holder.setNoteId(mCursor.getSimperiumKey());
10411041
Calendar date = getDateByPreference(mCursor.getObject());
1042-
holder.mDate.setText(date != null ? DateTimeUtils.getDateTextShort(date) : "");
1042+
holder.mDate.setText(date != null ? DateTimeUtils.getDateTextNumeric(date) : "");
10431043
holder.mDate.setVisibility(mIsSearching && date != null ? View.VISIBLE : View.GONE);
10441044
boolean isPinned = mCursor.getObject().isPinned();
10451045
holder.mPinned.setVisibility(!isPinned || mIsSearching ? View.GONE : View.VISIBLE);
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package com.automattic.simplenote.utils;
22

3-
import android.app.Activity;
3+
import android.content.Context;
4+
import android.text.format.DateFormat;
5+
import android.text.format.DateUtils;
46

57
import java.text.SimpleDateFormat;
68
import java.util.Calendar;
79
import java.util.Locale;
810

911
public class DateTimeUtils {
10-
public static String getDateText(Activity activity, Calendar noteDate) {
11-
if (noteDate == null) {
12+
public static String getDateText(Context context, Calendar calendar) {
13+
if (calendar == null) {
1214
return "";
1315
}
1416

15-
long now = Calendar.getInstance().getTimeInMillis();
16-
CharSequence dateText = android.text.format.DateUtils.getRelativeDateTimeString(
17-
activity,
18-
noteDate.getTimeInMillis(),
19-
now,
17+
CharSequence dateText = DateUtils.getRelativeDateTimeString(
18+
context,
19+
calendar.getTimeInMillis(),
20+
Calendar.getInstance().getTimeInMillis(),
2021
0L,
21-
android.text.format.DateUtils.FORMAT_ABBREV_ALL
22+
DateUtils.FORMAT_ABBREV_ALL
2223
);
2324

2425
return dateText.toString();
2526
}
2627

27-
public static String getDateTextShort(Calendar date) {
28-
SimpleDateFormat formatter = new SimpleDateFormat("MMM d", Locale.getDefault());
29-
return formatter.format(date.getTime());
28+
public static String getDateTextNumeric(Calendar date) {
29+
String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "MM/dd/YYYY");
30+
return new SimpleDateFormat(pattern, Locale.getDefault()).format(date.getTime());
3031
}
3132
}

0 commit comments

Comments
 (0)