Java Code Examples for com.google.gwt.i18n.shared.DateTimeFormat

The following examples show how to use com.google.gwt.i18n.shared.DateTimeFormat. These examples are extracted from open source projects. 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 Project: cuba   Source File: CubaTimeFieldWidget.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean isValueParsable(String time) {
    if (nullRepresentation.equals(time)) {
        return true;
    }

    if (timeFormat == null || timeFormat.isEmpty()) {
        // let server side to parse
        return true;
    }

    DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat(timeFormat);
    try {
        dateTimeFormat.parseStrict(time);
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 2
Source Project: gwt-material-addins   Source File: MaterialTimePicker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Called after the lolliclock event <code>afterHide</code>.
 */
protected void afterHide() {
    String timeString = getTime();
    Date parsedDate = null;

    if (timeString != null && !timeString.equals("")) {
        try {
            parsedDate = DateTimeFormat.getFormat(options.hour24 ? "HH:mm" : "hh:mm aa").parse(timeString);
        } catch (IllegalArgumentException e) {
            // Silently catch parse errors
        }
    }

    setValue(parsedDate, true);

    // Remove class 'valid' after hide.
    getValidMixin().setOn(false);

    CloseEvent.fire(this, this.time);
    fireEvent(new BlurEvent() {});
}
 
Example 3
Source Project: errai-tutorial   Source File: Contact.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
  final StringBuilder builder = new StringBuilder();
  builder.append("[Contact: id=")
         .append(id)
         .append(", nickname=")
         .append(nickname)
         .append(", fullname=")
         .append(fullname)
         .append(", phonenumber=")
         .append(phonenumber)
         .append(", email=")
         .append(email)
         .append(", birthday=")
         .append(DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(birthday).substring(0, 10))
         .append(", notes=\"")
         .append(notes.substring(0, 20) + (notes.length() > 20 ? "..." : ""));

  return builder.toString();
}
 
Example 4
Source Project: gwt-material-addins   Source File: MaterialTimePicker.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setValue(Date time, boolean fireEvents) {
    this.time = time;
    if (this.time == null) {
        return;
    }
    label.removeStyleName(CssName.ACTIVE);
    label.addStyleName(CssName.ACTIVE);
    $(timeInput.getElement()).val(DateTimeFormat.getFormat(options.hour24 ? "HH:mm" : "hh:mm aa").format(time));
    super.setValue(time, fireEvents);
}
 
Example 5
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 5 votes vote down vote up
private long adjustToMiddleOfDay(long zonedDate) {
    DateTimeFormat hourFormat = DateTimeFormat.getFormat("HH");
    String hourStr = hourFormat.format(new Date(zonedDate), getLocaleDataProvider().getTimeZone());
    int h = Integer.parseInt(hourStr);
    int addHours = 12 - h;
    return zonedDate + (addHours * HOUR_INTERVAL);
}
 
Example 6
Source Project: swcv   Source File: WordCloudLatestApp.java    License: MIT License 4 votes vote down vote up
private Grid createTable(List<WordCloud> clouds, boolean debug)
{
    Grid table = new Grid(clouds.size() + 1, debug ? 4 : 3);
    table.addStyleName("latest");
    CellFormatter cf = table.getCellFormatter();

    table.setHTML(0, 0, "<b>id</b>");
    table.setHTML(0, 1, "<b>creation date</b>");
    table.setHTML(0, 2, "<b>source</b>");
    cf.setWidth(0, 0, "10%");
    cf.setWidth(0, 1, "25%");
    cf.setWidth(0, 2, "65%");
    cf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    cf.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    cf.setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);

    if (debug)
    {
        table.setHTML(0, 3, "<b>ip</b>");
        cf.setWidth(0, 1, "20%");
        cf.setWidth(0, 2, "60%");
        cf.setWidth(0, 3, "10%");
        cf.setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER);
    }

    for (int i = 0; i < clouds.size(); i++)
    {
        WordCloud cloud = clouds.get(i);

        table.setHTML(i + 1, 0, "<a href='/cloud.html?id=" + cloud.getId() + "'>" + cloud.getId() + "</a>");
        Date dt = cloud.getCreationDateAsDate();
        table.setHTML(i + 1, 1, DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(dt));
        table.setWidget(i + 1, 2, createSourceField(cloud, debug));
        cf.setHorizontalAlignment(i + 1, 2, HasHorizontalAlignment.ALIGN_LEFT);

        if (debug)
        {
            table.setHTML(i + 1, 3, cloud.getCreatorIP());
        }
    }

    return table;
}
 
Example 7
Source Project: gantt   Source File: LocaleDataProvider.java    License: Apache License 2.0 4 votes vote down vote up
/** Format zoned date. */
String formatDate(Date zonedDate, DateTimeFormat formatter);
 
Example 8
Source Project: gantt   Source File: GanttConnector.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String formatDate(Date zonedDate, DateTimeFormat formatter) {
    return formatter.format(zonedDate, getTimeZone());
}
 
Example 9
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getYearDateTimeFormat() {
    if (yearDateTimeFormat == null) {
        yearDateTimeFormat = DateTimeFormat.getFormat("yyyy");
    }
    return yearDateTimeFormat;
}
 
Example 10
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getMonthDateTimeFormat() {
    if (monthDateTimeFormat == null) {
        monthDateTimeFormat = DateTimeFormat.getFormat("M");
    }
    return monthDateTimeFormat;
}
 
Example 11
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getWeekDateTimeFormat() {
    if (weekDateTimeFormat == null) {
        weekDateTimeFormat = DateTimeFormat.getFormat("d");
    }
    return weekDateTimeFormat;
}
 
Example 12
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getDayDateTimeFormat() {
    if (dayDateTimeFormat == null) {
        dayDateTimeFormat = DateTimeFormat.getFormat("d");
    }
    return dayDateTimeFormat;
}
 
Example 13
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getHour12DateTimeFormat() {
    if (hour12DateTimeFormat == null) {
        hour12DateTimeFormat = DateTimeFormat.getFormat("h");
    }
    return hour12DateTimeFormat;
}
 
Example 14
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getHour24DateTimeFormat() {
    if (hour24DateTimeFormat == null) {
        hour24DateTimeFormat = DateTimeFormat.getFormat("HH");
    }
    return hour24DateTimeFormat;
}
 
Example 15
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public DateTimeFormat getCustomHourDateTimeFormat() {
    if (customHourDateTimeFormat == null) {
        customHourDateTimeFormat = DateTimeFormat.getFormat(hourFormat);
    }
    return customHourDateTimeFormat;
}
 
Example 16
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public void setHour24DateTimeFormat(DateTimeFormat hour24DateTimeFormat) {
    this.hour24DateTimeFormat = hour24DateTimeFormat;
}
 
Example 17
Source Project: gantt   Source File: TimelineWidget.java    License: Apache License 2.0 4 votes vote down vote up
public void setHour12DateTimeFormat(DateTimeFormat hour12DateTimeFormat) {
    this.hour12DateTimeFormat = hour12DateTimeFormat;
}