Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different date format for JavaDateInstant #36

Open
demogorgorn opened this issue Jul 1, 2015 · 4 comments
Open

Different date format for JavaDateInstant #36

demogorgorn opened this issue Jul 1, 2015 · 4 comments
Assignees

Comments

@demogorgorn
Copy link

Hello! Is it possible to cpecify different date format or should I write new subclass of JavaDateInstant? Thanks!

@demogorgorn
Copy link
Author

Sorry, I've found - JavaDatePrinter.java. Thanks!

@demogorgorn
Copy link
Author

If someone is interested in:

 startDatePicker.setInstantPrinter(new FormatDatePrinter("E, dd.MM.yyyy"));

And custom formatter class:

import com.marvinlabs.widget.floatinglabel.instantpicker.DateInstant;
import com.marvinlabs.widget.floatinglabel.instantpicker.DatePrinter;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class FormatDatePrinter<DateInstantT extends DateInstant> implements DatePrinter<DateInstantT> {

    final String dateFormat;

    public FormatDatePrinter(String dateFormat) {
        this.dateFormat = (dateFormat != null) ? dateFormat : "dd.MM.yyyy";
    }

    @Override
    public String print(DateInstant dateInstant) {
        if (dateInstant == null) return "";

        Calendar cal = new GregorianCalendar(dateInstant.getYear(), dateInstant.getMonthOfYear() + 1, dateInstant.getDayOfMonth());
        SimpleDateFormat sdf = new SimpleDateFormat(this.dateFormat);
        return sdf.format(cal.getTime());
    }
}

@vpratfr
Copy link
Member

vpratfr commented Jul 1, 2015

Your class could be a useful addition to the library. Thanks.

@vpratfr vpratfr reopened this Jul 1, 2015
@vpratfr
Copy link
Member

vpratfr commented Jul 1, 2015

Re-opening to remember to include that class

@vpratfr vpratfr self-assigned this Jul 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants