List of usage examples for org.joda.time DateTime parse
@FromString public static DateTime parse(String str)
From source file:org.opentestsystem.delivery.testadmin.domain.schedule.ScheduledStudent.java
License:Open Source License
@SuppressWarnings("unchecked") private <T> T convertTo(final String value, final Class<T> clazz) { try {/*from ww w .j a va 2 s . co m*/ if (String.class.isAssignableFrom(clazz)) { return (T) value; } else if (Number.class.isAssignableFrom(clazz)) { return clazz.getConstructor(String.class).newInstance(value); } else if (DateTime.class.isAssignableFrom(clazz)) { return (T) DateTime.parse(value); } else if (Enum.class.isAssignableFrom(clazz)) { Method getEnum = null; try { getEnum = clazz.getDeclaredMethod("getEnumByValue", String.class); } catch (final NoSuchMethodException me) { getEnum = clazz.getMethod("valueOf", String.class); } return (T) getEnum.invoke(null, value); } else { throw new EligibilityException("eligibility.value.convert.error", new String[] { value, clazz.toString() }); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { throw new EligibilityException("eligibility.value.convert.error", new String[] { value, clazz.toString() }, e); } }
From source file:org.opentestsystem.delivery.testreg.domain.ImplicitEligibilityRule.java
License:Open Source License
private String getDateInStringFormat(final String strDate) { DateTime dtValue = null;/*w ww . ja va2 s .co m*/ if (isNotEmpty(strDate)) { dtValue = DateTime.parse(strDate); final DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ"); return fmt.print(dtValue); } return strDate; }
From source file:org.opentestsystem.delivery.testreg.domain.Student.java
License:Open Source License
private DateTime getDate(final String strDate) { if (isNotEmpty(strDate)) { return DateTime.parse(strDate); }/*from w w w.j a v a2 s . c o m*/ return null; }
From source file:org.opentestsystem.shared.search.domain.SearchFilter.java
License:Open Source License
/** * Get the values to be searched on/* w ww. jav a 2s . c o m*/ * * @param strings * @return */ public Object[] getSearchValue(final String... strings) { Object[] vals = new Object[strings.length]; int index = 0; NumberFormat format = NumberFormat.getInstance(Locale.US); for (String value : strings) { if (StringUtils.isNotEmpty(value)) { try { Object val = null; StringBuffer debugMsg = new StringBuffer("creating search value "); switch (this.dataType) { case Number: val = format.parse(value); debugMsg.append(value).append(" as number ").append(val); break; case MilliDate: val = new DateTime(format.parse(value).longValue()); debugMsg.append(value).append(" as date from millis ").append(val); break; case ISO8601Date: val = DateTime.parse(value); debugMsg.append(value).append(" as date from ISO-8601 String ").append(val); break; case Boolean: val = Boolean.parseBoolean(value); debugMsg.append(value).append(" as boolean ").append(val); break; case ObjectId: val = new ObjectId(value); debugMsg.append(value).append(" as Object ID from String ").append(val); break; default: val = value; debugMsg = new StringBuffer(SB_INIT_SIZE); debugMsg.append("keeping search value "); debugMsg.append(value); debugMsg.append(" as string"); break; } vals[index] = val; LOGGER.debug(debugMsg.toString()); } catch (ParseException e) { throw new RestException("search.criteria.invalid.format", e); } LOGGER.debug(""); } index++; } return vals; }
From source file:org.phenotips.data.rest.DateTimeAdapter.java
License:Open Source License
@Override public DateTime unmarshal(String v) { if (StringUtils.isBlank(v)) { return null; } return DateTime.parse(v); }
From source file:org.projectbuendia.client.json.DateTimeSerializer.java
License:Apache License
@Override public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return DateTime.parse(json.getAsString()); }
From source file:org.projectbuendia.client.ui.chart.LocalizedChartDataGridAdapter.java
License:Apache License
private String formatColumnHeader(String columnId) { DateTime dateTime = DateTime.parse(columnId).withChronology(mChronology); LocalDate date = dateTime.toLocalDate(); Resources res = mContext.getResources(); int admitDay = Dates.dayNumberSince(mAdmissionDate, date); String admitDayLabel = (admitDay >= 1) ? res.getString(R.string.day_n, admitDay) : ""; String dateString = date.toString("d MMM"); String dateLabel = date.equals(mToday) ? res.getString(R.string.today_date, dateString) : dateString; // The column header has two lines of text: the first line gives the day number since // admission and the second line gives the calendar date. Pending feedback from the field // on its importance, the symptom onset day number could also be shown in the column // header in a different colour. This would be done by constructing HTML and using // Html.fromHtml() to produce a Spanned object that will be rendered by the TextView. return admitDayLabel + "\n" + dateLabel; }
From source file:org.projectforge.web.address.AddressImportForm.java
License:Open Source License
/** * @param property//from w w w.j a v a 2 s. c om */ private void setBirth(final Property property, final AddressDO address) { if (property != null) address.setBirthday(new Date(DateTime.parse(property.getValue()).getMillis())); }
From source file:org.slc.sli.api.resources.security.SamlFederationResource.java
License:Apache License
/** * Check that the current time is within the specified range. * * @param notBefore//from ww w.j a va 2s .c o m * - can be null to skip before check * @param notOnOrAfter * - can be null to skip after check * * @return true if in range, false otherwise */ private boolean isTimeInRange(String notBefore, String notOnOrAfter) { DateTime currentTime = new DateTime(DateTimeZone.UTC); if (notBefore != null) { DateTime calNotBefore = DateTime.parse(notBefore); if (currentTime.isBefore(calNotBefore)) { LOG.debug("{} is before {}.", currentTime, calNotBefore); return false; } } if (notOnOrAfter != null) { DateTime calNotOnOrAfter = DateTime.parse(notOnOrAfter); if (currentTime.isAfter(calNotOnOrAfter) || currentTime.isEqual(calNotOnOrAfter)) { LOG.debug("{} is on or after {}.", currentTime, calNotOnOrAfter); return false; } } return true; }
From source file:org.smartdeveloperhub.vocabulary.language.LanguagePack.java
License:Apache License
DateTime generated() { final String property = getProperty(HEADER_GENERATED, "Could not find generation date"); try {//from w w w . j a v a 2s. c o m return DateTime.parse(property); } catch (final IllegalArgumentException e) { throw new CorruptedLanguagePackException("Invalid generation date (" + property + ")", e); } }