Example usage for com.google.gwt.i18n.client DateTimeFormat format

List of usage examples for com.google.gwt.i18n.client DateTimeFormat format

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client DateTimeFormat format.

Prototype

public String format(Date date) 

Source Link

Document

Format a date object.

Usage

From source file:cc.kune.core.client.i18n.I18nUITranslationService.java

License:GNU Affero Public License

/**
 * Format date with locale.//from  www .ja v  a 2 s  . c o  m
 *
 * @param date
 *          the date
 * @param shortFormat
 *          the short format
 * @return the string
 */
public String formatDateWithLocale(final Date date, final boolean shortFormat) {
    String dateFormat = shortFormat ? currentLang.getDateFormatShort() : currentLang.getDateFormat();

    final DateTimeFormat fmt;
    if (dateFormat == null) {
        fmt = DateTimeFormat.getFormat("M/d/yyyy h:mm a");
    } else {
        if (shortFormat) {
            fmt = DateTimeFormat.getFormat(dateFormat + " h:mm a");
        } else {
            final String abrevMonthInEnglish = DateTimeFormat.getFormat("MMM").format(date);
            final String monthToTranslate = abrevMonthInEnglish + " [%NT abbreviated month]";
            dateFormat = dateFormat.replaceFirst("MMM", "'" + t(monthToTranslate) + "'");
            fmt = DateTimeFormat.getFormat(dateFormat + " h:mm a");
        }
    }
    final String dateFormated = fmt.format(date);
    return dateFormated;
}

From source file:cc.kune.events.client.viewer.CalendarViewerPanel.java

License:GNU Affero Public License

@Override
public void updateTitle(final CalendarViews currentCalView) {
    final Date currentDate = getDate();
    DateTimeFormat fmt = null;
    // More info about formats:
    // http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/i18n/client/DateTimeFormat.html
    switch (currentCalView) {
    case DAY:/* w  w w . ja  va 2  s. c  om*/
    case AGENDA:
        fmt = DateTimeFormat.getFormat("EEEE, MMMM dd, yyyy");
        break;
    case MONTH:
    default:
        fmt = DateTimeFormat.getFormat("MMMM yyyy");
        break;
    }
    final String dateFormatted = fmt.format(currentDate);
    final ForIsWidget docHeader = gsArmor.getDocHeader();
    UiUtils.clear(docHeader);
    contentTitle.setTitle(i18n.t("Events in [%s]", dateFormatted), EventsToolConstants.TYPE_ROOT, null, false);
    docHeader.add(contentTitle);
}

From source file:cimav.client.data.domain.Incidencia.java

