Example usage for org.joda.time DateTime getYear

List of usage examples for org.joda.time DateTime getYear

Introduction

In this page you can find the example usage for org.joda.time DateTime getYear.

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:org.mongoste.util.DateUtil.java

License:Open Source License

public static DateTime toUTC(DateTime fromDate) {
    if (DateTimeZone.UTC.equals(fromDate.getZone())) {
        return fromDate;
    }/*  w  w w . j  ava  2 s .c  o  m*/
    MutableDateTime dt = getDateTimeUTC().toMutableDateTime();
    dt.setDateTime(fromDate.getYear(), fromDate.getMonthOfYear(), fromDate.getDayOfMonth(),
            fromDate.getHourOfDay(), fromDate.getMinuteOfHour(), fromDate.getSecondOfMinute(),
            fromDate.getMillisOfSecond());
    return dt.toDateTime();
}

From source file:org.mvnsearch.snippet.domain.manager.impl.SnippetServiceImpl.java

License:Open Source License

/**
 * render template into code//from  w  w w. j av a2 s .  c o m
 *
 * @param mnemonic    mnemonic
 * @param packageName package name
 * @param fileName    file name
 * @param author      author name
 * @return rendered code
 */
public String renderTemplate(String mnemonic, String packageName, String fileName, String author) {
    DetachedCriteria criteria = DetachedCriteria.forClass(Snippet.class);
    criteria.add(Restrictions.eq("mnemonic", mnemonic));
    if (language > 0) {
        criteria.add(Restrictions.eq("language", language));
    }
    List<Snippet> snippets = getHibernateTemplate().findByCriteria(criteria);
    if (!snippets.isEmpty()) {
        Snippet snippet = snippets.get(0);
        String className = fileName;
        if (StringUtils.isNotEmpty(className) && className.indexOf(".") != -1) {
            className = className.substring(0, className.indexOf("."));
        }
        String code = snippet.getCode();
        if (StringUtils.isNotEmpty(author)) {
            code = code.replace("${USER}", author);
        }
        if (StringUtils.isNotEmpty(packageName)) {
            code = code.replace("${PACKAGE_NAME}", packageName);
        }
        if (StringUtils.isNotEmpty(fileName)) {
            code = code.replace("${NAME}", className);
            code = code.replace("${FILE_NAME}", fileName);
        }
        //date info replace
        DateTime now = new DateTime();
        code = code.replace("${YEAR}", String.valueOf(now.getYear()));
        code = code.replace("${MONTH}", String.valueOf(now.getMonthOfYear()));
        code = code.replace("${DAY}", String.valueOf(now.getDayOfMonth()));
        return code;
    }
    return "";
}

From source file:org.nekorp.workflow.backend.service.reporte.global.RenglonFactoryRG.java

License:Apache License

@Override
public RenglonRG build(Servicio data) {
    RenglonRG r = new RenglonRG();
    r.setDatosAuto(factoryAuto.build(data));
    r.setDatosBitacora(factoryBitacora.build(data));
    r.setDatosCliente(factoryCliente.build(data));
    r.setDatosCosto(factoryCosto.build(data));
    r.setDatosServicio(factoryServicio.build(data));
    Date entradaAutoRaw = r.getDatosBitacora().getFechaIngresoAuto();
    if (entradaAutoRaw != null) {
        DateTime entradaAuto = new DateTime(entradaAutoRaw);
        entradaAuto = new DateTime(entradaAuto.getYear(), entradaAuto.getMonthOfYear(),
                entradaAuto.getDayOfMonth(), entradaAuto.hourOfDay().getMinimumValue(),
                entradaAuto.minuteOfHour().getMinimumValue(), entradaAuto.secondOfMinute().getMinimumValue(),
                entradaAuto.millisOfSecond().getMinimumValue(), entradaAuto.getZone());
        DateTime iniServ = new DateTime(data.getMetadata().getFechaInicio());
        iniServ = new DateTime(iniServ.getYear(), iniServ.getMonthOfYear(), iniServ.getDayOfMonth(),
                iniServ.hourOfDay().getMinimumValue(), iniServ.minuteOfHour().getMinimumValue(),
                iniServ.secondOfMinute().getMinimumValue(), iniServ.millisOfSecond().getMinimumValue(),
                iniServ.getZone());//  w  w w.  jav a 2s. com
        if (iniServ.isBefore(entradaAuto)) {
            r.getDatosServicio().setProgramado("X");
        }
    }
    return r;
}

