com.google.gwt.i18n.client.DateTimeFormat Java Examples

The following examples show how to use com.google.gwt.i18n.client.DateTimeFormat. 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: RepeatableFormItem.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
/**
     * Replace string values of record attributes with types declared by item children.
     * This is necessary as declarative forms do not use DataSource stuff.
     * @param record record to scan for attributes
     * @param item item with possible profile
     * @return resolved record
     */
    private static Record resolveRecordValues(Record record, FormItem item) {
        Field f = getProfile(item);
        if (f != null) {
            for (Field field : f.getFields()) {
                String fType = field.getType();
                if ("date".equals(fType) || "datetime".equals(fType)) {
                    // parses ISO dateTime to Date; otherwise DateItem cannot recognize the value!
                    Object value = record.getAttributeAsObject(field.getName());
                    if (!(value instanceof String)) {
                        continue;
                    }
                    String sd = (String) value;
//                    ClientUtils.severe(LOG, "name: %s, is date, %s", field.getName(), sd);
//                    Date d = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).parse("1994-11-05T13:15:30Z");
                    try {
                        Date d = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).parse(sd);
                        record.setAttribute(field.getName(), d);
                    } catch (IllegalArgumentException ex) {
                        LOG.log(Level.WARNING, sd, ex);
                    }
                }
            }
        }
        return record;
    }
 
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: DateUtils.java    From swellrt with Apache License 2.0 6 votes vote down vote up
/**
 * Package-private version, takes a fixed "now" time - used for testing
 */
String formatPastDate(Date date, Date now) {

  // NOTE(zdwang): For now skip it for junit code; also see formatDateTime()
  if (!GWT.isClient()) {
    return "formatPastDate is not yet implemented in unit test code";
  }

  if (!isValid(date, now)) {
    GWT.log("formatPastDate can only format time in the past, trying anyway", null);
  }

  if (isRecent(date, now, 6 * HOUR_MS) || onSameDay(date, now)) {
    return formatTime(date);
  } else if (isRecent(date, now, 30 * DAY_MS)) {
    return getMonthDayFormat().format(date) + " " + formatTime(date);
  } else if (isSameYear(date, now)) {
    return getMonthDayFormat().format(date);
  } else {
    return DateTimeFormat.getMediumDateFormat().format(date);
  }
}
 
Example #4
Source File: DBController.java    From EasyML with Apache License 2.0 6 votes vote down vote up
/**
 * Get dataset panel show values .
 * 
 * @param dataset
 * @param isUpdate
 * @return  Data panel show value array
 */
public static String[] getDatasetPanelValue(final Dataset dataset, boolean isUpdate) {
	String[] values = new String[7];
	Date dateNow = new Date();
	DateTimeFormat dateFormat = DateTimeFormat
			.getFormat("yyyy-MM-dd KK:mm:ss a");
	values[4] = dateFormat.format(dateNow);
	double version = 0;
	if ((!dataset.getVersion().contains("n"))&&isUpdate){
		version = Double.parseDouble(dataset.getVersion()) + 0.1;
	}else version = Double.parseDouble(dataset.getVersion());     
	values[3] = NumberFormat.
			getFormat("#0.0").format(version);

	values[1] = null;
	String TypeString = dataset.getContenttype();
	if (TypeString == null || TypeString.equals("") || "General".equals(TypeString)) values[2] = "General/CSV/TSV/JSON";
	else if ("TSV".equals(TypeString)) values[2] = "TSV/General/CSV/JSON";
	else if ("CSV".equals(TypeString)) values[2] = "CSV/General/TSV/JSON";
	else values[2] = "JSON/General/TSV/CSV";
	values[0] = dataset.getName();
	values[5] = AppController.email;
	values[6] = dataset.getDescription();
	return values;
}
 