public void ajustar() {

    // Fecha/*  ww  w .  ja v  a  2  s. c om*/
    Date fechaInicioQuin = Quincena.get().getFechaInicio();
    Date fechaFinQuin = Quincena.get().getFechaFin();

    if (this.getTipo().isIncapacidad()) {
        // la fecha de inicio para Incapacidades tiene que ser mayor o igual al inicio de la quincena
        //boolean isAntes = this.fechaInicial.compareTo(fechaInicioQuin) < 0;
        if (this.fechaInicial.before(fechaInicioQuin)) {
            this.fechaInicial = fechaInicioQuin;
        }
    } else if (this.getTipo().isFalta()) {
        // la falta tiene que estar entre la fecha de inicio y la fecha de fin de la quincena
        //boolean isBetween = (this.fechaInicial.compareTo(fechaInicioQuin) >= 0) && (this.fechaInicial.compareTo(fechaFinQuin) <= 0); // incluye endpoints
        boolean isBetween = (this.fechaInicial.equals(fechaInicioQuin)
                || this.fechaInicial.after(fechaInicioQuin))
                && (this.fechaInicial.equals(fechaFinQuin) || this.fechaInicial.before(fechaFinQuin));
        if (!isBetween) {
            // Si no esta, ajustarla a la fecha de inicio
            this.fechaInicial = Quincena.get().getFechaInicio();
        }
    } else if (this.getTipo().isPermiso()) {

    }

    // Dias
    if (this.getTipo().isIncapacidad()) {
        if (this.dias > 90) {
            // Mximo 90 incapacidades
            this.dias = 90;
        }
        Date fechaAux = this.fechaInicial;
        this.diasHabiles = 0;
        this.diasInhabiles = 0;
        while ((fechaFinQuin.after(fechaAux) || fechaFinQuin.equals(fechaAux))
                && ((this.diasHabiles + this.diasInhabiles) < this.dias)) {
            // mientras no revase a la fecha fin
            // y mientras Habiles + Inhabibles no superen los dias totales
            DateTimeFormat format = DateTimeFormat.getFormat("c"); // try with "E" pattern also
            String dayOfWeek = format.format(fechaAux); //0 for sunday
            if (dayOfWeek.equals("0") || dayOfWeek.equals("6")) {
                this.diasInhabiles++;
            } else {
                this.diasHabiles++;
            }
            // avanzar 1 da
            fechaAux = new Date(fechaAux.getTime() + TimeUnit.DAYS.toMillis(1));
        }
    } else if (this.getTipo().isFalta()) {
        if (this.dias > 5) {
            // Mximo 5 faltas
            this.dias = 5;
        }
        if (this.dias > Quincena.get().getDiasOrdinarios()) {
            // Mximo igual a los ordinarios
            this.dias = Quincena.get().getDiasOrdinarios();
        }
        // todas la faltas capturadas son sobre dias hbiles; no hay faltas en das inhabiles o de asueto
        this.diasHabiles = this.dias;
        // no hay faltas en das de descanso
        this.diasInhabiles = 0;
    } else if (this.getTipo().isPermiso()) {
        // no cuentan como faltas
        //this.incidencias = 0;
    }
}

From source file:cimav.client.view.common.EmpleadoListCell.java

