Example usage for org.joda.time.format DateTimeFormatter parseLocalDate

List of usage examples for org.joda.time.format DateTimeFormatter parseLocalDate

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseLocalDate.

Prototype

public LocalDate parseLocalDate(String text) 

Source Link

Document

Parses only the local date from the given text, returning a new LocalDate.

Usage

From source file:vn.webapp.service.AcademicYearServiceImpl.java

public int getCurSemester() {
    List<AcademicYear> acadYearList = academicYearDAO.getList();
    AcademicYear res = new AcademicYear();
    LocalDate today = LocalDate.now();
    LocalDate firstdate = LocalDate.now();
    LocalDate enddate = LocalDate.now();
    for (AcademicYear aY : acadYearList) {
        DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
        DateTimeFormatter fmt1 = DateTimeFormat.forPattern("yyyy-MM-dd");
        try {//from   w w  w  .  j  a va  2  s  .  c  om
            firstdate = fmt.parseLocalDate(aY.getACAYEAR_FromDate());
            enddate = fmt.parseLocalDate(aY.getACAYEAR_ToDate());
        } catch (IllegalArgumentException e) {
            firstdate = fmt1.parseLocalDate(aY.getACAYEAR_FromDate());
            enddate = fmt1.parseLocalDate(aY.getACAYEAR_ToDate());
        }
        //System.out.println(aY.getACAYEAR_Code()+":"+firstdate+" --> "+enddate);
        if ((Days.daysBetween(firstdate, today).getDays() > 0)
                && (Days.daysBetween(today, enddate).getDays() > 0)) {
            int weeks = Days.daysBetween(firstdate, today).getDays() / 7 + 1;
            if (weeks < 23)
                return 1;
            else if (weeks < 45)
                return 2;
            else
                return 3;
        }
    }
    return 0;
}