package com.alexstyl.specialdates.date;

import android.content.Context;
import android.text.format.DateUtils;

import com.alexstyl.specialdates.MementoApplication;

public final class DateDisplayStringCreator {

    private static final String SEPARATOR = "-";
    private static final String ZERO = "0";

    private static DateDisplayStringCreator instance;

    public static DateDisplayStringCreator getInstance() {
        if (instance == null) {
            instance = new DateDisplayStringCreator();
        }
        return instance;
    }

    public String stringOf(Date date) {
        StringBuilder str = new StringBuilder();
        addYear(date, str);
        str.append(SEPARATOR);
        addMonth(date, str);
        str.append(SEPARATOR);
        addDayOfMonth(date, str);
        return str.toString();
    }

    private void addYear(Date date, StringBuilder str) {
        if (date.hasYear()) {
            str.append(date.getYear());
        } else {
            str.append(SEPARATOR);
        }
    }

    private void addMonth(Date date, StringBuilder str) {
        boolean isSingleDigit = isSingleDigit(date.getMonth());
        if (isSingleDigit) {
            str.append(ZERO);
        }
        str.append(date.getMonth());
    }

    private void addDayOfMonth(Date date, StringBuilder str) {
        boolean isSingleDigit = isSingleDigit(date.getDayOfMonth());
        if (isSingleDigit) {
            str.append(ZERO);
        }
        str.append(date.getDayOfMonth());
    }

    private boolean isSingleDigit(int number) {
        return number < 10;
    }

    public String fullyFormattedBirthday(Date birthday) {
        Context appContext = MementoApplication.getContext();

        int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM | DateUtils.FORMAT_SHOW_DATE;

        if (birthday.hasYear()) {
            format_flags |= DateUtils.FORMAT_SHOW_YEAR;
        } else {
            format_flags |= DateUtils.FORMAT_NO_YEAR;
        }

        return DateUtils.formatDateTime(appContext, birthday.toMillis(), format_flags);
    }

//    public Date getDayDateFor(Date birthday) {
//        int year;
//        if (birthday.hasYear()) {
//            year = birthday.getYear();
//        } else {
//            year = Date.todaysYear();
//        }
//        return Date.on(birthday.getDayOfMonth(), birthday.getMonth(), year);
//    }

    public String fullyFormattedDate(Date date) {
        Context appContext = MementoApplication.getContext();

        int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_CAP_AMPM | DateUtils.FORMAT_SHOW_DATE;
        format_flags |= DateUtils.FORMAT_SHOW_YEAR;
        return DateUtils.formatDateTime(appContext, date.toMillis(), format_flags);

    }
}

@@ -2099,313 +2099,8 @@
  %7D%0A%0A
-//    public Date getDayDateFor(Date birthday) %7B%0A//        int year;%0A//        if (birthday.hasYear()) %7B%0A//            year = birthday.getYear();%0A//        %7D else %7B%0A//            year = Date.todaysYear();%0A//        %7D%0A//        return Date.on(birthday.getDayOfMonth(), birthday.getMonth(), year);%0A//    %7D%0A%0A
     

Remove comments