@Override
public void render(Cell.Context context, EmpleadoBase value, SafeHtmlBuilder sb) {
    if (value == null) {
        return;//from  ww  w  .j ava2 s .c  o  m
    }

    boolean isSelected = this.selectionModel != null && this.selectionModel.getSelectedObject() != null
            && this.selectionModel.getSelectedObject().equals(value);

    String es_null = "---";
    String grupoStr = value.getGrupo() != null ? value.getGrupo().getCode() : es_null;
    boolean tieneEstimulos = EGrupo.CYT.equals(value.getGrupo());
    if (tieneEstimulos) {
        String estimulos = value.getEstimulosProductividad() != null ? "" + value.getEstimulosProductividad()
                : es_null;
        grupoStr = grupoStr + "(" + estimulos + ")";
    }
    String estimulosCyt = value.getEstimulosProductividad() != null ? "" + value.getEstimulosProductividad()
            : es_null;
    String deptoCodeStr = value.getDepartamento() != null ? value.getDepartamento().getCode() : es_null;
    String deptoNameStr = value.getDepartamento() != null ? value.getDepartamento().getName() : es_null;
    String nivelStr = value.getNivel() != null ? value.getNivel().getCode() : es_null;
    String nivelNombreStr = value.getNivel() != null ? value.getNivel().getName() : es_null;
    String sedeStr = value.getSede() != null ? value.getSede().getAbrev() : es_null;
    DateTimeFormat dtf = DateTimeFormat.getFormat("dd/MMM/yyyy");
    String fechaAntStr = dtf.format(value.getFechaAntiguedad());
    String diasMesesAniosStr = "Nulo";
    if (value.getPantYears() != null) {
        diasMesesAniosStr = value.getPantYears() + " aos(s), " + value.getPantMonths() + " mese(s), "
                + value.getPantDayOdd() + " das(s)";
    }

    String td_selec_id = "td_selec_" + value.getId();

    String html = "<table width='100%' cellspacing='0' cellpadding='0' style='cursor: pointer; text-align: left; vertical-align: middle; border-bottom:1px solid lightgray;'>\n"
            + " <tbody> \n" + "  <tr >\n" + "    <td rowspan='6' id='" + td_selec_id
            + "_left' class'td_selection' style='height:auto; width: 5px; SELECTED_COLOR_REEMPLAZO'></td>\n"
            + "    <td colspan='3' style='height:10px;'></td>\n" + "    <td rowspan='6' id='" + td_selec_id
            + "_right' class'td_selection' style='height:auto; width: 5px; SELECTED_COLOR_REEMPLAZO'></td>\n"
            + "  </tr>\n" + "  <tr>\n" + "    <td width='78px' rowspan='3' style='text-align: center;'>"
            + "         <img data-toggle='tooltip' data-placement='left' title='TOOL_TIP_ID_REEMPLAZO' src='URL_FOTO_REEMPLAZO' style='border:1px solid lightgray; margin-top: 3px; border-radius:50%; padding:2px;'/>"
            + "    </td>\n" + "  </tr>\n" + "  <tr>\n"
            + "    <td colspan='2' style='vertical-align: top;'><h5 style='margin-top: 0px; margin-bottom: 0px;'>NOMBRE_REEMPLAZO</h5></td>\n"
            + "  </tr>\n" + "  <tr >\n" + "    <td  colspan='1' style='line-height: 1.8;'> "
            + "         <code class='label-cyt-grp-niv'><span >CODE_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv'><span >GRUPO_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv' data-toggle='tooltip' data-placement='left' title='TOOL_TIP_NIVEL_REEMPLAZO'><span >NIVEL_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv'><span >SEDE_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv' data-toggle='tooltip' data-placement='left' title='DATO_ANTIGUEDAD_REEMPLAZO'><span >FECHA_ANTIGUEDAD_REEMPLAZO</span></code> "
            + "    </td>\n" + "  </tr>\n" + "  <tr style='border-bottom:1px solid lightgray;'>\n"
            + "    <td style='text-align:center;' ></td>\n" + "    <td colspan='3' style='height:10px;'></td>\n"
            + "  </tr>\n" + " </tbody> " + "</table>";

    if (isSelected) {
        html = html.replace("SELECTED_COLOR_REEMPLAZO", "background-color: " + colorSelected + ";"); // 628cd5;");
    } else if (value.isDirty() != null && value.isDirty()) {
        html = html.replace("SELECTED_COLOR_REEMPLAZO", "background-color: lightgray;");
    } else {
        html = html.replace("SELECTED_COLOR_REEMPLAZO", "background-color: #F8F8F8;");
    }

    try {

        String idReem = "---";
        if (value.getId() != null) {
            idReem = value.getId().toString();
        }
        html = html.replace("TOOL_TIP_ID_REEMPLAZO", idReem);
        html = html.replace("CODE_REEMPLAZO", chkStrNull(value.getCode()));
        html = html.replace("URL_FOTO_REEMPLAZO", chkStrNull(value.getUrlPhoto()));
        html = html.replace("NOMBRE_REEMPLAZO", chkStrNull(value.getName()));
        html = html.replace("GRUPO_REEMPLAZO", chkStrNull(grupoStr));
        html = html.replace("TOOL_TIP_NIVEL_REEMPLAZO", chkStrNull(nivelNombreStr));
        html = html.replace("NIVEL_REEMPLAZO", chkStrNull(nivelStr));
        html = html.replace("DEPTO_CODIGO_REEMPLAZO", chkStrNull(deptoCodeStr));
        html = html.replace("TOOL_TIP_DEPTO_REEMPLAZO", chkStrNull(deptoNameStr));
        html = html.replace("SEDE_REEMPLAZO", chkStrNull(sedeStr));
        html = html.replace("FECHA_ANTIGUEDAD_REEMPLAZO", chkStrNull(fechaAntStr));
        html = html.replace("DATO_ANTIGUEDAD_REEMPLAZO", chkStrNull(diasMesesAniosStr));
        if (value.getId() != null) {
            html = html.replace("ID_REEMPLAZO", value.getId().toString());
        } else {
            html = html.replace("ID_REEMPLAZO", "---");
        }

        sb.appendHtmlConstant(html);
    } catch (Exception e) {
        Window.alert("Catch it! " + html);
    }
}

