Search in sources :

Example 16 with ParseException

use of java.text.ParseException in project Openfire by igniterealtime.

the class Application method getDouble.

private double getDouble(String value) throws ParseException {
    int n;
    if ((n = value.indexOf(":")) > 0) {
        value = value.substring(0, n);
    }
    double f = 0.0;
    try {
        f = Double.parseDouble(value);
    } catch (NumberFormatException e) {
        throw new ParseException("Invalid double value: " + value, 0);
    }
    return f;
}
Also used : ParseException(java.text.ParseException)

Example 17 with ParseException

use of java.text.ParseException in project head by mifos.

the class DateUtils method convertUserToDbFmt.

public static String convertUserToDbFmt(String userDate, String userPattern) throws InvalidDateException {
    try {
        SimpleDateFormat userFormat = new SimpleDateFormat(userPattern, dateLocale);
        // userFormat.setLenient(false);
        java.util.Date date = userFormat.parse(userDate);
        return toDatabaseFormat(date);
    } catch (ParseException e) {
        throw new InvalidDateException(userDate);
    }
}
Also used : Date(java.util.Date) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with ParseException

use of java.text.ParseException in project head by mifos.

the class DateUtils method convertDbToUserFmt.

public static String convertDbToUserFmt(String dbDate, String userPattern) throws InvalidDateException {
    try {
        SimpleDateFormat databaseFormat = new SimpleDateFormat(dbFormat, dateLocale);
        java.util.Date date = databaseFormat.parse(dbDate);
        SimpleDateFormat userFormat = new SimpleDateFormat(userPattern);
        return userFormat.format(date);
    } catch (ParseException e) {
        throw new InvalidDateException(dbDate, e);
    }
}
Also used : Date(java.util.Date) InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with ParseException

use of java.text.ParseException in project head by mifos.

the class DateUtils method getDateAsSentFromBrowser.

/**
     * "as sent from browser" is a bit of a misnomer; it really is (at least in
     * many cases), as formatted by a routine on the server side like
     * ClientCustActionForm#getDateOfBirth()
     *
     * @throws InvalidDateException
     */
public static java.sql.Date getDateAsSentFromBrowser(String value) throws InvalidDateException {
    if (value == null || value == "") {
        return null;
    }
    try {
        String formatStr = "d" + dateSeparator + "M" + dateSeparator + "yy";
        SimpleDateFormat format = new SimpleDateFormat(formatStr, internalLocale);
        format.setLenient(false);
        return new java.sql.Date(format.parse(value).getTime());
    } catch (ParseException e) {
        throw new InvalidDateException(value);
    }
}
Also used : InvalidDateException(org.mifos.application.admin.servicefacade.InvalidDateException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LocalDate(org.joda.time.LocalDate)

Example 20 with ParseException

use of java.text.ParseException in project head by mifos.

the class MifosBatchJob method computeMissedJobLaunches.

@SuppressWarnings("unchecked")
public List<Date> computeMissedJobLaunches(Date from, Date to, Trigger trigger, boolean onDemandRun) throws Exception {
    List<Date> missedLaunches = new LinkedList<Date>();
    if (trigger instanceof CronTrigger) {
        CronTrigger cronTrigger = new CronTrigger();
        cronTrigger.setStartTime(from);
        cronTrigger.setNextFireTime(from);
        String cronExpression = ((CronTrigger) trigger).getCronExpression();
        try {
            cronTrigger.setCronExpression(cronExpression);
        } catch (ParseException pe) {
            throw new Exception(pe);
        }
        List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(cronTrigger, null, from, to);
        missedLaunches.addAll(computationOutcome);
        missedLaunches.remove(0);
        if (!onDemandRun && missedLaunches.size() > 0) {
            missedLaunches.remove(missedLaunches.size() - 1);
        }
    } else if (trigger instanceof SimpleTrigger) {
        SimpleTrigger simpleTrigger = new SimpleTrigger();
        simpleTrigger.setStartTime(from);
        simpleTrigger.setNextFireTime(from);
        simpleTrigger.setRepeatInterval(((SimpleTrigger) trigger).getRepeatInterval());
        simpleTrigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
        List<Date> computationOutcome = TriggerUtils.computeFireTimesBetween(simpleTrigger, null, from, to);
        missedLaunches.addAll(computationOutcome);
        missedLaunches.remove(0);
        if (!onDemandRun && missedLaunches.size() > 0) {
            missedLaunches.remove(missedLaunches.size() - 1);
        }
    }
    return missedLaunches;
}
Also used : CronTrigger(org.quartz.CronTrigger) LinkedList(java.util.LinkedList) List(java.util.List) ParseException(java.text.ParseException) SimpleTrigger(org.quartz.SimpleTrigger) LinkedList(java.util.LinkedList) Date(java.util.Date) ParseException(java.text.ParseException) BatchJobException(org.mifos.framework.components.batchjobs.exceptions.BatchJobException) JobExecutionException(org.quartz.JobExecutionException) JobInstanceAlreadyCompleteException(org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException)

Aggregations

ParseException (java.text.ParseException)3530 Date (java.util.Date)1381 SimpleDateFormat (java.text.SimpleDateFormat)1296 IOException (java.io.IOException)366 ArrayList (java.util.ArrayList)334 DateFormat (java.text.DateFormat)305 Calendar (java.util.Calendar)288 Test (org.junit.Test)274 HashMap (java.util.HashMap)139 Matcher (java.util.regex.Matcher)99 File (java.io.File)97 GregorianCalendar (java.util.GregorianCalendar)97 Map (java.util.Map)95 List (java.util.List)92 BigDecimal (java.math.BigDecimal)72 Locale (java.util.Locale)68 ParsePosition (java.text.ParsePosition)57 Timestamp (java.sql.Timestamp)55 InputStream (java.io.InputStream)53 DecimalFormat (java.text.DecimalFormat)50