List of usage examples for org.joda.time.format ISODateTimeFormat date
public static DateTimeFormatter date()
From source file:com.vityuk.ginger.provider.format.JodaTimeUtils.java
License:Apache License
private static DateTimeFormatter createJodaDateFormatter(FormatType formatType, DateFormatStyle formatStyle) { switch (formatType) { case TIME:/*from w w w. j a v a 2 s . co m*/ switch (formatStyle) { case SHORT: return DateTimeFormat.shortTime(); case MEDIUM: return DateTimeFormat.mediumTime(); case LONG: return DateTimeFormat.longTime(); case FULL: return DateTimeFormat.fullTime(); case DEFAULT: return ISODateTimeFormat.time(); } case DATE: switch (formatStyle) { case SHORT: return DateTimeFormat.shortDate(); case MEDIUM: return DateTimeFormat.mediumDate(); case LONG: return DateTimeFormat.longDate(); case FULL: return DateTimeFormat.fullDate(); case DEFAULT: return ISODateTimeFormat.date(); } case DATETIME: switch (formatStyle) { case SHORT: return DateTimeFormat.shortDateTime(); case MEDIUM: return DateTimeFormat.mediumDateTime(); case LONG: return DateTimeFormat.longDateTime(); case FULL: return DateTimeFormat.fullDateTime(); case DEFAULT: return ISODateTimeFormat.dateTime(); } } throw new IllegalArgumentException(); }
From source file:de.geeksfactory.opacclient.objects.Copy.java
License:MIT License
/** * Get property using the following keys: barcode, location, department, branch, status, * returndate, reservations, signature, resinfo, url * * Dates will be returned in ISO-8601 format (yyyy-MM-dd). If you supply an invalid key, an * {@link IllegalArgumentException} will be thrown. * * This method is used to simplify refactoring of old APIs from the Map<String, String> data * structure to this class. If you are creating a new API, you probably don't need to use it. * * @param key one of the keys mentioned above *//*from w ww . j av a2 s .c o m*/ public String get(String key) { switch (key) { case "barcode": return getBarcode(); case "location": return getLocation(); case "department": return getDepartment(); case "branch": return getBranch(); case "status": return getStatus(); case "returndate": return ISODateTimeFormat.date().print(getReturnDate()); case "reservations": return getReservations(); case "signature": return getShelfmark(); case "resinfo": return getResInfo(); case "url": return getUrl(); default: throw new IllegalArgumentException("key unknown"); } }
From source file:de.iteratec.iteraplan.presentation.dialog.History.HistoryController.java
License:Open Source License
/** * URL Handler method that returns an HTML view of the history of one building block, narrowed down by provided criteria * @param bbId Building Block ID//from w w w .j av a2s .c o m * @param bbType Building Block type code, which can be decoded by {@link TypeOfBuildingBlock#fromInitialCapString(String)} * @param page The number of the page to return, depending on {@code pageSize}. Zero-based. May be {@code null}, in which case the default value 0 is used. * @param pageSize The number of history events on the returned page. -1 is interpreted as "everything". May be {@code null}, in which case the default value -1 is used. * @param dateFromStr The start date of the time range to filter history events for. This is expected to be in ISO date format (pattern yyyy-MM-dd)! * @param dateToStr The end date (inclusive) of the time range to filter history events for. This is expected to be in ISO date format (pattern yyyy-MM-dd)! */ @SuppressWarnings("boxing") @RequestMapping public ModelAndView localHistory(@RequestParam(value = "id", required = true) String bbId, @RequestParam(value = "buildingBlockType", required = true) String bbType, @RequestParam(value = "page", required = false) String page, @RequestParam(value = "pageSize", required = false) String pageSize, @RequestParam(value = "dateFrom", required = false) String dateFromStr, @RequestParam(value = "dateTo", required = false) String dateToStr) { ModelAndView modelAndView = new ModelAndView("history/local"); // Check if user may see history, and note so JSP can show a nice error. If not, return Boolean hasPermission = Boolean.valueOf(UserContext.getCurrentPerms().getUserHasFuncPermViewHistory()); modelAndView.addObject("isHasViewHistoryPermission", hasPermission); if (!hasPermission.booleanValue()) { return modelAndView; } int id = parseInt(bbId, -1); // Default to showing page 0 (first page), if unspecified int curPage = parseInt(page, 0); // current page must not be negative curPage = Math.max(curPage, 0); // Default -1 means infinite results Per Page int pageSizeInt = parseInt(pageSize, -1); // make sure it's not 0, /0 error later; and make all values < -1 turn into -1 if (pageSizeInt <= 0) { pageSizeInt = -1; } DateTimeFormatter isoDateFormatter = ISODateTimeFormat.date(); DateTime dateFrom = null; DateTime dateTo = null; if (StringUtils.isNotEmpty(dateFromStr)) { try { LocalDate date = LocalDate.parse(dateFromStr, isoDateFormatter); dateFrom = date.toDateTimeAtStartOfDay(); } catch (IllegalArgumentException ex) { // invalid date format, ignore } } if (StringUtils.isNotEmpty(dateToStr)) { try { // assumption: we parsed from a date with no time which gave us the beginning of that day, but // we want to include the whole day, so add 1 day LocalDate date = LocalDate.parse(dateToStr, isoDateFormatter).plusDays(1); dateTo = date.toDateTimeAtStartOfDay(); } catch (IllegalArgumentException ex) { // invalid date format, ignore } } HistoryResultsPage resultsPage; try { resultsPage = historyService.getLocalHistoryPage(getClassFromTypeString(bbType), id, curPage, pageSizeInt, dateFrom, dateTo); } catch (Exception e) { throw new IteraplanTechnicalException(IteraplanErrorMessages.HISTORY_RETRIEVAL_GENERAL_ERROR, e); } assert resultsPage != null; modelAndView.addObject("resultsPage", resultsPage); modelAndView.addObject("isHistoryEnabled", Boolean.valueOf(historyService.isHistoryEnabled())); return modelAndView; }
From source file:di.uniba.it.tee2.util.TEEUtils.java
License:Open Source License
/** * @param oldDate/*w w w . j a v a 2 s. co m*/ * @return * @throws java.text.ParseException */ public static String normalizeTime(String oldDate) throws Exception { Date now = new Date(); if (oldDate.equals("PRESENT_REF")) { oldDate = new SimpleDateFormat("yyyy-MM-dd").format(now); } else if (oldDate.endsWith("FA")) { oldDate = oldDate.replace("FA", "09-23"); } else if (oldDate.endsWith("WI")) { oldDate = oldDate.replace("WI", "12-21"); } else if (oldDate.endsWith("SU")) { oldDate = oldDate.replace("SU", "06-20"); } else if (oldDate.endsWith("SP")) { oldDate = oldDate.replace("SP", "03-20"); } else if (oldDate.equals("PAST_REF") || (oldDate.endsWith("WE"))) { return ""; } else if (oldDate.equals("FUTURE_REF")) { return new SimpleDateFormat("yyyyMMdd").format(now); } DateTime oldD = DateTime.parse(oldDate); DateTimeFormatter OldDFmt = ISODateTimeFormat.date(); String str = OldDFmt.print(oldD); Date date = new SimpleDateFormat("yyyy-MM-dd").parse(str); String newDate = DateTools.dateToString(date, DateTools.Resolution.DAY); return newDate; }
From source file:dk.teachus.frontend.utils.Formatters.java
License:Apache License
public static DateTimeFormatter getFormatIsoDate() { return ISODateTimeFormat.date(); }
From source file:eu.itesla_project.mcla.forecast_errors.FEAHistoDBFacade.java
License:Mozilla Public License
protected String historicalDataQuery() { String query = "headers=true"; query += "&count=" + MAXRECORDSNUM; DateTimeFormatter dateFormatter = ISODateTimeFormat.date(); DateTime intervalStart = histoInterval.getStart(); DateTime intervalEnd = histoInterval.getEnd(); query += "&time=[" + intervalStart.toString(dateFormatter) + "," + intervalEnd.toString(dateFormatter) + "]"; switch (timeHorizon) { case DACF:/* w w w. j ava2s. co m*/ query += "&horizon=" + timeHorizon.getName(); break; default: throw new AssertionError(); } if (timeHorizon.getForecastTime() >= 0) query += "&forecast=" + timeHorizon.getForecastTime(); query += "&cols=datetime,horizon,forecastTime"; for (String generatorId : generatorsIds) { query += "," + generatorId + "_P" + "," + generatorId + "_Q"; } for (String loadId : loadsIds) { query += "," + loadId + "_P" + "," + loadId + "_Q"; } return query; }
From source file:google.registry.tools.params.LocalDateParameter.java
License:Open Source License
@Override public LocalDate convert(String value) { return LocalDate.parse(value, ISODateTimeFormat.date()); }
From source file:io.apiman.manager.api.rest.impl.OrganizationResourceImpl.java
License:Apache License
/** * Parses a query param representing a date into an actual date object. * @param dateStr// w w w. j ava2 s .c om * @param defaultDate * @param floor */ private static DateTime parseDate(String dateStr, DateTime defaultDate, boolean floor) { if ("now".equals(dateStr)) { //$NON-NLS-1$ return DateTime.now(); } if (dateStr.length() == 10) { DateTime parsed = ISODateTimeFormat.date().withZoneUTC().parseDateTime(dateStr); // If what we want is the floor, then just return it. But if we want the // ceiling of the date, then we need to set the right params. if (!floor) { parsed = parsed.plusDays(1).minusMillis(1); } return parsed; } if (dateStr.length() == 20) { return ISODateTimeFormat.dateTimeNoMillis().withZoneUTC().parseDateTime(dateStr); } if (dateStr.length() == 24) { return ISODateTimeFormat.dateTime().withZoneUTC().parseDateTime(dateStr); } return defaultDate; }
From source file:io.konig.data.app.common.ExtentContainer.java
License:Apache License
public boolean validateQueryParam(String key, String value, URI datatype) throws DataAppException { try {//from w w w . ja va2 s . c om if (XMLSchema.DATE.equals(datatype)) { DateTime localTime = new DateTime(value).toDateTime(DateTimeZone.UTC); localTime.toString(ISODateTimeFormat.date()); return true; } else if (XMLSchema.STRING.equals(datatype)) { if (VIEW.equals(key) && FusionCharts.MAP_MEDIA_TYPE.equals(value)) { return true; } else if (VIEW.equals(key) && FusionCharts.MSLINE_MEDIA_TYPE.equals(value)) { return true; } else if (VIEW.equals(key) && FusionCharts.BAR_MEDIA_TYPE.equals(value)) { return true; } else if (VIEW.equals(key) && FusionCharts.PIE_MEDIA_TYPE.equals(value)) { return true; } else if (AGGREGATE.equals(key)) { AggregateAs.valueOf(value); return true; } else if (XSORT.equals(key) || YSORT.equals(key)) { SortAs.valueOf(value); return true; } } else if (XMLSchema.LONG.equals(datatype)) { Long.parseLong(value); return true; } throw new DataAppException("Invalid Input", 400); } catch (Exception ex) { throw new DataAppException("Invalid Input", 400); } }
From source file:io.prestosql.operator.scalar.DateTimeFunctions.java
License:Apache License
@ScalarFunction("to_iso8601") @SqlType("varchar(16)") // Standard format is YYYY-MM-DD, which gives up to 10 characters. // However extended notation with format (Y)+-MM-DD is also acceptable and as the maximum year // represented by 64bits timestamp is ~584944387 it may require up to 16 characters to represent a date. public static Slice toISO8601FromDate(ConnectorSession session, @SqlType(StandardTypes.DATE) long date) { DateTimeFormatter formatter = ISODateTimeFormat.date().withChronology(UTC_CHRONOLOGY); return utf8Slice(formatter.print(DAYS.toMillis(date))); }