Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    /**
     * This is a helper method for checking if the fromDate is later than the
     * toDate. This is necessary in case a user sends the dates with HTTP GET.
     *
     * @param fromDate
     * @param toDate
     * @return boolean
     */
    public static boolean checkDates(String fromDate, String toDate) {
        String formatString = DEFAULT_DATE_FORMAT;
        SimpleDateFormat sdf = new SimpleDateFormat(formatString);

        Date date1 = null;
        Date date2 = null;

        try {
            date1 = sdf.parse(fromDate);
            date2 = sdf.parse(toDate);
        } catch (ParseException e) {
            return false; // The user hasn't specified any dates
        }

        if (!date1.before(date2)) {
            return true; // Return true if date2 is earlier than date1
        } else {
            return false;
        }
    }
}