From 0392bf6a0278b679fdd4d0d493e6689702c71fb9 Mon Sep 17 00:00:00 2001 From: chschtsch Date: Fri, 20 Nov 2015 00:49:52 +0300 Subject: [PATCH 1/2] fix bug with upload date + better way to parse it --- .../newpipe/VideoItemDetailFragment.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 81636d825..4be7d74f5 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -32,6 +32,8 @@ import android.view.MenuItem; import java.net.URL; import java.text.DateFormat; import java.text.NumberFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -240,15 +242,14 @@ public class VideoItemDetailFragment extends Fragment { thumbsUpView.setText(nf.format(info.like_count)); thumbsDownView.setText(nf.format(info.dislike_count)); - //this is horribly convoluted - //TODO: find a better way to convert YYYY-MM-DD to a locale-specific date - //suggestions are welcome - int year = Integer.parseInt(info.upload_date.substring(0, 4)); - int month = Integer.parseInt(info.upload_date.substring(5, 7)); - int date = Integer.parseInt(info.upload_date.substring(8, 10)); - Calendar cal = Calendar.getInstance(); - cal.set(year, month, date); - Date datum = cal.getTime(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date datum = null; + try { + datum = formatter.parse(info.upload_date); + } catch (ParseException e) { + e.printStackTrace(); + } + DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); String localisedDate = df.format(datum); From fa1d386fccec4491006bb1faf62ba9ce13b82810 Mon Sep 17 00:00:00 2001 From: chschtsch Date: Fri, 20 Nov 2015 00:52:43 +0300 Subject: [PATCH 2/2] cleanup --- .../main/java/org/schabi/newpipe/VideoItemDetailFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 4be7d74f5..c883e7f8d 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -35,7 +35,6 @@ import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.Vector;