package cgeo.geocaching.ui; import cgeo.geocaching.cgeoapplication; import android.content.Context; import android.text.format.DateUtils; public abstract class Formatter { /** Text separator used for formatting texts */ public static final String SEPARATOR = " ยท "; private static final Context context = cgeoapplication.getInstance().getBaseContext(); /** * Generate a time string according to system-wide settings (locale, 12/24 hour) * such as "13:24". * * @param date * milliseconds since the epoch * @return the formatted string */ public static String formatTime(long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_TIME); } /** * Generate a date string according to system-wide settings (locale, date format) * such as "20 December" or "20 December 2010". The year will only be included when necessary. * * @param date * milliseconds since the epoch * @return the formatted string */ public static String formatDate(long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE); } /** * Generate a date string according to system-wide settings (locale, date format) * such as "20 December 2010". The year will always be included, making it suitable * to generate long-lived log entries. * * @param date * milliseconds since the epoch * @return the formatted string */ public static String formatFullDate(long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR); } /** * Generate a numeric date string according to system-wide settings (locale, date format) * such as "10/20/2010". * * @param date * milliseconds since the epoch * @return the formatted string */ public static String formatShortDate(long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE); } /** * Generate a numeric date and time string according to system-wide settings (locale, * date format) such as "7 sept. at 12:35". * * @param context * a Context * @param date * milliseconds since the epoch * @return the formatted string */ public static String formatShortDateTime(Context context, long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL); } }