From source file:org.nekorp.workflow.desktop.view.AppLayoutView.java

License:Apache License

private void reporteGlobalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteGlobalButtonActionPerformed
    try {//from   ww w  .ja  va  2  s.  c o m
        parametrosReporteGlobal.setFechaInicial(new Date());
        parametrosReporteGlobal.setFechaFinal(new Date());
        parametrosReporteGlobalDialogFactory.createDialog(mainFrame, true).setVisible(true);
        if (parametrosReporteGlobal.isEjecutar()) {
            JFileChooser chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Hojas de clculo", "xlsx");
            chooser.setFileFilter(filter);
            String homePath = System.getProperty("user.home");
            File f = new File(new File(homePath + "/Reporte-Global" + ".xlsx").getCanonicalPath());
            chooser.setSelectedFile(f);
            int returnVal = chooser.showSaveDialog(this.mainFrame);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
                ParametrosReporteGlobal param = new ParametrosReporteGlobal();
                param.setDestination(chooser.getSelectedFile());
                DateTime fechaInicial = new DateTime(parametrosReporteGlobal.getFechaInicial());
                DateTime fechaFinal = new DateTime(parametrosReporteGlobal.getFechaFinal());
                fechaFinal = new DateTime(fechaFinal.getYear(), fechaFinal.getMonthOfYear(),
                        fechaFinal.getDayOfMonth(), fechaFinal.hourOfDay().getMaximumValue(),
                        fechaFinal.minuteOfHour().getMaximumValue(),
                        fechaFinal.secondOfMinute().getMaximumValue(),
                        fechaFinal.millisOfSecond().getMaximumValue(), fechaFinal.getZone());
                param.setFechaInicial(fechaInicial);
                param.setFechaFinal(fechaFinal);
                this.aplication.generaReporteGlobal(param);
            }
        }
    } catch (IOException ex) {
        AppLayoutView.LOGGER.error("Exploto al tratar de generar el reporte global", ex);
    } finally {
        this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR));
    }
}

From source file:org.neotree.ui.view.DateTimeFieldView.java

License:Open Source License

@OnClick(R.id.field_date_button)
public void onDateFieldClick() {
    DateTime pickerDate = (getValue() != null) ? getValue() : DateTime.now();
    DatePickerDialog picker = DatePickerDialog.newInstance(this, pickerDate.getYear(),
            pickerDate.getMonthOfYear() - 1, // Damn Java!
            pickerDate.getDayOfMonth());
    picker.setMaxDate(Calendar.getInstance());
    picker.dismissOnPause(true);/* w w  w  . j  a  v  a2  s .  co  m*/
    picker.vibrate(false);
    picker.show(((Activity) getContext()).getFragmentManager(), "NTDatePickerDialog");
}

From source file:org.numenta.nupic.encoders.DateEncoder.java

License:Open Source License

/**
 * Returns an {@link TDoubleList} containing the sub-field scalar value(s) for
 * each sub-field of the inputData. To get the associated field names for each of
 * the scalar values, call getScalarNames().
 *
 * @param inputData   the input value, in this case a date object
 * @return   a list of one input double/*from  w w  w  .  j a  va2 s .co m*/
 */
