Java Code Examples for com.google.gwt.i18n.client.DateTimeFormat#parse()

The following examples show how to use com.google.gwt.i18n.client.DateTimeFormat#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkflowTaskFormView.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private Object getParameterValue(Record record, ValueType valueType, DisplayType displayType) {
    Object val = record.getAttributeAsObject(WorkflowParameterDataSource.FIELD_VALUE);
    if (valueType == ValueType.DATETIME && val instanceof String) {
        DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601);
        val = format.parse((String) val);
    } else if (displayType == DisplayType.CHECKBOX && val instanceof String) {
        if (Boolean.TRUE.toString().equalsIgnoreCase((String) val)) {
            val = true;
        } else if (Boolean.FALSE.toString().equalsIgnoreCase((String) val)) {
            val = false;
        } else {
            try {
                val = new BigDecimal((String) val).compareTo(BigDecimal.ZERO) > 0;
            } catch (NumberFormatException e) {
                // ignore
            }
        }
    } else if (displayType == DisplayType.CHECKBOX && val instanceof Number) {
        val = ((Number) val).doubleValue() > 0;
    }
    return val;
}
 
Example 2
Source File: DateOfBirthPicker.java    From gwt-material-addins with Apache License 2.0 6 votes vote down vote up
public boolean validateLeapYear(Integer month, Integer day, Integer year) {
    if (month != null && day != null && year != null) {
        String dateToValidate = month + 1 + "/" + day + "/" + year;
        if (dateToValidate == null) {
            return false;
        }
        DateTimeFormat sdf = DateTimeFormat.getFormat("MM/dd/yyyy");
        try {
            Date date = sdf.parse(dateToValidate);
            if (date.getMonth() != month) {
                return false;
            }
            value = date;
        } catch (Exception e) {

            e.printStackTrace();
            return false;
        }
        return true;
    }
    return false;
}
 
Example 3
Source File: ISO8601.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse string date in format "YYYY-MM-DDThh:mm:ss.SSSTZD"
 */
public static Date parseExtended(String value) {
	if (value == null) {
		return null;
	} else {
		DateTimeFormat dtf = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601);
		return dtf.parse(value);
	}
}
 
Example 4
Source File: ISO8601.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse string date in format "yyyyMMddHHmmss"
 */
public static Date parseBasic(String value) {
	if (value == null) {
		return null;
	} else {
		DateTimeFormat dtf = DateTimeFormat.getFormat(BASIC_PATTER);
		return dtf.parse(value);
	}
}
 
Example 5
Source File: UTCDateBoxImplHtml5.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the supplied text and converts it to a Long
 * corresponding to that midnight in UTC on the specified date.
 * 
 * @return null if it fails to parsing using the specified
 *         DateTimeFormat
 */
private Long string2long(String text, DateTimeFormat fmt) {
    
    // null or "" returns null
    if (text == null) return null;
    text = text.trim();
    if (text.length() == 0) return null;
    
    Date date = fmt.parse(text);
    return date != null ? UTCDateBox.date2utc(date) : null;
}
 
Example 6
Source File: HistoryPopupPanel.java    From EasyML with Apache License 2.0 4 votes vote down vote up
/**
 * UI Initialization
 */
protected void init() {
	this.setSize("850px", "400px");
	this.setGlassEnabled(true);
	this.setModal(true);

	desc.setText(desc.getText()+"  Job Id - "+bdaJobId);
	closeButton.setSize("10px", "10px");
	closeButton.setStyleName("closebtn");

	VerticalPanel topPanel = new VerticalPanel(); //Outermost vertical panel
	topPanel.add(closeButton);
	topPanel.setCellHeight(closeButton, "13px");
	topPanel.setStyleName("vpanel");
	desc.setStyleName("popupTitle");
	topPanel.add(desc);
	topPanel.setCellHeight(desc, "30px");

	HorizontalPanel optPanel = new HorizontalPanel(); //Operation panel(include search, batch delete.etc)
	optPanel.addStyleName("run-history-optPanel");
	DateTimeFormat pickerFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
	startTimeBox.setFormat(new DateBox.DefaultFormat(pickerFormat));
	startTimeBox.getDatePicker().addStyleName("run-history-datepicker-popup");
	endTimeBox.setFormat(new DateBox.DefaultFormat(pickerFormat));
	endTimeBox.getDatePicker().addStyleName("run-history-datepicker-popup");
	searchBtn.removeStyleName("gwt-Button");
	searchBtn.addStyleName("run-history-search-button");
	//The initial time is set to 2016-1-1
	endTime = new Date();
	DateTimeFormat tmpFormatter = DateTimeFormat.getFormat("yyyy-MM-dd");
	startTime = tmpFormatter.parse("2016-01-01");
	selectAllChkBox.setVisible(false);
	batchDelBtn.removeStyleName("gwt-Button");
	batchDelBtn.addStyleName("run-history-batch-del-button");

	optPanel.add(startTimeLabel); 
	optPanel.add(startTimeBox);
	optPanel.add(endTimeLabel);
	optPanel.add(endTimeBox);
	optPanel.add(searchBtn);
	if(isExample && !AppController.power.equals("111"))  //Example job only can be deleted by administrator privileges
	{}
	else
		optPanel.add(batchDelBtn);
	optPanel.add(selectAllChkBox);

	runHistoryGrid.addStyleName("run-history-table"); //Data view
	runHistoryGrid.addStyleName("table-striped");
	runHistoryGrid.addStyleName("table-hover");
	runHistoryGrid.resize(rowNum, colNum);
	for(int i=0;i<colNum;i++)
	{
		runHistoryGrid.setText(0, i, columns[i]);
	}
	initGridData();

	topPanel.add(optPanel);
	topPanel.add(runHistoryGrid);

	VerticalPanel bottomPanel = new VerticalPanel(); //Paging control
	bottomPanel.add(pageGrid);
	bottomPanel.addStyleName("run-history-bottomPanel");

	VerticalPanel panel = new VerticalPanel();
	panel.add(topPanel);
	panel.add(bottomPanel);

	this.add(panel);
	this.setStyleName("loading_container");
}
 
Example 7
Source File: UTCTimeBoxImplShared.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
protected static final Long parseUsingFormat(String text, DateTimeFormat fmt) {
    Date date = new Date(0);
    int num = fmt.parse(text, 0, date);
    return (num != 0) ? new Long(normalizeInLocalRange(date.getTime() - UTCDateBox.timezoneOffsetMillis(date))) : null;
}
 
Example 8
Source File: DisplayerGwtFormatter.java    From dashbuilder with Apache License 2.0 4 votes vote down vote up
@Override
public Date parseDate(String pattern, String d) {
    DateTimeFormat df = getDateFormat(pattern);
    return df.parse(d);
}