From source file:cimav.client.view.MainUI.java

@Override
protected void onLoad() {
    super.onLoad();

    BaseREST.initHeader("juan.calderas");

    GWT.log("login -> juan.calderas");

    if (Quincena.get() == null) {
        CalculoREST calculoREST = new CalculoREST();
        calculoREST.addRESTExecutedListener(new BaseREST.RESTExecutedListener() {
            @Override//from w  w  w  .  j  a  v  a 2 s  . c  o  m
            public void onRESTExecuted(MethodEvent restEvent) {
                if (EMethod.FIND_QUINCENA.equals(restEvent.getMethod())) {
                    if (ETypeResult.SUCCESS.equals(restEvent.getTypeResult())) {
                        Quincena.set((Quincena) restEvent.getResult());

                        String quin = Quincena.get().getQuincena() < 10 ? "0" + Quincena.get().getQuincena()
                                : "" + Quincena.get().getQuincena();
                        lNumQuincena.setText(quin);
                        DateTimeFormat fmt = DateTimeFormat.getFormat("EEEE, MMM dd");
                        lFechasQuincena.setText("" + fmt.format(Quincena.get().getFechaInicio()) + " - "
                                + fmt.format(Quincena.get().getFechaFinCalendario()));

                    } else {
                        GrowlOptions go = new GrowlOptions();
                        go.setType(GrowlType.DANGER);
                        go.setDelay(0);
                        Growl.growl("Fall al cargar la Quincena. " + restEvent.getReason(), go);
                    }
                }
            }
        });
        calculoREST.findQuincena();
    }

    BaseREST.initHeader("alban.lakata");

    //centerPanelHeaderId.getElement().setId("centerPanelHeaderId");
    //        //GQuery.$("#centerPanelHeaderId").css("border","solid 5px red");
    //        List<Widget> tds = GQuery.$("#centerPanelHeaderId").$("table > tr > td").widgets();
    //        if (tds != null && tds.size() >= 2) {
    //            tds.get(0).getElement().getStyle().setWidth(300, Style.Unit.PX);
    //            tds.get(1).getElement().getStyle().setWidth(100, Style.Unit.PCT);
    //        }
    //        centerPanelHeaderId.setCellWidth(centerPanelHeaderId.getWidget(0), "600px");
    //        centerPanelHeaderId.setCellWidth(centerPanelHeaderId.getWidget(1), "50%");
    //        centerPanelHeaderId.setCellHorizontalAlignment(centerPanelHeaderId.getWidget(1), HasHorizontalAlignment.HorizontalAlignmentConstant.endOf(HasDirection.Direction.RTL));

}

From source file:com.alkacon.geranium.client.util.DateTimeUtil.java

License:Open Source License

/**
 * Returns a formated date String from a Date value,
 * the formatting based on the provided options.<p>
 * /*from w  w  w  .  ja  va2 s  . c  om*/
 * @param date the Date object to format as String
 * @param format the format to use
 * 
 * @return the formatted date 
 */
public static String getDate(Date date, Format format) {

    DateTimeFormat df;
    switch (format) {
    case FULL:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_FULL);
        break;
    case LONG:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_LONG);
        break;
    case MEDIUM:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_MEDIUM);
        break;
    case SHORT:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_SHORT);
        break;
    default:
        // can never happen, just to prevent stupid warning
        return "";
    }
    return df.format(date);
}

From source file:com.alkacon.geranium.client.util.DateTimeUtil.java

License:Open Source License

/**
 * Returns a formated time String from a Date value,
 * the formatting based on the provided options.<p>
 * //from  w ww .j  a va  2  s. c om
 * @param date the Date object to format as String
 * @param format the format to use
 * 
 * @return the formatted time 
 */
public static String getTime(Date date, Format format) {

    DateTimeFormat df;
    switch (format) {
    case FULL:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.TIME_FULL);
        break;
    case LONG:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.TIME_LONG);
        break;
    case MEDIUM:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.TIME_MEDIUM);
        break;
    case SHORT:
        df = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.TIME_SHORT);
        break;
    default:
        // can never happen, just to prevent stupid warning
        return "";
    }
    return df.format(date);
}

