Search in sources :

Example 1 with DateTimeFormatter

use of org.threeten.bp.format.DateTimeFormatter in project wire-android by wireapp.

the class ZTimeFormatter method getSingleMessageTime.

private static String getSingleMessageTime(Context context, Date date, boolean defaultLocale) {
    boolean is24HourFormat = DateFormat.is24HourFormat(context);
    Resources resources = defaultLocale ? getEnglishResources(context) : context.getResources();
    final String pattern = is24HourFormat ? resources.getString(R.string.timestamp_pattern__24h_format) : resources.getString(R.string.timestamp_pattern__12h_format);
    try {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
        return formatter.format(DateConvertUtils.asLocalDateTime(date).atZone(ZoneId.systemDefault()));
    } catch (Exception e) {
        ExceptionHandler.saveException(e, Thread.currentThread(), new CrashManagerListener() {

            @Override
            public String getDescription() {
                return pattern;
            }
        });
        if (!defaultLocale) {
            return getSingleMessageTime(context, date, true);
        } else {
            return "";
        }
    }
}
Also used : Resources(android.content.res.Resources) DateTimeFormatter(org.threeten.bp.format.DateTimeFormatter) CrashManagerListener(net.hockeyapp.android.CrashManagerListener)

Aggregations

Resources (android.content.res.Resources)1 CrashManagerListener (net.hockeyapp.android.CrashManagerListener)1 DateTimeFormatter (org.threeten.bp.format.DateTimeFormatter)1