Example #5
Source File: EventRoomAvailability.java    From unitime with Apache License 2.0 6 votes vote down vote up
@Override
public SessionMonth.Flag getDateFlag(EventType type, Date date) {
	if (iSessionMonths == null || iSessionMonths.isEmpty()) return null;
	if (date == null) return null;
	int m = Integer.parseInt(DateTimeFormat.getFormat("MM").format(date));
	for (SessionMonth month: iSessionMonths)
		if (m == month.getMonth() + 1) {
			int d = Integer.parseInt(DateTimeFormat.getFormat("dd").format(date)) - 1;
			if (month.hasFlag(d, SessionMonth.Flag.FINALS) && type != EventType.FinalExam) return SessionMonth.Flag.FINALS;
			if (month.hasFlag(d, SessionMonth.Flag.BREAK)) return SessionMonth.Flag.BREAK;
			if (month.hasFlag(d, SessionMonth.Flag.WEEKEND)) return SessionMonth.Flag.WEEKEND;
			if (month.hasFlag(d, SessionMonth.Flag.HOLIDAY)) return SessionMonth.Flag.HOLIDAY;
			if (month.hasFlag(d, SessionMonth.Flag.MIDTERMS) && type != EventType.MidtermExam) return SessionMonth.Flag.MIDTERMS;
			return null;
		}
	return null;
}
 
Example #6
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 #7
Source File: PeriodPreferencesWidget.java    From unitime with Apache License 2.0 6 votes vote down vote up
Cell(int day, int slot, Date date, PeriodInterface period) {
	super("cell", "item", isEditable() && period != null ? "clickable" : null, period == null ? "disabled" : null, period != null && iModel.isAssigned(period) ? "highlight" : null);
	iDay = day;
	iSlot = slot;
	iDate = date;
	iPeriod = period;
	if (period != null) {
		PreferenceInterface preference = iModel.getPreference(day, slot);
		if (preference == null) {
			getElement().getStyle().clearBackgroundColor();
			setHTML("");
			setTitle("");
		} else {
			getElement().getStyle().setBackgroundColor(preference.getColor());
			setTitle(DateTimeFormat.getFormat(CONSTANTS.examPeriodDateFormat()).format(date) + " " + slot2short(slot) + (period == null ? "" : " - " + slot2short(slot + period.getLength())) + ": " + preference.getName());
		}
		if (isEditable())
			addMouseDownHandler(new MouseDownHandler() {
				@Override
				public void onMouseDown(MouseDownEvent event) {
					setOption(iPreference);
				}
			});				
	}
}
 
Example #8
Source File: Header.java    From SensorWebClient with GNU General Public License v2.0 6 votes vote down vote up
private Label getCopyrightLink() {

        DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy");
		String year = dateFormatter.format(new Date());

        Label copyright = getHeaderLinkLabel("© 52°North, GmbH " + year);
        copyright.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				String url = "http://www.52north.org";
                Window.open(url, "_blank", "");
			}
		});
		return copyright;
	}
 
Example #9
Source File: PeriodPreferencesWidget.java    From unitime with Apache License 2.0 6 votes vote down vote up
private D(int day, int slot, Date date, PeriodInterface period) {
	super("cell", "day", isEditable() && period != null ? "clickable" : null, period == null ? "unavailable" : null);
	iDay = day;
	iSlot = slot;
	iDate = date;
	iPeriod = period;
	setText(DateTimeFormat.getFormat("d").format(date));
	if (period != null) {
		PreferenceInterface preference = iModel.getPreference(day, slot);
		if (preference == null) {
			getElement().getStyle().clearBackgroundColor();
			setTitle("");
		} else {
			getElement().getStyle().setBackgroundColor(preference.getColor());
			setTitle(DateTimeFormat.getFormat(CONSTANTS.examPeriodDateFormat()).format(date) + " " + slot2short(slot) + (period == null ? "" : " - " + slot2short(slot + period.getLength())) + ": " + preference.getName());
		}
		if (isEditable())
			addMouseDownHandler(new MouseDownHandler() {
				@Override
				public void onMouseDown(MouseDownEvent event) {
					setOption(iPreference);
				}
			});				
	}
}
 
