List of usage examples for com.google.gwt.i18n.client DateTimeFormat parseStrict
public Date parseStrict(String text) throws IllegalArgumentException
From source file:com.github.nmorel.gwtjackson.client.utils.DateFormat.java
License:Apache License
/** * Parse a date using the {@link DateTimeFormat} given in * parameter and the browser timezone./*from w w w.j a v a2 s .c om*/ * * @param format format to use * @param date date to parse * * @return the parsed date */ public static Date parse(DateTimeFormat format, String date) { return format.parseStrict(date); }
From source file:com.google.zxing.web.generator.client.CalendarEventGenerator.java
License:Apache License
private static Date getDateFromTextBox(HasText textBox) throws GeneratorException { DateTimeFormat extractTime = DateTimeFormat.getFormat("HHmm"); try {//from ww w .java 2 s.co m return extractTime.parseStrict(textBox.getText()); } catch (IllegalArgumentException iae) { throw new GeneratorException("Invalid time"); } }
From source file:com.gwtmodel.table.Utils.java
License:Apache License
public static Date toD(String s) { DateTimeFormat te = getDateFormat(IGetCustomValues.DATEFORMAT); try {/* w w w. j a va 2s . c om*/ return te.parseStrict(s); } catch (IllegalArgumentException e) { return null; } }
From source file:com.gwtmodel.table.Utils.java
License:Apache License
public static Timestamp toDT(String s) { DateTimeFormat te = getDateFormat(IGetCustomValues.DATETIMEFORMAT); Date d;//from w w w . jav a2 s. com try { d = te.parseStrict(s); } catch (IllegalArgumentException e) { return null; } Timestamp t = new Timestamp(d.getTime()); return t; }
From source file:com.vaadin.terminal.gwt.client.DateTimeService.java
License:Open Source License
/** * Parses the given date string using the given format string and the locale * set in this DateTimeService instance. * //w w w. ja va 2 s . c om * @param dateString * Date string e.g. "1 February 2010" * @param formatString * Format string e.g. "d MMMM yyyy" * @param lenient * true to use lenient parsing, false to use strict parsing * @return A Date object representing the dateString. Never returns null. * @throws IllegalArgumentException * if the parsing fails * */ public Date parseDate(String dateString, String formatString, boolean lenient) throws IllegalArgumentException { /* DateTimeFormat uses the browser's locale */ DateTimeFormat format = DateTimeFormat.getFormat(formatString); /* * Parse month names separately when locale for the DateTimeService is * not the same as the browser locale */ dateString = parseMonthName(dateString, formatString); Date date; if (lenient) { date = format.parse(dateString); } else { date = format.parseStrict(dateString); } // Some version of Firefox sets the timestamp to 0 if parsing fails. if (date != null && date.getTime() == 0) { throw new IllegalArgumentException("Parsing of '" + dateString + "' failed"); } return date; }
From source file:edu.caltech.ipac.firefly.data.form.DateFieldDef.java
public Date getDate(Object val) { if (StringUtils.isEmpty(val)) return null; Date parsed = null;//from w w w . j av a 2 s .co m if (val instanceof Date) { return (Date) val; } else { DateTimeFormat dtFormat; if (formats != null) { for (String f : formats) { dtFormat = DateTimeFormat.getFormat(f); try { parsed = dtFormat.parseStrict(val.toString().trim()); return parsed; } catch (Exception e) { } } } if (parsed == null) { throw new IllegalArgumentException("Unable to parse date from " + val.toString()); } else { return parsed; } } }
From source file:net.webpasswordsafe.client.ui.ReportDialog.java
License:Open Source License
private boolean isValidDate(String value, String format) { boolean isValid = false; try {//w ww .ja va 2 s . c om DateTimeFormat df = DateTimeFormat.getFormat(format); df.parseStrict(value); isValid = true; } catch (IllegalArgumentException e) { } return isValid; }
From source file:org.kuali.student.common.ui.client.validator.ClientDateParser.java
License:Educational Community License
public Date parseDate(String input) { Date result = null;/* w w w. ja va 2 s.c om*/ for (DateTimeFormat format : formats) { try { result = format.parseStrict(input); } catch (IllegalArgumentException e) { // just eat it } if (result != null) { break; } } if (result == null) { throw new DateParseException("Invalid date value: " + input); } return result; }
From source file:org.n52.client.Application.java
License:Open Source License
private static void fireNewTimeRangeEvent(TimeRange timeRange) { try {/*w w w . j a v a2 s . c o m*/ DateTimeFormat formatter = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.ISO_8601); long begin = formatter.parseStrict(timeRange.getStart()).getTime(); long end = formatter.parseStrict(timeRange.getEnd()).getTime(); Toaster.getToasterInstance().addMessage("Begin: " + timeRange.getStart()); Toaster.getToasterInstance().addMessage("End: " + timeRange.getEnd()); EventBus.getMainEventBus().fireEvent(new DatesChangedEvent(begin, end, true)); } catch (Exception e) { if (!GWT.isProdMode()) { GWT.log("Unparsable TimeRange: " + timeRange, e); } } }
From source file:org.openempi.webapp.client.ui.util.Utility.java
License:Open Source License
public static Date StringToDate(String strDate) { Date date = null;/*from w w w . jav a 2 s. c om*/ if (strDate != null && !strDate.isEmpty()) { DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd"); date = dtf.parseStrict(strDate); } return date; }