List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
From source file:org.mvnsearch.snippet.domain.manager.impl.SnippetServiceImpl.java
License:Open Source License
/** * render template into code/* ww w .j a v a 2 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());//from ww w. j av a 2s . c om 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 v a 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);//from w w w.j ava2s .co m picker.vibrate(false); picker.show(((Activity) getContext()).getFragmentManager(), "NTDatePickerDialog"); }
From source file:org.nuxeo.ecm.core.repository.jcr.XPathBuilder.java
License:Open Source License
/** * Process special expressions.//from w w w .ja va2s . 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 w w w.ja v a 2s . c o m 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 {//from w w w . j ava 2 s . co m // create time widget with current time as of right now clearAnswer(); } }
From source file:org.ohmage.request.event.EventReadRequest.java
License:Apache License
/** * Creates an Event read request./*from ww w . ja va 2 s.c o m*/ * * @param httpRequest The HttpServletRequest with the parameters for this * request. * * @throws InvalidRequestException Thrown if the parameters cannot be * parsed. * * @throws IOException There was an error reading from the request. */ public EventReadRequest(HttpServletRequest httpRequest) throws IOException, InvalidRequestException { super(httpRequest, null); LOGGER.info("Creating an Event read request."); String tUsername = null; DateTime tStartDate = null; StreamReadRequest tRegularReadRequest = null; StreamReadRequest tExtendedReadRequest = null; Collection<ColumnKey> tColumns = null; if (!isFailed()) { try { String[] t; getParameters().keySet().size(); t = getParameterValues(InputKeys.DATE); if (t.length == 0) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else if (t.length == 1) { tStartDate = MobilityValidators.validateDate(t[0]); if (tStartDate == null) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else { tStartDate = new DateTime(tStartDate.getYear(), tStartDate.getMonthOfYear(), tStartDate.getDayOfMonth(), 0, 0, DateTimeZone.UTC); } } else { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "Multiple date values were given: " + InputKeys.DATE); } // tColumns = null; // // // t = getParameterValues(InputKeys.MOBILITY_WITH_SENSOR_DATA); // if(t.length > 1) { // throw new ValidationException( // ErrorCode.MOBILITY_INVALID_INCLUDE_SENSOR_DATA_VALUE, // "Multiple \"include sensor data\" values to query were given: " + // InputKeys.MOBILITY_WITH_SENSOR_DATA); // } // else if(t.length == 1) { // if(MobilityValidators.validateIncludeSensorDataValue(t[0])) { // tColumns = MobilityColumnKey.ALL_COLUMNS; // } // } // // t = getParameterValues(InputKeys.COLUMN_LIST); // if(t.length > 1) { // throw new ValidationException( // ErrorCode.MOBILITY_INVALID_COLUMN_LIST, // "Multiple column lists were given: " + // InputKeys.COLUMN_LIST); // } // else if(t.length == 1) { // if(! StringUtils.isEmptyOrWhitespaceOnly(t[0])) { // if(tColumns == null) { // tColumns = // MobilityValidators.validateColumns( // t[0], // true); // } // else { // throw new ValidationException( // ErrorCode.MOBILITY_INVALID_COLUMN_LIST, // "Both '" + // InputKeys.MOBILITY_WITH_SENSOR_DATA + // "' and '" + // InputKeys.COLUMN_LIST + // "' were present. Only one may be present."); // } // } // } // if(tColumns == null) { // tColumns = DEFAULT_COLUMNS; // } // Get the user. t = getParameterValues(InputKeys.USERNAME); if (t.length > 1) { throw new ValidationException(ErrorCode.USER_INVALID_USERNAME, "Multiple usernames to query were given: " + InputKeys.USERNAME); } else if (t.length == 1) { tUsername = UserValidators.validateUsername(t[0]); } // TODO forget all that stream nonsense, just call .NET from here // Always get all of the columns. try { tRegularReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "regular", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); tExtendedReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "extended", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); } catch (IllegalArgumentException e) { throw new ValidationException("There was an error creating the request.", e); } } catch (ValidationException e) { e.failRequest(this); e.logException(LOGGER); } } username = tUsername; startDate = tStartDate; regularReadRequest = tRegularReadRequest; extendedReadRequest = tExtendedReadRequest; columns = tColumns; points = new ArrayList<MobilityPoint>(); }
From source file:org.ohmage.request.mobility.MobilityReadRequest.java
License:Apache License
/** * Creates a Mobility read request./*from w w w . j a va2s.c o m*/ * * @param httpRequest The HttpServletRequest with the parameters for this * request. * * @throws InvalidRequestException Thrown if the parameters cannot be * parsed. * * @throws IOException There was an error reading from the request. */ public MobilityReadRequest(HttpServletRequest httpRequest) throws IOException, InvalidRequestException { super(httpRequest, null); LOGGER.info("Creating a Mobility read request."); String tUsername = null; DateTime tStartDate = null; StreamReadRequest tRegularReadRequest = null; StreamReadRequest tExtendedReadRequest = null; Collection<ColumnKey> tColumns = null; if (!isFailed()) { try { String[] t; t = getParameterValues(InputKeys.DATE); if (t.length == 0) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else if (t.length == 1) { tStartDate = MobilityValidators.validateDate(t[0]); if (tStartDate == null) { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "The date value is missing: " + InputKeys.DATE); } else { tStartDate = new DateTime(tStartDate.getYear(), tStartDate.getMonthOfYear(), tStartDate.getDayOfMonth(), 0, 0, DateTimeZone.UTC); } } else { throw new ValidationException(ErrorCode.SERVER_INVALID_DATE, "Multiple date values were given: " + InputKeys.DATE); } tColumns = null; t = getParameterValues(InputKeys.MOBILITY_WITH_SENSOR_DATA); if (t.length > 1) { throw new ValidationException(ErrorCode.MOBILITY_INVALID_INCLUDE_SENSOR_DATA_VALUE, "Multiple \"include sensor data\" values to query were given: " + InputKeys.MOBILITY_WITH_SENSOR_DATA); } else if (t.length == 1) { if (MobilityValidators.validateIncludeSensorDataValue(t[0])) { tColumns = MobilityColumnKey.ALL_COLUMNS; } } t = getParameterValues(InputKeys.COLUMN_LIST); if (t.length > 1) { throw new ValidationException(ErrorCode.MOBILITY_INVALID_COLUMN_LIST, "Multiple column lists were given: " + InputKeys.COLUMN_LIST); } else if (t.length == 1) { if (!StringUtils.isEmptyOrWhitespaceOnly(t[0])) { if (tColumns == null) { tColumns = MobilityValidators.validateColumns(t[0], true); } else { throw new ValidationException(ErrorCode.MOBILITY_INVALID_COLUMN_LIST, "Both '" + InputKeys.MOBILITY_WITH_SENSOR_DATA + "' and '" + InputKeys.COLUMN_LIST + "' were present. Only one may be present."); } } } if (tColumns == null) { tColumns = DEFAULT_COLUMNS; } // Get the user. t = getParameterValues(InputKeys.USERNAME); if (t.length > 1) { throw new ValidationException(ErrorCode.USER_INVALID_USERNAME, "Multiple usernames to query were given: " + InputKeys.USERNAME); } else if (t.length == 1) { tUsername = UserValidators.validateUsername(t[0]); } // Always get all of the columns. try { tRegularReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "regular", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); tExtendedReadRequest = new StreamReadRequest(httpRequest, getParameterMap(), false, TokenLocation.EITHER, false, tUsername, "edu.ucla.cens.Mobility", null, "extended", 2012050700, tStartDate.minusMinutes(10), tStartDate.plusDays(1), null, true, null, null); } catch (IllegalArgumentException e) { throw new ValidationException("There was an error creating the request.", e); } } catch (ValidationException e) { e.failRequest(this); e.logException(LOGGER); } } username = tUsername; startDate = tStartDate; regularReadRequest = tRegularReadRequest; extendedReadRequest = tExtendedReadRequest; columns = tColumns; points = new ArrayList<MobilityPoint>(); }
From source file:org.ojbc.web.portal.controllers.helpers.DateTimePropertyEditor.java
License:RPL License
@Override public String getAsText() { DateTime value = (DateTime) this.getValue(); if (value == null) { return ""; }//from w w w . jav a 2s. c om return value.getMonthOfYear() + "/" + value.getDayOfMonth() + "/" + value.getYear(); }