Example #10
Source File: SessionDatesSelector.java    From unitime with Apache License 2.0 5 votes vote down vote up
public boolean isEnabled(Date date) {
	int year = Integer.parseInt(DateTimeFormat.getFormat("yyyy").format(date));
	int month = Integer.parseInt(DateTimeFormat.getFormat("MM").format(date));
	int day = Integer.parseInt(DateTimeFormat.getFormat("dd").format(date));
	for (int i = 0; i < iPanel.getWidget().getWidgetCount(); i ++) {
		Widget w = iPanel.getWidget().getWidget(i);
		if (w instanceof SingleMonth) {
			SingleMonth s = (SingleMonth)w;
			if (s.getYear() == year && s.getMonth() + 1 == month)
				return s.get(day - 1).isEnabled();
		}
	}
	return false;
}
 
Example #11
Source File: SessionDatesSelector.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void init(List<SessionMonth> months) {
	iPanel.getWidget().clear();
	int firstOutside = -1, start = -1, end = -1, finals = -1, midterms = -1, firstHoliday = - 1, firstBreak = -1, today = -1, firstPast = -1, firstEventDate = -1, firstClassDate = -1;
	int idx = 0;
	P lastWeek = null;
	for (SessionMonth month: months) {
		SingleMonth m = new SingleMonth(month, isCanSelectPast(), idx++, lastWeek);
		lastWeek = m.getWeeks().get(m.getWeeks().size() - 1);
		if (lastWeek.getDays().size() == 7) lastWeek = null;
		iPanel.getWidget().add(m);
		if (start < 0) start = month.getFirst(SessionMonth.Flag.START);
		if (end < 0) end = month.getFirst(SessionMonth.Flag.END);
		if (finals < 0) finals = month.getFirst(SessionMonth.Flag.FINALS);
		if (midterms < 0) midterms = month.getFirst(SessionMonth.Flag.MIDTERMS);
		if (firstHoliday < 0) firstHoliday = month.getFirst(SessionMonth.Flag.HOLIDAY);
		if (firstBreak < 0) firstBreak = month.getFirst(SessionMonth.Flag.BREAK);
		if (firstOutside < 0) firstOutside = month.getFirst(SessionMonth.Flag.DISABLED);
		if (firstPast < 0) firstPast = month.getFirst(SessionMonth.Flag.PAST);
		if (firstEventDate < 0) firstEventDate = month.getFirst(SessionMonth.Flag.DATE_MAPPING_EVENT);
		if (firstClassDate < 0) firstClassDate = month.getFirst(SessionMonth.Flag.DATE_MAPPING_CLASS);
		if (month.getYear() == Integer.parseInt(DateTimeFormat.getFormat("yyyy").format(new Date())) &&
			month.getMonth() + 1 == Integer.parseInt(DateTimeFormat.getFormat("MM").format(new Date())))
			today = Integer.parseInt(DateTimeFormat.getFormat("dd").format(new Date()));
		if (month.getFirst(SessionMonth.Flag.START) >= 0) iSessionYear = month.getYear();
	}
	iPanel.getWidget().add(new Legend(firstOutside, start, finals, midterms, firstHoliday, firstBreak, iCanSelectPast ? -1 : firstPast, today, firstClassDate, firstEventDate));
	iPanel.getWidget().setCursor(new Date());
}
 
Example #12
Source File: DateUtils.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Formats the specified date and time as a String.
 */
public String formatDateTime(Date date) {
  // NOTE(zdwang): For now skip it for junit code; also see formatPastDate()
  if (!GWT.isClient()) {
    return "formatDateTime is not yet implemented in unit test code";
  }

  // AM/PM -> am/pm for consistency with formatPastDate()
  return DateTimeFormat.getShortDateTimeFormat().format(date).toLowerCase();
}
 
Example #13
Source File: DateUtils.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Formats the specified time as a String.
 */
public String formatTime(Date date) {
  // NOTE(zdwang): For now skip it for junit code; also see formatPastDate()
  if (!GWT.isClient()) {
    return "formatDateTime is not yet implemented in unit test code";
  }

  // AM/PM -> am/pm for consistency with formatPastDate()
  return DateTimeFormat.getShortTimeFormat().format(date).toLowerCase();
}
 
Example #14
Source File: UTCDateBoxImplHtml5.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
/**
 * Formats the supplied value using the specified DateTimeFormat.
 * 
 * @return "" if the value is null
 */