From source file:com.anzsoft.client.ui.ChatWindow.java

License:Open Source License

private DivElement createMessage(final String user, final String message, boolean local) {
    Element element = DOM.createDiv();
    DivElement messageDiv = DivElement.as(element);
    lastMsgID = DOM.createUniqueId();/*from   ww  w .  j  a  va  2 s.  c  o m*/
    messageDiv.setId(lastMsgID);
    messageDiv.setClassName("selected-article");

    //create the avatar table
    element = DOM.createTable();
    TableElement avatarTable = TableElement.as(element);
    messageDiv.appendChild(avatarTable);
    avatarTable.setAttribute("hspace", "4");
    avatarTable.setAttribute("cellspacing", "0");
    avatarTable.setAttribute("vspace", "2");
    avatarTable.setAttribute("border", "0");
    avatarTable.setAttribute("align", "left");

    Element tbodyElement = DOM.createTBody();
    avatarTable.appendChild(tbodyElement);

    Element trElement = DOM.createTR();
    tbodyElement.appendChild(trElement);

    Element tdElement = DOM.createTD();
    trElement.appendChild(tdElement);
    tdElement.setAttribute("height", "45");
    tdElement.setAttribute("width", "45");
    tdElement.setAttribute("align", "middle");
    Style style = tdElement.getStyle();
    style.setProperty("border", "1px solid black");
    style.setProperty("background-color", "white");

    Element imgElement = DOM.createImg();
    ImageElement imageElement = ImageElement.as(imgElement);
    tdElement.appendChild(imageElement);
    imageElement.setAttribute("height", "45");
    imageElement.setAttribute("widht", "45");
    XmppVCard vc = null;
    if (local)
        vc = JabberApp.instance().getSelfVCard();
    else
        vc = vcard;
    if (!GXT.isIE && vc != null && !vc.photo().isEmpty())
        imageElement.setSrc("data:image;base64," + vc.photo());
    else
        imageElement.setSrc(JabberApp.instance().getAvatarUrl(jid));

    tdElement = DOM.createTD();
    tdElement.setInnerHTML("&nbsp&nbsp");
    trElement.appendChild(tdElement);

    //create the div for timestamp and nick
    element = DOM.createDiv();
    DivElement tnDiv = DivElement.as(element);
    tnDiv.setClassName("msg_header");
    messageDiv.appendChild(tnDiv);
    //style = tnDiv.getStyle();
    //style.setProperty("border-bottom", "1px solid black");

    element = DOM.createTable();
    TableElement tnTableElement = TableElement.as(element);
    tnDiv.appendChild(tnTableElement);
    tnTableElement.setAttribute("cellspacing", "0");
    tnTableElement.setAttribute("cellpadding", "0");
    tnTableElement.setAttribute("width", "80%");
    tnTableElement.setAttribute("border", "0");

    tbodyElement = DOM.createTBody();
    tnTableElement.appendChild(tbodyElement);

    trElement = DOM.createTR();
    tbodyElement.appendChild(trElement);

    Element nickElement = DOM.createTD();
    trElement.appendChild(nickElement);
    nickElement.setClassName("msg-nick");
    nickElement.setAttribute("valign", "bottom");
    nickElement.setAttribute("align", "left");
    nickElement.setInnerHTML("<b>" + user + "</b>");

    Element timeElement = DOM.createTD();
    trElement.appendChild(timeElement);
    timeElement.setClassName("msg-nick");
    timeElement.setAttribute("valign", "bottom");
    timeElement.setAttribute("align", "right");
    DateTimeFormat timeFormat = DateTimeFormat.getMediumTimeFormat();
    String datetime = timeFormat.format(new java.util.Date());
    timeElement.setInnerHTML("<small>" + datetime + "</small>");

    Element messageElement = DOM.createSpan();
    messageElement.setInnerHTML(ChatTextFormatter.format(message == null ? "" : message).getHTML());

    messageDiv.appendChild(messageElement);
    return messageDiv;
}

