List of usage examples for org.joda.time DateTime parse
public static DateTime parse(String str, DateTimeFormatter formatter)
From source file:prototypes.ws.proxy.soap.commons.time.Dates.java
License:Apache License
public static Calendar parseToCalendar(String cal, String pattern) { DateTime dt = DateTime.parse(cal, DateTimeFormat.forPattern(pattern)); return dt.toGregorianCalendar(); }
From source file:pt.ist.fenixedu.integration.api.infra.FenixAPICanteen.java
License:Open Source License
public static String get(String daySearch) { String locale = I18N.getLocale().toString().replace("_", "-"); if (canteenInfo == null || canteenInfo.isJsonNull() || oldInformation()) { String canteenUrl = FenixEduIstIntegrationConfiguration.getConfiguration().getFenixApiCanteenUrl(); try {/*from w w w . j av a2 s . c o m*/ Response response = HTTP_CLIENT.target(canteenUrl).request(MediaType.APPLICATION_JSON) .header("Authorization", getServiceAuth()).get(); if (response.getStatus() == 200) { JsonParser parser = new JsonParser(); canteenInfo = (JsonObject) parser.parse(response.readEntity(String.class)); day = new DateTime(); } else { return new JsonObject().toString(); } } catch (ProcessingException e) { e.printStackTrace(); return new JsonObject().toString(); } } JsonArray jsonArrayWithLang = canteenInfo.getAsJsonArray(locale); DateTime dayToCompareStart; DateTime dayToCompareEnd; DateTime dateTime = DateTime.parse(daySearch, DateTimeFormat.forPattern(datePattern)); int dayOfWeek = dateTime.getDayOfWeek(); if (dayOfWeek != 7) { dayToCompareStart = dateTime.minusDays(dayOfWeek); dayToCompareEnd = dateTime.plusDays(7 - dayOfWeek); } else { dayToCompareStart = dateTime; dayToCompareEnd = dateTime.plusDays(7); } JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (dateToCompare.isAfter(dayToCompareStart) && dateToCompare.isBefore(dayToCompareEnd)) { jsonResult.add(jObj); } } Gson gson = new GsonBuilder().setPrettyPrinting().create(); return gson.toJson(jsonResult); }
From source file:pt.ist.fenixedu.integration.api.infra.FenixAPIFromExternalServer.java
License:Open Source License
public static String getCanteen(String daySearch, String canteenName) { String canteenUrl = FenixEduIstIntegrationConfiguration.getConfiguration().getFenixApiCanteenUrl() .concat("?name=" + canteenName); JsonObject canteenInfo = getInformation(canteenUrl); String lang = I18N.getLocale().toLanguageTag(); if (!canteenInfo.has(lang)) { return empty.toString(); }/* w w w .j a va 2 s . c o m*/ JsonArray jsonArrayWithLang = canteenInfo.getAsJsonObject().getAsJsonArray(lang); DateTime dayToCompareStart; DateTime dayToCompareEnd; DateTime dateTime = DateTime.parse(daySearch, DateTimeFormat.forPattern(datePattern)); int dayOfWeek = dateTime.getDayOfWeek(); if (dayOfWeek != 7) { dayToCompareStart = dateTime.minusDays(dayOfWeek); dayToCompareEnd = dateTime.plusDays(7 - dayOfWeek); } else { dayToCompareStart = dateTime; dayToCompareEnd = dateTime.plusDays(7); } Interval validInterval = new Interval(dayToCompareStart, dayToCompareEnd); JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (validInterval.contains(dateToCompare)) { jsonResult.add(jObj); } } return gson.toJson(jsonResult); }
From source file:rapture.dp.invocable.CheckPrerequisiteStep.java
License:Open Source License
private boolean isDataReady(CallingContext ctx, PrerequisiteConfig config) { outer: for (PrerequisiteConfig.RequiredData requiredData : config.getRequiredData()) { if (log.isDebugEnabled()) log.debug("Check requirement " + requiredData.toString()); String uri = requiredData.getUri(); int chevron = uri.indexOf('<'); RaptureURI ruri = new RaptureURI((chevron > 0) ? uri.substring(0, chevron - 1) : uri); String keyFormat = requiredData.getKeyFormat(); if (StringUtils.isEmpty(keyFormat)) keyFormat = "yyyyMMdd"; String specificDate = StringUtils.trimToNull(requiredData.getSpecificDate()); if ((specificDate != null) && specificDate.startsWith("$")) { specificDate = Kernel.getDecision().getContextValue(ctx, getWorkerURI(), specificDate.substring(1)); }//from w w w.jav a 2 s.com // For series we look for a data point with the valid date if (ruri.getScheme().equals(Scheme.SERIES)) { if (specificDate != null) log.warn("specificDate not supported for series data"); DateTime acceptableTime = getDateTime(DateTime.now().withTimeAtStartOfDay(), requiredData.getDateWithin(), requiredData.getTimeNoEarlierThan()); if (!isDataReady.contains(uri)) { if (!Kernel.getSeries().seriesExists(ctx, uri)) { log.debug("Series not found " + uri); return false; } SeriesPoint lastDataPoint = Kernel.getSeries().getLastPoint(ctx, uri); DateTime lastDataPointTime = DateTime.parse(lastDataPoint.getColumn(), DateTimeFormat.forPattern(keyFormat)); log.debug("Last data point is at " + lastDataPointTime); if (lastDataPointTime.isBefore(acceptableTime)) { log.debug("data point is outside acceptable range"); return false; } else { log.debug("data point is valid"); isDataReady.add(uri); } } else { log.debug("data point already seen"); } } else { // For types other than series we simply check for the existence of the blob/doc/sheet etc. DateTime start = (specificDate != null) ? DateTime.parse(specificDate, DateTimeFormat.forPattern(keyFormat)) : DateTime.now().withTimeAtStartOfDay(); DateTime acceptableTime = getDateTime(start, requiredData.getDateWithin(), requiredData.getTimeNoEarlierThan()); DateTime lastDataPointTime = (specificDate == null) ? new DateTime() : acceptableTime; SimpleDateFormat sdf = new SimpleDateFormat(keyFormat); while (!lastDataPointTime.isBefore(acceptableTime)) { String datedUri = uri; if (uri.contains("<DATE>")) datedUri = uri.replace("<DATE>", sdf.format(lastDataPointTime.toDate())); if (isDataReady.contains(datedUri)) { if (log.isDebugEnabled()) log.debug(datedUri.toString() + " already seen"); continue outer; } boolean uriExists = false; // There is no generic exists method. switch (ruri.getScheme()) { case BLOB: uriExists = Kernel.getBlob().blobExists(ctx, datedUri); break; case DOCUMENT: uriExists = Kernel.getDoc().docExists(ctx, datedUri); break; default: log.warn("Unexpected URI type : " + uri); return false; } if (uriExists) { if (log.isDebugEnabled()) log.debug(datedUri.toString() + " found"); isDataReady.add(uri); continue outer; } // Go back one day lastDataPointTime = lastDataPointTime.minusDays(1); } // Fail because we went outside acceptable time range // - we continue the outer for loop if successful log.debug("requirement not met"); return false; } } // All found return true; }
From source file:se.jguru.nazgul.core.reflection.api.conversion.registry.helpers.MultiConverter.java
License:Apache License
@Converter(acceptsNullValues = true) public Date convertToDate(final DateTime dateTime) { if (dateTime == null) { return DateTime.parse("2012-03-04T05:06", ISODateTimeFormat.dateHourMinute()).toDate(); }//from w ww. j a v a 2s . com // Convert the supplied calendarDate return dateTime.toDate(); }
From source file:se.jguru.nazgul.core.reflection.api.conversion.registry.helpers.MultiConverter.java
License:Apache License
@Converter(conditionalConversionMethod = "isBasicDateTimeNoMillisFormat") public DateTime convertToDateTime(final String aString) { return DateTime.parse(aString, ISODateTimeFormat.basicDateTimeNoMillis()); }
From source file:se.jguru.nazgul.core.reflection.api.conversion.registry.helpers.MultiConverter.java
License:Apache License
public boolean isBasicDateTimeNoMillisFormat(final String aString) { try {//from ww w . jav a2 s. c om DateTime.parse(aString, ISODateTimeFormat.basicDateTimeNoMillis()); } catch (Exception e) { return false; } return true; }
From source file:se.jguru.nazgul.core.reflection.api.conversion.registry.helpers.MultiConverter.java
License:Apache License
public DateTime nonAnnotatedConverterMethod(final String aString) { return DateTime.parse(aString, ISODateTimeFormat.basicDateTimeNoMillis()); }
From source file:se.jguru.nazgul.core.reflection.api.conversion.registry.helpers.MultiConverter.java
License:Apache License
@Converter(priority = 200, conditionalConversionMethod = "isDateHourMinuteFormat") public DateTime lowerPriorityDateTimeConverter(final String aString) { return DateTime.parse(aString, ISODateTimeFormat.dateHourMinute()); }
From source file:se.jguru.nazgul.core.reflection.api.conversion.registry.helpers.MultiConverter.java
License:Apache License
public boolean isDateHourMinuteFormat(final String aString) { try {// ww w. j ava 2s .co m DateTime.parse(aString, ISODateTimeFormat.dateHourMinute()); } catch (Exception e) { return false; } return true; }