private String long2string(Long value, DateTimeFormat fmt) {
    // for html5 inputs, use "" for no value
    if (value == null) return "";
    Date date = UTCDateBox.utc2date(value);
    return date != null ? fmt.format(date) : null;
}
 
Example #15
Source File: PeriodPreferencesWidget.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void setOption(PreferenceInterface preference) {
	if (!isEditable() || iPeriod == null) return;
	iModel.setPreference(iDay, iSlot, preference);
	if (preference == null) {
		getElement().getStyle().clearBackgroundColor();
		setTitle("");
	} else {
		getElement().getStyle().setBackgroundColor(preference.getColor());
		setTitle(DateTimeFormat.getFormat(CONSTANTS.examPeriodDateFormat()).format(iDate) + " " + slot2short(iSlot) + " - " + slot2short(iSlot + iPeriod.getLength()) + ": " + preference.getName());
	}
	ValueChangeEvent.fire(PeriodPreferencesWidget.this, getValue());
}
 
Example #16
Source File: SessionDatesSelector.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Override
public List<Date> getValue() {
	List<Date> ret = new ArrayList<Date>();
	DateTimeFormat df = DateTimeFormat.getFormat("yyyy/MM/dd");
	for (int i = 0; i < iPanel.getWidget().getWidgetCount(); i ++) {
		Widget w = iPanel.getWidget().getWidget(i);
		if (w instanceof SingleMonth) {
			SingleMonth s = (SingleMonth)w;
			for (D d: s.getDays()) {
				if (d.getValue()) ret.add(df.parse(s.getYear() + "/" + (1 + s.getMonth()) + "/" + (1 + d.getNumber())));
			}
		}
	}
	return ret;
}
 
Example #17
Source File: DatePickerBase.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
/**
 * Sets format of the date using GWT notation
 *
 * @param format date format in GWT notation
 */
public void setGWTFormat(final String format) {
    this.format = toBootstrapDateFormat(format);

    // Get the old value
    final Date oldValue = getValue();

    // Make the new DateTimeFormat
    this.dateTimeFormat = DateTimeFormat.getFormat(format);

    if (oldValue != null) {
        setValue(oldValue);
    }
}
 
Example #18
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 #19
Source File: DateInputParser.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
public Date parseDate(String format) {
    if (isValid(format)) {
        valuebox.clearStatusText();
        return DateTimeFormat.getFormat(format).parse(valuebox.getText());
    }
    return null;
}
 
Example #20
Source File: UTCTimeBox.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
/**
 * Allows a UTCTimeBox to be created with a specified format.
 */
public UTCTimeBox(DateTimeFormat timeFormat) {
    // used deferred binding for the implementation
    impl = GWT.create(UTCTimeBoxImpl.class);
    impl.setTimeFormat(timeFormat);
    initWidget(impl.asWidget());
}
 
Example #21
Source File: TestPopup.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param value
 * @param value2
 */
private void log(String value, String value2) {
	DateTimeFormat dtf = DateTimeFormat.getFormat(Main.i18n("general.date.pattern"));
	int row = table.getRowCount();
	table.setHTML(row, 0, dtf.format(new Date()) + " " + value);
	table.setHTML(row, 1, value2);
	table.getCellFormatter().setHeight(row, 0, "20px");
	table.getCellFormatter().setWidth(row, 0, "250px");
}
 
Example #22
Source File: Toaster.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
public void addMessage(String msg) {

        Date d = new Date();
        String timeStamp = DateTimeFormat.getFormat("dd.MM.yyyy HH:mm").format(d);

        Label l = new Label(timeStamp + " " + msg);
        l.setCanSelectText(true);
        l.setStyleName("n52_sensorweb_client_toasterMsg");
        l.setAutoHeight();

        this.messages.add(l);

        for (int i = 0; i < this.messages.size(); i++) {
            if (this.layout.hasMember(this.messages.get(i))) {
                this.layout.removeMember(this.messages.get(i));
            }
        }
        for (int i = this.messages.size() - 1; i >= 0; i--) {
            this.layout.addMember(this.messages.get(i));
        }

//        this.left = this.toasterWindow.getParentElement().getWidth().intValue() - this.width - 10;
//        this.top = this.toasterWindow.getParentElement().getHeight().intValue() - this.height - 30;
//
//        this.toasterWindow.setLeft(this.left);
//        this.toasterWindow.setTop(this.top);

        animateToaster();
    }
 