From source file:com.brainz.wokhei.client.home.OrderBrowserModulePart.java

/**
 *
 *//*from  www. j a va2s.c o  m*/
private void updatePanel() {
    //buy now false by default
    _buyNowImage.setVisible(false);
    _askRevisionImage.setVisible(false);

    // TODO: notifyChanges(_currentOrder);

    if (downloadPanel != null) {
        downloadPanelContainer.remove(downloadPanel);
    }

    if (_currentOrder != null) {

        orderImage.setVisible(true);

        nextOrderButton.setVisible(OrderDTOUtils.getNextOrder(_orders, _currentOrder) != _currentOrder);
        previousOrderButton.setVisible(OrderDTOUtils.getPreviousOrder(_orders, _currentOrder) != _currentOrder);

        alwaysInfos(false);
        orderNameLabel.setText(_currentOrder.getText());

        DateTimeFormat fmt = DateTimeFormat.getFormat("EEE MMM yy k:m");
        colour.setStyleName("colour" + _currentOrder.getColour().toString());
        if (_currentOrder.getColour().equals(Colour.SurpriseMe)) {
            colour.setText("?");
            colour.addStyleName("fontAR");
            colour.addStyleName("colourSurpriseMeHomeBrowsing");
        } else {
            colour.setText("");
        }
        colourLabel.setText(_currentOrder.getColour().getName() + " ");

        // Set original description + revisions --> a panel with small top-down small arrows
        setupDescriptionsPanel();

        orderDateLabel.setText(fmt.format(_currentOrder.getDate()));
        if (_currentOrder.getStatus().equals(Status.VIEWED) && _currentOrder.hasCompletedReview()) {
            statusTitle.setText(
                    Messages.valueOf("RE" + _currentOrder.getStatus().toString() + "_TITLE").getString());
            statusDescription.setText(
                    Messages.valueOf("RE" + _currentOrder.getStatus().toString() + "_TEXT").getString());
        } else {
            statusTitle.setText(Messages.valueOf(_currentOrder.getStatus().toString() + "_TITLE").getString());
            statusDescription
                    .setText(Messages.valueOf(_currentOrder.getStatus().toString() + "_TEXT").getString());
        }
        switch (_currentOrder.getStatus()) {
        case INCOMING:
        case ACCEPTED:
        case IN_PROGRESS:
        case QUALITY_GATE:
        case REJECTED:
        case REVIEWING:
            orderImage.removeStyleName("labelButton");
            orderImage.setUrl(Images.valueOf(_currentOrder.getStatus().toString()).getImageURL());
            break;
        case READY:
            orderImage.addStyleName("labelButton");
            orderImage.setUrl(Images.valueOf(_currentOrder.getStatus().toString()).getImageURL());
            break;
        case VIEWED:
            orderImage.addStyleName("labelButton");
            orderImage.setUrl(Images.valueOf(_currentOrder.getStatus().toString()).getImageURL());
            setupBuyNowStuff();
            break;
        case BOUGHT:
            orderImage.addStyleName("labelButton");
            orderImage.setUrl(Images.valueOf(_currentOrder.getStatus().toString()).getImageURL());
            setupDownloadStuff(_currentOrder.getStatus());
            break;
        }
    } else {
        //there's no current order means we have no order - need to set invisible for IE
        nextOrderButton.setVisible(false);
        previousOrderButton.setVisible(false);
        orderImage.setVisible(false);
        alwaysInfos(true);
    }
    applyCufon();
}

From source file:com.chap.links.client.GraphDemo2_interactive_and_custom_css.java

License:Apache License

/**
 * Get the range from the timeline and put it in the textboxes on screen
 *///w w  w.j  a  v a 2 s .c o m
private void getRange() {
    Graph.DateRange range = graph.getVisibleChartRange();
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");

    // set the new startdate and enddate
    txtStartDate.setText(dtf.format(range.getStart()));
    txtEndDate.setText(dtf.format(range.getEnd()));
}