diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-18 20:19:26 -0500 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-18 20:19:26 -0500 |
commit | 880fd1dcd657e53a47d15f8bfd3c491071f13f90 (patch) | |
tree | 87a4e956e8da9c4c3d560ccbfe0caabec09af020 /core/src/main | |
parent | d487949a3680f3d8ef6d766cea60cd154d7f7f05 (diff) | |
parent | 0a0c2850175936a6e6711322a486411ab8af834a (diff) | |
download | AntennaPod-880fd1dcd657e53a47d15f8bfd3c491071f13f90.zip |
Merge pull request #1554 from mfietz/pub_date_last_year
Pub date formatting
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java index 1a148673c..4b4201b50 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.core.util; +import android.content.Context; import android.util.Log; import org.apache.commons.lang3.StringUtils; @@ -7,6 +8,7 @@ import org.apache.commons.lang3.StringUtils; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; @@ -141,4 +143,17 @@ public class DateUtils { format.setTimeZone(defaultTimezone); return format.format(date); } + + public static String formatAbbrev(final Context context, final Date date) { + GregorianCalendar cal = new GregorianCalendar(); + cal.add(GregorianCalendar.YEAR, -1); + // some padding, because no one really remembers what day of the month it is + cal.add(GregorianCalendar.DAY_OF_MONTH, 10); + boolean withinLastYear = date.after(cal.getTime()); + int format = android.text.format.DateUtils.FORMAT_ABBREV_ALL; + if(withinLastYear) { + format |= android.text.format.DateUtils.FORMAT_NO_YEAR; + } + return android.text.format.DateUtils.formatDateTime(context, date.getTime(), format); + } } |