List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:com.github.pockethub.util.TimeUtils.java
License:Apache License
public static Date stringToDate(String value) { DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateTime t = format.parseDateTime(value); return t.toDate(); }
From source file:com.github.thorqin.toolkit.utility.StringUtils.java
public static DateTime parseISO8601(String dateTime) { DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser(); return formatter.parseDateTime(dateTime); }
From source file:com.google.cloud.dataflow.examples.opinionanalysis.IndexerPipelineUtils.java
License:Apache License
public static DateTime parseDateString(DateTimeFormatter formatter, String s) { DateTime result = null;//from www .j a va 2 s . com try { result = formatter.parseDateTime(s); } catch (Exception e) { result = null; } return result; }
From source file:com.google.cloud.tools.intellij.debugger.BreakpointUtil.java
License:Apache License
/** * Parses a date time string to a {@link java.util.Date}. * * <p>This method is currently only needed because the CDB service is returning ambiguous DateTime * formats. https://github.com/GoogleCloudPlatform/google-cloud-intellij/issues/917. * When the root cause is fixed, we should be able to replace this method with direct invocations * to {@code DateTimeFormatter.parse()} or {@code java.time.ZonedDateTime.parse()}, if we're * using Java8.// w w w . ja v a2s .com */ @Nullable public static Date parseDateTime(@Nullable String dateString) { if (dateString == null) { return null; } for (DateTimeFormatter formatter : FORMATS) { try { return formatter.parseDateTime(dateString).toDate(); } catch (IllegalArgumentException iae) { // Do nothing, try the next parser. } } LOG.error("datetime " + dateString + "couldn't be parsed by any formats."); return null; }
From source file:com.google.samples.apps.iosched.explore.ExploreSessionsFragment.java
License:Open Source License
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { DateTimeFormatter formatter = DateTimeFormat.forPattern("E dd.MMMM yyyy"); DateTime dateToUse = null;/* w ww . j a v a2 s . c o m*/ DateTime startDate = null; DateTime endDate = null; if (mSessionDate != null) { dateToUse = formatter.parseDateTime(mSessionDate); startDate = dateToUse.plusHours(0); endDate = dateToUse.plusHours(23); } switch (id) { case ExploreSessionsQuery.NORMAL_TOKEN: return new CursorLoader(getActivity(), mCurrentUri, ExploreSessionsQuery.NORMAL_PROJECTION, mSessionDate != null ? ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION : null, mSessionDate != null ? new String[] { startDate.getMillis() + "", endDate.getMillis() + "" } : null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); case ExploreSessionsQuery.SEARCH_TOKEN: return new CursorLoader(getActivity(), mCurrentUri, ExploreSessionsQuery.SEARCH_PROJECTION, mSessionDate != null ? ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION : null, mSessionDate != null ? new String[] { startDate.getMillis() + "", endDate.getMillis() + "" } : null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); case TAG_METADATA_TOKEN: return TagMetadata.createCursorLoader(getActivity()); default: return null; } }
From source file:com.google.sampling.experiential.server.migration.MigrationFrontendServlet.java
License:Open Source License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json;charset=UTF-8"); User user = AuthUtil.getWhoFromLogin(); if (user == null) { AuthUtil.redirectUserToLogin(req, resp); } else if (AuthUtil.isUserAdmin()) { String cursor = null;//from w ww.jav a2s . c o m DateTime stDate = null; DateTime endDate = null; cursor = req.getParameter("cursor"); String jobName = req.getParameter("name"); String startTime = req.getParameter("startTime"); String endTime = req.getParameter("endTime"); try { DateTimeFormatter formatter = DateTimeFormat.forPattern(TimeUtil.DATE_TIME_WITH_NO_TZ); if (startTime != null && endTime != null) { stDate = formatter.parseDateTime(startTime); endDate = formatter.parseDateTime(endTime); } } catch (IllegalArgumentException e) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); } String jobId = sendMigrateRequestToBackend(req, jobName, cursor, stDate, endDate); String redirectUrl = null; // On dev local, when we kick off job from backend module - migration with correct port number, // the job status which is defined in default module is getting searched in migration module. // In other environments, the request gets routed through dispatch xml. if (EnvironmentUtil.isDevInstance()) { redirectUrl = "http://" + ModulesServiceFactory.getModulesService().getVersionHostname("default", null) + "/jobStatus?jobId=" + jobId; } else { redirectUrl = "/jobStatus?jobId=" + jobId; } resp.sendRedirect(redirectUrl); } else { resp.sendError(403); } }
From source file:com.gst.infrastructure.core.service.DateUtils.java
License:Apache License
public static LocalDate parseLocalDate(final String stringDate, final String pattern) { try {/*from www. jav a 2 s .c om*/ final DateTimeFormatter dateStringFormat = DateTimeFormat.forPattern(pattern); dateStringFormat.withZone(getDateTimeZoneOfTenant()); final DateTime dateTime = dateStringFormat.parseDateTime(stringDate); return dateTime.toLocalDate(); } catch (final IllegalArgumentException e) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.date.pattern", "The parameter date (" + stringDate + ") is invalid w.r.t. pattern " + pattern, "date", stringDate, pattern); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } }
From source file:com.gst.organisation.teller.api.CashierApiResource.java
License:Apache License
@GET @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON)//from ww w.j a v a 2 s . com public String getCashierData(@QueryParam("officeId") final Long officeId, @QueryParam("tellerId") final Long tellerId, @QueryParam("staffId") final Long staffId, @QueryParam("date") final String date) { final DateTimeFormatter dateFormatter = ISODateTimeFormat.basicDate(); final Date dateRestriction = (date != null ? dateFormatter.parseDateTime(date).toDate() : new Date()); final Collection<CashierData> allCashiers = this.readPlatformService.getCashierData(officeId, tellerId, staffId, dateRestriction); return this.jsonSerializer.serialize(allCashiers); }
From source file:com.gst.organisation.teller.api.TellerApiResource.java
License:Apache License
@GET @Path("{tellerId}/cashiers") @Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON }) @Produces(MediaType.APPLICATION_JSON)/* ww w . j av a2 s . c om*/ public String getCashierData(@PathParam("tellerId") final Long tellerId, @QueryParam("fromdate") final String fromDateStr, @QueryParam("todate") final String toDateStr) { final DateTimeFormatter dateFormatter = ISODateTimeFormat.basicDate(); final Date fromDate = (fromDateStr != null ? dateFormatter.parseDateTime(fromDateStr).toDate() : new Date()); final Date toDate = (toDateStr != null ? dateFormatter.parseDateTime(toDateStr).toDate() : new Date()); final TellerData teller = this.readPlatformService.findTeller(tellerId); final Collection<CashierData> cashiers = this.readPlatformService.getCashiersForTeller(tellerId, fromDate, toDate); CashiersForTeller cashiersForTeller = new CashiersForTeller(); cashiersForTeller.cashiers = cashiers; cashiersForTeller.tellerId = tellerId; cashiersForTeller.tellerName = teller.getName(); cashiersForTeller.officeId = teller.getOfficeId(); cashiersForTeller.officeName = teller.getOfficeName(); return this.jsonSerializer.serialize(cashiersForTeller); }
From source file:com.hack23.cia.service.component.agent.impl.riksdagen.workgenerator.RiksdagenDocumentListWorkGeneratorImpl.java
License:Apache License
@Override public void generateWorkOrders() { try {/*from w ww. jav a2 s. c o m*/ final int startYearForDocumentElement = getImportService().getStartYearForDocumentElement(); final org.joda.time.format.DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTime fromDateTime = fmt.parseDateTime(startYearForDocumentElement + "-01-01"); DateTime loadedWeekDate = fmt.parseDateTime(startYearForDocumentElement + "-01-01"); final DateTime toDate = new DateTime(); while (loadedWeekDate.isBefore(toDate)) { loadedWeekDate = loadedWeekDate.plusWeeks(1); sendMessage(loadDocumentWorkdestination, new LoadDocumentWork(fmt.print(fromDateTime), fmt.print(loadedWeekDate))); fromDateTime = fromDateTime.plusWeeks(1); } } catch (final Exception e) { LOGGER.warn("error generating work for loading documents", e); } }