Skip to content

Commit f38feda

Browse files
vanshikaaroramaskaravivek
authored andcommitted
modified date format (commons-app#2341)
* modified date format * mediadetail fragment modified * added the function in dateutils * modified imports
1 parent 3482993 commit f38feda

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.support.annotation.Nullable;
1313
import android.text.Html;
1414
import android.text.TextUtils;
15+
import android.text.format.DateFormat;
1516
import android.util.TypedValue;
1617
import android.view.LayoutInflater;
1718
import android.view.View;
@@ -53,6 +54,7 @@
5354
import fr.free.nrw.commons.mwapi.MediaWikiApi;
5455
import fr.free.nrw.commons.ui.widget.CompatTextView;
5556
import timber.log.Timber;
57+
import fr.free.nrw.commons.utils.DateUtils;
5658

5759
import static android.content.Context.CLIPBOARD_SERVICE;
5860
import static android.view.View.GONE;
@@ -518,8 +520,7 @@ private String prettyUploadedDate(Media media) {
518520
if (date == null || date.toString() == null || date.toString().isEmpty()) {
519521
return "Uploaded date not available";
520522
}
521-
SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy", Locale.getDefault());
522-
return formatter.format(date);
523+
return DateUtils.dateInLocaleFormat(date);
523524
}
524525

525526
/**

app/src/main/java/fr/free/nrw/commons/utils/DateUtils.java

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.free.nrw.commons.utils;
22

3+
import android.text.format.DateFormat;
4+
35
import java.text.SimpleDateFormat;
46
import java.util.Calendar;
57
import java.util.Date;
@@ -41,4 +43,14 @@ public static String getCurrentDate() {
4143
Date date = new Date();
4244
return dateFormat.format(date);
4345
}
46+
public static String dateInLocaleFormat(Date date){
47+
String formatter;
48+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
49+
formatter = new SimpleDateFormat(DateFormat.getBestDateTimePattern(Locale.getDefault(), "dd MMM yyyy"), Locale.getDefault()).format(date);
50+
}
51+
else {
52+
formatter = String.valueOf(new SimpleDateFormat("dd MMM yyyy", Locale.getDefault()));
53+
}
54+
return formatter;
55+
}
4456
}

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 commit comments

Comments
 (0)