Example usage for java.text SimpleDateFormat setLenient

List of usage examples for java.text SimpleDateFormat setLenient

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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:graph.module.DateParseModule.java

private synchronized void initFormats() {
    if (acceptedFormats_ != null)
        return;//from  w w  w  .  j  a  v  a 2  s  .  c om
    acceptedFormats_ = new ArrayList<>();
    acceptedFormats_.add(new SimpleDateFormat("yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("yyyy MM"));
    acceptedFormats_.add(new SimpleDateFormat("yyyy MM dd"));
    acceptedFormats_.add(new SimpleDateFormat("MM"));
    acceptedFormats_.add(new SimpleDateFormat("MMMM"));
    acceptedFormats_.add(new SimpleDateFormat("MM yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("MMMM yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("MMMM dd yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("EEEE MMMM dd yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("dd MM yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("MM dd yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("dd MMMM yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("EEEE dd MM yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("EEEE dd MMMM yyyy"));
    acceptedFormats_.add(new SimpleDateFormat("dd MMMM"));
    acceptedFormats_.add(new SimpleDateFormat("MMMM dd"));
    acceptedFormats_.add(new SimpleDateFormat("dd MM"));

    for (SimpleDateFormat sdf : acceptedFormats_) {
        sdf.setLenient(false);
    }
}

From source file:org.mule.transport.http.transformers.MuleMessageToHttpResponseTestCase.java

@Test
public void testSetDateOnOutbound() throws Exception {
    MuleMessageToHttpResponse transformer = new MuleMessageToHttpResponse();
    MuleMessage msg = mock(MuleMessage.class);

    HttpResponse response = transformer.createResponse(null, "UTF-8", msg);
    Header[] headers = response.getHeaders();

    boolean hasDateHeader = false;
    for (Header header : headers) {
        if (HttpConstants.HEADER_DATE.equals(header.getName())) {
            hasDateHeader = true;//from  w  w w .  j a v a  2s  . c  o  m
            // validate that the header is in the appropriate format (rfc-1123)
            SimpleDateFormat formatter = new SimpleDateFormat(HttpConstants.DATE_FORMAT, Locale.US);
            formatter.setLenient(false);
            try {
                formatter.parse(header.getValue());
            } catch (ParseException e) {
                // will to accept 24 hour style (which is really what it's supposed to be).
                formatter.setLenient(true);
                formatter.parse(header.getValue());
                formatter = new SimpleDateFormat(HttpConstants.DATE_FORMAT.replaceFirst("hh", "HH"), Locale.US);
                formatter.setLenient(false);
                formatter.parse(header.getValue());
            }
        }
    }
    Assert.assertTrue("Missing 'Date' header", hasDateHeader);
}

From source file:org.jasig.portlet.ClassifiedsPortlet.web.SubmitAdFormController.java

@InitBinder
public void initBinder(PortletRequest request, PortletRequestDataBinder binder) throws Exception {

    SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

    dateFormat.setLenient(false);

    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));

    binder.registerCustomEditor(Category.class, new CategoryEditor(categoryService));
}

From source file:com.chalmers.feedlr.model.FacebookItem.java

@JsonProperty("updated_time")
public void setTimestamp(String timestamp) {

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+SSSS");
    dateFormat.setLenient(false);
    Date created = null;//from w w  w.  j a v  a 2 s . co m
    try {
        created = dateFormat.parse(timestamp);
    } catch (Exception e) {
        Log.e(getClass().getName(), e.getMessage());
    }

    SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    this.timestamp = d.format(created);
}

From source file:de.berlios.jhelpdesk.web.preferences.filter.CustomFilterEditController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    dateFormat.setLenient(true);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    binder.registerCustomEditor(User.class, userEditor);
    binder.registerCustomEditor(TicketCategory.class, categoryEditor);
}

From source file:org.motechproject.server.omod.web.controller.SearchPatientsController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    String datePattern = "dd/MM/yyyy";
    SimpleDateFormat dateFormat = new SimpleDateFormat(datePattern);
    dateFormat.setLenient(false);

    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true, datePattern.length()));
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}

From source file:com.rsmart.kuali.kfs.fp.batch.DisbursementVoucherInputFileType.java

/**
 * @see org.kuali.kfs.sys.batch.BatchInputFileType#getFileName(java.lang.String, java.lang.Object, java.lang.String)
 *//* www . ja  v a 2s .c  o  m*/
public String getFileName(String principalId, Object parsedFileContents, String fileUserIdentifer) {
    Timestamp currentTimestamp = dateTimeService.getCurrentTimestamp();

    StringBuffer buf = new StringBuffer();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd_HHmmss");
    formatter.setLenient(false);
    formatter.format(currentTimestamp, buf, new FieldPosition(0));

    String fileName = FPConstants.DV_FILE_UPLOAD_FILE_PREFIX + principalId;
    if (StringUtils.isNotBlank(fileUserIdentifer)) {
        fileName += "_" + StringUtils.remove(fileUserIdentifer, " ");
    }
    fileName += "_" + buf.toString();

    return fileName;
}

From source file:net.heroicefforts.viable.android.dao.VersionDetail.java

/**
 * Instantiate the release state based upon the JIRA JSON format.
 * /*www . j a v  a  2 s . com*/
 * @param obj JIRA JSON release object 
 * @throws JSONException if there's an error parsing the JSON.
 */
public VersionDetail(JSONObject obj) throws JSONException {
    this.name = obj.getString("name");
    this.description = obj.getString("description");

    if (obj.has("releaseDate")) {
        try {
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            fmt.setLenient(true);
            this.releaseDate = fmt.parse(obj.getString("releaseDate"));
        } catch (ParseException e) {
            Log.e(TAG, "Error parsing JSON dates.", e);
            throw new JSONException("Error parsing JSON dates.");
        }
    }
}

From source file:com.chalmers.feedlr.model.TwitterItem.java

/**
 * Sets the timestamp of a Ttwitter Item.
 * //  w  ww.java  2  s  .  c o m
 * @param timestamp
 *            the time the Twitter item was created
 */
@JsonProperty("created_at")
public void setTimestamp(String timestamp) {
    // Converts from the format to dateformat.
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZZZ yyyy", Locale.ENGLISH);
    dateFormat.setLenient(false);
    Date created = null;

    try {
        created = dateFormat.parse(timestamp);
    } catch (Exception e) {
        Log.e(getClass().getName(), e.getMessage());
    }

    SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    this.timestamp = d.format(created);
}

From source file:io.github.benas.todolist.web.controller.TodoController.java

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(TodoListUtils.DATE_FORMAT);
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    binder.registerCustomEditor(Priority.class, new TodoPriorityPropertyEditor());
}