List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
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.j a v a 2 s .com 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 {//ww w .ja v a 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./*ww w . j a v a2s. c om*/ * * @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.ja v a2s . c om * * @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 ""; }// w w w . j a va 2s . c om return value.getMonthOfYear() + "/" + value.getDayOfMonth() + "/" + value.getYear(); }
From source file:org.onebusaway.admin.util.VehicleStatusBuilder.java
License:Apache License
private String getPullinTime(String pulloutTime, String pullinTime) { StringBuilder pullinTimeBuilder = new StringBuilder(extractTime(pullinTime)); DateTimeFormatter formatter = ISODateTimeFormat.dateTimeNoMillis(); DateTime pulloutDateTime = formatter.parseDateTime(pulloutTime); int pulloutDay = pulloutDateTime.getDayOfMonth(); DateTime pullinDateTime = formatter.parseDateTime(pullinTime); int pullinDay = pullinDateTime.getDayOfMonth(); //Check if pullout time falls on the next day if (pulloutDay < pullinDay) { pullinTimeBuilder.append(" +1 day"); }/* ww w.j a v a 2 s . com*/ return pullinTimeBuilder.toString(); }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Gets the current hour, minute and second from a dublin core period if available. * * @param period/*ww w .ja v a 2 s. c om*/ * The current period from dublin core. * @return A new DateTime with the current hour, minute and second. */ static DateTime getCurrentStartDate(Opt<DCMIPeriod> period) { DateTime currentStartDate = new DateTime(); currentStartDate = currentStartDate.withZone(DateTimeZone.UTC); currentStartDate = currentStartDate.withYear(2001); currentStartDate = currentStartDate.withMonthOfYear(1); currentStartDate = currentStartDate.withDayOfMonth(1); if (period.isSome() && period.get().hasStart()) { DateTime fromDC = new DateTime(period.get().getStart().getTime()); fromDC = fromDC.withZone(DateTimeZone.UTC); currentStartDate = currentStartDate.withZone(DateTimeZone.UTC); currentStartDate = currentStartDate.withYear(fromDC.getYear()); currentStartDate = currentStartDate.withMonthOfYear(fromDC.getMonthOfYear()); currentStartDate = currentStartDate.withDayOfMonth(fromDC.getDayOfMonth()); } return currentStartDate; }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Gets the current hour, minute and second from a dublin core period if available. * * @param period// w w w . ja va2 s . com * The current period from dublin core. * @return A new DateTime with the current hour, minute and second. */ private static DateTime getCurrentStartDateTime(Opt<DCMIPeriod> period) { DateTime currentStartTime = new DateTime(); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withYear(2001); currentStartTime = currentStartTime.withMonthOfYear(1); currentStartTime = currentStartTime.withDayOfMonth(1); currentStartTime = currentStartTime.withHourOfDay(0); currentStartTime = currentStartTime.withMinuteOfHour(0); currentStartTime = currentStartTime.withSecondOfMinute(0); if (period.isSome() && period.get().hasStart()) { DateTime fromDC = new DateTime(period.get().getStart().getTime()); fromDC = fromDC.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withYear(fromDC.getYear()); currentStartTime = currentStartTime.withMonthOfYear(fromDC.getMonthOfYear()); currentStartTime = currentStartTime.withDayOfMonth(fromDC.getDayOfMonth()); currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay()); currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour()); currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute()); } return currentStartTime; }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Sets the start time in a dublin core catalog to the right value and keeps the start date and duration the same. * * @param dc/*w ww. ja v a 2 s . c om*/ * The dublin core catalog to adjust * @param field * The metadata field that contains the start time. * @param ename * The EName in the catalog to identify the property that has the dublin core period. */ static void setTemporalStartTime(DublinCoreCatalog dc, MetadataField<?> field, EName ename) { if (field.getValue().isNone() || (field.getValue().get() instanceof String && StringUtils.isBlank(field.getValue().get().toString()))) { logger.debug("No value was set for metadata field with dublin core id '{}' and json id '{}'", field.getInputID(), field.getOutputID()); return; } try { // Get the current date SimpleDateFormat dateFormat = MetadataField.getSimpleDateFormatter(field.getPattern().get()); Date startDate = dateFormat.parse((String) field.getValue().get()); // Get the current period Opt<DCMIPeriod> period = getPeriodFromCatalog(dc, ename); // Get the current duration Long duration = getDuration(period); // Get the current start date DateTime currentStartDate = getCurrentStartDate(period); // Setup the new start time DateTime startDateTime = new DateTime(startDate.getTime()); startDateTime = startDateTime.withZone(DateTimeZone.UTC); startDateTime = startDateTime.withYear(currentStartDate.getYear()); startDateTime = startDateTime.withMonthOfYear(currentStartDate.getMonthOfYear()); startDateTime = startDateTime.withDayOfMonth(currentStartDate.getDayOfMonth()); // Get the current end date based on new date and duration. DateTime endDate = new DateTime(startDateTime.toDate().getTime() + duration); dc.set(ename, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(startDateTime.toDate(), endDate.toDate()), Precision.Second)); } catch (ParseException e) { logger.error("Not able to parse date {} to update the dublin core because: {}", field.getValue(), ExceptionUtils.getStackTrace(e)); } }
From source file:org.openehr.rm.datatypes.quantity.datetime.DvDate.java
License:LGPL
/** * Parses a string value and return a DvDate *//*ww w.j av a 2 s . c o m*/ public DvDate parse(String value) { DateTime date = DvDateTimeParser.parseDate(value); return new DvDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); }