public TDoubleList getScalars(DateTime inputData) {
    if (inputData == null) {
        throw new IllegalArgumentException("DateEncoder requires a valid Date object but got null");
    }

    TDoubleList values = new TDoubleArrayList();

    //Get the scalar values for each sub-field

    double timeOfDay = inputData.getHourOfDay() + inputData.getMinuteOfHour() / 60.0;

    // The day of week was 1 based, so convert to 0 based
    int dayOfWeek = inputData.getDayOfWeek() - 1; // + timeOfDay / 24.0

    if (seasonEncoder != null) {
        // The day of year was 1 based, so convert to 0 based
        double dayOfYear = inputData.getDayOfYear() - 1;
        values.add(dayOfYear);
    }

    if (dayOfWeekEncoder != null) {
        values.add(dayOfWeek);
    }

    if (weekendEncoder != null) {

        //saturday, sunday or friday evening
        boolean isWeekend = dayOfWeek == 6 || dayOfWeek == 5 || (dayOfWeek == 4 && timeOfDay > 18);

        int weekend = isWeekend ? 1 : 0;

        values.add(weekend);
    }

    if (customDaysEncoder != null) {
        boolean isCustomDays = customDaysList.contains(dayOfWeek);

        int customDay = isCustomDays ? 1 : 0;

        values.add(customDay);
    }

    if (holidayEncoder != null) {
        // A "continuous" binary value. = 1 on the holiday itself and smooth ramp
        //  0->1 on the day before the holiday and 1->0 on the day after the holiday.

        double holidayness = 0;

        for (Tuple h : holidaysList) {
            //hdate is midnight on the holiday
            DateTime hdate = new DateTime(inputData.getYear(), (int) h.get(0), (int) h.get(1), 0, 0, 0);

            if (inputData.isAfter(hdate)) {
                Duration diff = new Interval(hdate, inputData).toDuration();
                long days = diff.getStandardDays();
                if (days == 0) {
                    //return 1 on the holiday itself
                    holidayness = 1;
                    break;
                } else if (days == 1) {
                    //ramp smoothly from 1 -> 0 on the next day
                    holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0);
                    break;
                }

            } else {
                //TODO This is not the same as when date.isAfter(hdate), why?
                Duration diff = new Interval(inputData, hdate).toDuration();
                long days = diff.getStandardDays();
                if (days == 0) {
                    //ramp smoothly from 0 -> 1 on the previous day
                    holidayness = 1.0 - ((diff.getStandardSeconds() - 86400.0 * days) / 86400.0);
                    //TODO Why no break?
                }
            }
        }

        values.add(holidayness);
    }

    if (timeOfDayEncoder != null) {
        values.add(timeOfDay);
    }

    return values;
}

From source file:org.nuxeo.ecm.core.repository.jcr.XPathBuilder.java

License:Open Source License

/**
 * Process special expressions.//ww w . j a va2 s.co m
 * <p>
 * If the expression is not a special one, return false so that the
 * expression will be processed in the default way. Otherwise process it and
 * return true.
 */
