Example usage for java.text DateFormat setLenient

List of usage examples for java.text DateFormat setLenient

Introduction

In this page you can find the example usage for java.text DateFormat setLenient.

Prototype

public void setLenient(boolean lenient) 

Source Link

Document

Specify whether or not date/time parsing is to be lenient.

Usage

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public String getBookings(int packageID, int providerID) throws ParseException {
    List<BookingDetailAllDate> bookingDates = packageDAO.getBookingsForManagement(packageID, providerID);
    HashMap<String, BookingDetailAllDate> bookingsOverview = new HashMap<>();
    DateFormat fromFormat = new SimpleDateFormat("MM/dd/yyyy");
    fromFormat.setLenient(false);
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.setLenient(false);//from www  .j  a va 2  s .  c o  m
    if (bookingDates != null) {
        for (BookingDetailAllDate bookingDate : bookingDates) {
            if (bookingDate.getNoBookings() > 0) {
                Date date = fromFormat.parse(bookingDate.getSelectedDate());
                String tripStart = dateFormat.format(date);
                bookingsOverview.put(tripStart, bookingDate);
            }
        }
    }
    return gson.toJson(bookingsOverview);
}

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public String getSales(String data, int providerID) throws ParseException {
    int packageID;
    Date fromDate;//from   w w w .  j a  va 2s.  c  o m
    Date toDate;
    Calendar calendar = Calendar.getInstance();
    DateFormat MMddyyyyFormat = new SimpleDateFormat("MM/dd/yyyy");
    DateFormat ddMMyyyyFormat = new SimpleDateFormat("dd/MM/yyyy");
    ddMMyyyyFormat.setLenient(false);
    if (data == null) {
        packageID = 0;
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        fromDate = calendar.getTime();
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        toDate = calendar.getTime();
    } else {
        JsonObject jsonObject = gson.fromJson(data, JsonObject.class);
        String fromDateStr = jsonObject.get("fromDate").getAsString();
        String toDateStr = jsonObject.get("toDate").getAsString();
        packageID = jsonObject.get("packageID").getAsInt();
        fromDate = MMddyyyyFormat.parse(fromDateStr);
        toDate = MMddyyyyFormat.parse(toDateStr);
    }
    List<BookingDTO> bookings = bookingDAO.getSales(packageID, providerID);
    List<Sale> sales = new ArrayList<Sale>();
    Date toDay = new Date();
    DateFormat MMddyyyyHHmmssFormat = new SimpleDateFormat("MM/dd/yyyy HH:ss:mm");
    MMddyyyyFormat.setLenient(false);
    for (BookingDTO booking : bookings) {
        String bookingDateStr = booking.getBookingDate().substring(0, 10);
        Date bookingDate = MMddyyyyFormat.parse(bookingDateStr);
        if (bookingDate.compareTo(fromDate) >= 0 && bookingDate.compareTo(toDate) <= 0) {
            int tripperID = booking.getTripperID();
            String tripperName = booking.getTripperFirstName() + " " + booking.getTripperLastName();
            int mainPackageID = booking.getPackageID();
            String packageName = booking.getPackageName();
            int status;
            String paidDateStr = booking.getPaid();
            if (paidDateStr != null && !paidDateStr.equals("none")) {
                status = 1;
            } else {
                status = 4;
            }
            double revenue = (booking.getAdultPrice() * booking.getNumberOfAdults()
                    + booking.getChildPrice() * booking.getNumberOfChilds())
                    * (100 - booking.getYouTripperPercentage() - booking.getProfitPercentage()) / 100;
            Sale sale = new Sale(bookingDateStr, tripperID, tripperName, mainPackageID, packageName, status,
                    revenue);
            sales.add(sale);
        }
    }
    return gson.toJson(sales);
}