Example #23
Source File: DisplayerGwtFormatter.java    From dashbuilder with Apache License 2.0 5 votes vote down vote up
protected DateTimeFormat getDateFormat(String pattern) {
    if (StringUtils.isBlank(pattern)) {
        return getDateFormat(ColumnSettings.DATE_PATTERN);
    }
    DateTimeFormat format = datePatternMap.get(pattern);
    if (format == null) {
        format = DateTimeFormat.getFormat(pattern);
        datePatternMap.put(pattern, format);
    }
    return format;
}
 
Example #24
Source File: Event.java    From gwtbootstrap3-extras with Apache License 2.0 5 votes vote down vote up
public Date getStartFromYearMonthDay() {
    Date iso = null;
    final String isoString = getISOStart();
    if (isoString != null && isoString.length() >= 10) {
        iso = DateTimeFormat.getFormat("yyyy-MM-dd").parse(isoString.substring(0, 10));
    }
    return iso;
}
 
Example #25
Source File: MsgPopup.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add message notification.
 */
public void add(GWTUINotification uin) {
	int row = table.getRowCount();
	DateTimeFormat dtf = DateTimeFormat.getFormat(Main.i18n("general.date.pattern"));
	table.setHTML(row, 0, "<b>" + dtf.format(uin.getDate()) + "</b>");
	table.setHTML(row, 1, uin.getMessage());
	table.getCellFormatter().setWidth(row, 1, "100%");
	table.getCellFormatter().setVerticalAlignment(row, 0, HasAlignment.ALIGN_TOP);
	table.getCellFormatter().setVerticalAlignment(row, 1, HasAlignment.ALIGN_TOP);
	table.getCellFormatter().setStyleName(row, 0, "okm-NoWrap");
	if (uin.getId() > lastId) {
		if (uin.getAction() == GWTUINotification.ACTION_LOGOUT) {
			row++;
			int seconds = 240;
			HTML countDown = new HTML(Main.i18n("ui.logout") + " " + secondsToHTML(seconds));
			table.setWidget(row, 0, countDown);
			table.getFlexCellFormatter().setColSpan(row, 0, 2);
			table.getCellFormatter().setHorizontalAlignment(row, 0, HasAlignment.ALIGN_CENTER);
			logout(countDown, seconds);
			show();
		}
		if (uin.isShow()) {
			show();
		}
	}
	evaluateButtons();
}
 
Example #26
Source File: I18N.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void init(GUIInfo info) {
	setLanguages(info.getSupportedLanguages());
	setGuiLanguages(info.getSupportedGUILanguages());
	initBundle(info.getBundle());

	/*
	 * Prepare the date formatters
	 */
	dateFormatShort = DateTimeFormat.getFormat(message("format_dateshort"));
	dateFormat = DateTimeFormat.getFormat(message("format_date"));
}
 
Example #27
Source File: ISO8601.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Format date with format "yyyyMMddHHmmss"
 */
public static String formatBasic(Date value) {
	if (value == null) {
		return null;
	} else {
		DateTimeFormat dtf = DateTimeFormat.getFormat(BASIC_PATTER);
		return dtf.format(value);
	}
}
 
Example #28
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 #29
Source File: ISO8601.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Format date with format "YYYY-MM-DDThh:mm:ss.SSSTZD"
 */
public static String formatExtended(Date value) {
	if (value == null) {
		return null;
	} else {
		DateTimeFormat dtf = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601);
		return dtf.format(value);
	}
}
 
Example #30
Source File: DateUtils.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Formats the specified time as a String.
 */
public String formatTime(Date date) {
  // NOTE(zdwang): For now skip it for junit code; also see formatPastDate()
  if (!GWT.isClient()) {
    return "formatDateTime is not yet implemented in unit test code";
  }

  // AM/PM -> am/pm for consistency with formatPastDate()
  return DateTimeFormat.getShortTimeFormat().format(date).toLowerCase();
}