private boolean specialExpression(Expression expr) throws QueryException {
    if (expr.lvalue instanceof Reference) { // TODO remove this
        String name = ((Reference) expr.lvalue).name;
        if (name.equals(NXQL.ECM_FULLTEXT)) {
            if (expr.rvalue.getClass() != StringLiteral.class) {
                throw new QueryException(
                        "Invalid query: " + NXQL.ECM_FULLTEXT + " can only be compared against string values");
            }
            xq.predicate.append("jcr:contains(., '").append(((StringLiteral) expr.rvalue).value).append("')");
            return true;
        } else if (name.equals(NXQL.ECM_NAME)) {
            if (expr.rvalue.getClass() != StringLiteral.class) {
                throw new QueryException(
                        "Invalid query: " + NXQL.ECM_NAME + "can only be compared against string values");
            }
            xq.predicate.append("fn:name() ").append(operator(expr.operator)).append(" '")
                    .append(((StringLiteral) expr.rvalue).value).append("'");
            return true;
        } else if (name.equals(NXQL.ECM_MIXINTYPE)) {
            if (expr.operator.equals(Operator.NOTEQ)) {
                LiteralList rvalue = new LiteralList();
                rvalue.add((Literal) expr.rvalue);
                xq.predicate.append(" not(");
                inclusion(xq.predicate, expr.lvalue, rvalue);
                xq.predicate.append(") ");
                return true;
            }
        } else if (expr.rvalue.getClass() == DateLiteral.class) { // dates
            // *[@dc:created > "2008-06-03T00:00:00.000+01:00" and
            // @dc:created < xs:dateTime("2008-06-04T00:00:00.000+01:00")]
            // xs:date seems to not be correctly handled in jackrabbit .
            // see
            // https://issues.apache.org/jira/browse/JCR-1386?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
            DateLiteral dl = (DateLiteral) expr.rvalue;
            Reference ref = (Reference) expr.lvalue;
            if (dl.onlyDate) {
                if (expr.operator == Operator.EQ) {
                    DateTime d0 = dl.value;
                    DateTime d1 = d0.plusDays(1);
                    int month = d0.getMonthOfYear();
                    int day = d0.getDayOfMonth();
                    xq.predicate.append("(");
                    reference(xq.predicate, ref);
                    xq.predicate.append(" >= xs:dateTime('").append(d0.getYear()).append("-");
                    if (month < 10) {
                        xq.predicate.append("0").append(month);
                    } else {
                        xq.predicate.append(month);
                    }
                    xq.predicate.append("-");
                    if (day < 10) {
                        xq.predicate.append("0").append(day);
                    } else {
                        xq.predicate.append(day);
                    }
                    xq.predicate.append("T00:00:00.000Z') and ");

                    month = d1.getMonthOfYear();
                    day = d1.getDayOfMonth();
                    reference(xq.predicate, ref);
                    xq.predicate.append(" < xs:dateTime('").append(d1.getYear()).append("-");
                    if (month < 10) {
                        xq.predicate.append("0").append(month);
                    } else {
                        xq.predicate.append(month);
                    }
                    xq.predicate.append("-");
                    if (day < 10) {
                        xq.predicate.append("0").append(day);
                    } else {
                        xq.predicate.append(day);
                    }
                    xq.predicate.append("T00:00:00.000Z'))");
                } else if (expr.operator == Operator.GTEQ) {
                    DateTime date = dl.value;
                    compareDate(xq.predicate, ref, expr.operator, date);
                } else if (expr.operator == Operator.GT) {
                    DateTime date = dl.value.plusDays(1);
                    compareDate(xq.predicate, ref, Operator.GTEQ, date);
                } else if (expr.operator == Operator.LT) {
                    DateTime date = dl.value;
                    compareDate(xq.predicate, ref, expr.operator, date);
                } else if (expr.operator == Operator.LTEQ) {
                    DateTime date = dl.value.plusDays(1);
                    compareDate(xq.predicate, ref, Operator.LT, date);
                }
            } else {
                reference(xq.predicate, ref);
                operator(xq.predicate, expr.operator);
                xq.predicate.append("xs:dateTime('" + DateLiteral.dateTime(dl) + "')");
            }
            return true;
        }
    }
    return false;
}

From source file:org.nuxeo.ecm.core.repository.jcr.XPathBuilder.java

License:Open Source License

private void compareDate(StringBuilder buf, Reference ref, Operator operator, DateTime date) {
    int month = date.getMonthOfYear();
    int day = date.getDayOfMonth();
    reference(buf, ref);/*from  www.j a  v  a 2  s  .  c  om*/
    operator(buf, operator);
    buf.append("xs:dateTime('").append(date.getYear()).append("-");
    if (month < 10) {
        buf.append("0").append(month);
    } else {
        buf.append(month);
    }
    buf.append("-");
    if (day < 10) {
        buf.append("0").append(day);
    } else {
        buf.append(day);
    }
    buf.append("T00:00:00.000Z')");
}

From source file:org.odk.collect.android.widgets.DateTimeWidgettext.java

License:Apache License

private void setAnswer() {

    if (mPrompt.getAnswerValue() != null) {

        DateTime ldt = new DateTime(((Date) ((DateTimeData) mPrompt.getAnswerValue()).getValue()).getTime());
        mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener);
        mTimePicker.setCurrentHour(ldt.getHourOfDay());
        mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
        textofwidget.setText(String.valueOf(ldt.getDayOfMonth()) + "/"
                + String.valueOf(ldt.getMonthOfYear() - 1) + "/" + String.valueOf((ldt.getYear())));
    } else {/*  w  w w  . j av a 2  s  .c o m*/
        // create time widget with current time as of right now
        clearAnswer();
    }
}