List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:jtodo.domain.Task.java
License:Open Source License
/** * Set new DateTime as the Deadline time from a string input. * * @param dateTime DateTime as a String// w w w . j ava2s .com * * @see IllegalArgumentException if the input could not be parsed */ public void setDeadline(String dateTime) throws IllegalArgumentException { org.joda.time.format.DateTimeFormatter formatter; formatter = DateTimeFormat.forPattern("dd.MM.YYYY HH:mm"); this.deadline.setActive(true); // forced active this.deadline.setDateTime(formatter.parseDateTime(dateTime)); }
From source file:logbook.LogBookCore.java
/** * This method is used to add two integers. This is * a the simplest form of a class method, just to * show the usage of various javadoc Tags. * @param ha Home Address String//from w w w . j ava2s . c om * @param hal Other Home Address List ArrayList<String> * @param wa Work Address String * @param wal Other Work Address List ArrayList<String> * @param cal Client Address List ArrayList<String> * @param StartAtAny Start At Any Bool * @param WorkOnWeekends WorkOnWeekends Bool * @param startDate Start Date String * @param endDate End Date String * @param startODO startODO int * @param endODO endODO int * @param percentClaim percentClaim int * @param groupCount Cluster Count int * @param complexMode Group Mode : DIST|HOPS|DISTHOPS String * @return LogGenerator This returns sum of numA and numB. */ public static ArrayList<LogRecord> GetLogBook(String ha, ArrayList<String> hal, String wa, ArrayList<String> wal, ArrayList<String> cal, boolean StartAtAny, boolean WorkOnWeekends, String startDate, String endDate, int startODO, int endODO, float percentClaim, int groupCount, String complexMode) { ArrayList<Destination> WorkAddresses = new ArrayList(); ArrayList<Destination> HomeAddresses = new ArrayList(); Destination home = new Destination(ha, false, true, false); Destination workHQ = new Destination(wa, false, false, true); for (String h : hal) { System.out.println(" H : " + h); HomeAddresses.add(new Destination(h, false, true, false)); } for (String s : wal) { System.out.println(" W : " + s); WorkAddresses.add(new Destination(s, false, false, true)); } for (String c : cal) { System.out.println(" C : " + c); WorkAddresses.add(new Destination(c, true, false, false)); } ui = new UserInput(home, workHQ, WorkAddresses, HomeAddresses, StartAtAny); repo = ui.DistinctRoutes(50); repo.UpdateRouteDistances(); repo.print(); System.out.println("Net Distinct Routes : " + repo.GetSize()); //repo.AllocateRandomFrequencies(); repo = ui.ProfileRouteRepository(repo, groupCount); ///////////////////////////////////////////////////////////////////////////// UserLimitations restr = new UserLimitations(WorkOnWeekends); DateTimeFormatter dstrFmt = DateTimeFormat.forPattern("dd-MMM-yyyy"); DateTime tempDate; DayRoute dr; int routeRef; // for(int i=0;i<this.jTable2.getModel().getRowCount();i++) // { // tempDate = dstrFmt.parseDateTime(String.valueOf(this.jTable2.getModel().getValueAt(i, 0))); // routeRef = Integer.parseInt(this.jTable2.getModel().getValueAt(i,1).toString()); // dr = repo.GetRoute(routeRef-1); // LogRecord lr = new LogRecord(dr,tempDate); // restr.AddRecord(lr); // } DateTime startOn = dstrFmt.parseDateTime(startDate); DateTime endOn = dstrFmt.parseDateTime(endDate); int countIncrement = 0; boolean upd = false; int setIncr = -10; double maxP = 0.0; ArrayList<Double> loadingList = new ArrayList(); if (percentClaim > 0) { loadingList.add(50.0); loadingList.add(80.0); loadingList.add(100.0); } // else // { // // double RegionValue = 0.0; // for(int i=0;i<groupCount;i++) // { // RegionValue += Double.parseDouble(this.jTable4.getModel().getValueAt(i, 1).toString()); // loadingList.add(RegionValue); // } // } ArrayList<Double> itr = loadingList; boolean loopBrk = false; ArrayList<LogGenerator> iterateThrough = new ArrayList<LogGenerator>(); int maxIndex = 0; for (int i = 0; i < 40; i++) { if (!loopBrk) { // upd = false; // for(Double d : itr) // { // if(d < 100 && upd == false && d+setIncr >= 0 && itr.indexOf(d) >= countIncrement) // { // itr.set(itr.indexOf(d), d + setIncr); // upd = true; // countIncrement = itr.indexOf(d); // } // // if( d == 0 && upd == false) // { // setIncr = 10; // countIncrement++; // } // // } if (itr.get(countIncrement) >= 10 && countIncrement < itr.size() - 1) { itr.set(countIncrement, itr.get(countIncrement) - 10); } else { if (countIncrement < itr.size() - 1) { countIncrement++; } //itr.set(countIncrement, itr.get(countIncrement)-10); } // print(itr); repo.SetGroupLoading(itr); lg = new LogGenerator(repo, startOn, endOn, restr, complexMode); lg.Allocate(); ArrayList<LogRecord> result = lg.GetRecords(); int totalRecords = result.size(); double TotalDeductable = 0.0, TotalDistance = 0.0; for (LogRecord l : result) { TotalDistance += Math.round(l.GetDistance()); TotalDeductable += Math.round(l.GetDeductableDistance()); } System.out.println(String.valueOf(TotalDeductable) + " of Total : " + String.valueOf(TotalDistance) + " : Percentage = " + String.valueOf(TotalDeductable * 100 / TotalDistance)); if (maxP < TotalDeductable * 100 / TotalDistance) { maxP = TotalDeductable * 100 / TotalDistance; iterateThrough.add(lg); maxIndex = iterateThrough.indexOf(lg); } } if (maxP >= percentClaim) { loopBrk = true; } } return SetPersonalRecords(lg.GetRecords(), startODO, endODO); }
From source file:microsoft.exchange.webservices.data.util.DateTimeParser.java
License:Open Source License
private Date parseInternal(String value, boolean dateOnly) { String originalValue = value; if (value == null || value.isEmpty()) { return null; } else {/*from ww w . j av a2s . c o m*/ if (value.endsWith("z")) { // This seems to be an edge case. Let's uppercase the Z to be sure. value = value.substring(0, value.length() - 1) + "Z"; } DateTimeFormatter[] formats = dateOnly ? dateFormats : dateTimeFormats; for (DateTimeFormatter format : formats) { try { return format.parseDateTime(value).toDate(); } catch (IllegalArgumentException e) { // Ignore and try the next pattern. } } } throw new IllegalArgumentException( String.format("Date String %s not in valid UTC/local format", originalValue)); }
From source file:microsoft.exchange.webservices.data.util.DateTimeUtils.java
License:Open Source License
private static Date parseInternal(String value, boolean dateOnly) { String originalValue = value; if (StringUtils.isEmpty(value)) { return null; } else {/* ww w.jav a 2 s . co m*/ if (value.endsWith("z")) { // This seems to be an edge case. Let's uppercase the Z to be sure. value = value.substring(0, value.length() - 1) + "Z"; } final DateTimeFormatter[] formats = dateOnly ? DATE_FORMATS : DATE_TIME_FORMATS; for (final DateTimeFormatter format : formats) { try { return format.parseDateTime(value).toDate(); } catch (IllegalArgumentException e) { // Ignore and try the next pattern. } } } throw new IllegalArgumentException( String.format("Date String %s not in valid UTC/local format", originalValue)); }
From source file:name.martingeisse.admin.application.converter.DateTimeConverter.java
License:Open Source License
@Override public DateTime convertToObject(String value, Locale locale) { try {//from www . j a va 2 s. c o m DateTimeFormatter formatter = getFormatter(locale); return formatter.parseDateTime(value); } catch (Exception e) { throw new ConversionException(e); } }
From source file:name.martingeisse.sql.config.CustomMysqlDateTimeType.java
License:Open Source License
@Override protected DateTime parse(final DateTimeFormatter formatter, final String value) { return formatter.parseDateTime(value); }
From source file:net.bashtech.geobot.MessageReplaceParser.java
License:Open Source License
public static String handleUntil(String message, String prefix, String suffix, PeriodFormatter formatter) { int commandStart = message.indexOf(prefix); int commandEnd = message.indexOf(suffix); if (commandStart + prefix.length() < commandEnd) { String replaced = message.substring(commandStart, commandEnd + suffix.length()); String dateStr = message.substring(commandStart + prefix.length(), commandEnd); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm"); String until;//from ww w . ja va 2s . c o m try { DateTime future = fmt.parseDateTime(dateStr); PeriodType pType = PeriodType.dayTime().withMillisRemoved().withSecondsRemoved(); Period period = new Period(new DateTime(), future, pType); until = period.toString(formatter); } catch (IllegalArgumentException e) { until = "Unknown date"; System.out.println(dateStr); e.printStackTrace(); } message = message.replace(replaced, until); } return message; }
From source file:net.crew_vre.events.rest.resources.EventResource.java
License:Open Source License
/** * Uploads a new event/*from w w w . j av a 2 s. c o m*/ * @param params The parameters of the event * @param graphId The id of the graph to add the event to * @return The response * @throws ParseException * @throws URISyntaxException */ @Path("local/{gid}") @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response uploadEvent(final MultivaluedMap<String, String> params, @PathParam("gid") String graphId) throws ParseException, URISyntaxException { Event event = new Event(); String graphUri = uriInfo.getRequestUri().toString(); if (!graphUri.endsWith("/")) { graphUri += "/"; } event.setGraph(graphUri); String uri = null; if (params.get("uri") == null) { uri = graphUri + System.currentTimeMillis() + (int) (Math.random() * 100000); } else { uri = params.remove("uri").get(0); if (!uri.startsWith(graphUri)) { return Response.status(Response.Status.CONFLICT).build(); } } event.setId(uri); if (params.get("title") != null) { event.setTitle(params.remove("title").get(0)); } if (params.get("description") != null) { event.setDescription(params.remove("description").get(0)); } DateTimeFormatter fmt = DateTimeFormat.forPattern(DATETIME_PATTERN); if (params.get("startDateTime") != null) { event.setStartDateTime(fmt.parseDateTime(params.remove("startDateTime").get(0))); } if (params.get("endDateTime") != null) { event.setEndDateTime(fmt.parseDateTime(params.remove("endDateTime").get(0))); } if (params.get("isPartOf") != null) { EventParent parent = new EventParent(); parent.setId(params.get("isPartOf").get(0)); Vector<EventParent> parents = new Vector<EventParent>(); parents.add(parent); event.setPartOf(parents); } File eventUploadDirectory = new File(eventUploadStoreDirectory, graphId); eventUploadDirectory.mkdirs(); Model eventModel = Utility.createModelFromEvent(event); File file = new File(eventUploadDirectory, event.getId().substring(graphUri.length()) + ".rdf"); try { eventModel.write(new FileOutputStream(file)); } catch (FileNotFoundException e) { e.printStackTrace(); return Response.status(Response.Status.CONFLICT).build(); } try { List<HarvestSourceAuthority> authorities = harvesterSourceManagementFacade.defaultPermissions(); for (HarvestSourceAuthority auth : authorities) { auth.setGraph(graphUri); } harvesterSourceManagementFacade.addSource(graphUri, "Local Events", "Events Uploaded by the Recorder", false); harvesterSourceManagementFacade.updatePermissions(graphUri, authorities); harvesterSourceManagementFacade.harvestSource(graphUri); } catch (Throwable t) { t.printStackTrace(); return Response.status(Response.Status.FORBIDDEN).build(); } return Response.created(new URI(event.getId())).build(); }
From source file:net.es.enos.esnet.OSCARSTopologyPublisher.java
License:Open Source License
public OSCARSTopologyPublisher(String date) { DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy"); this.date = formatter.parseDateTime(date); }
From source file:net.ftlines.wicket.fullcalendar.callback.ViewDisplayCallback.java
License:Apache License
@Override protected void respond(final AjaxRequestTarget target) { final Request r = target.getPage().getRequest(); final ViewType type = ViewType.forCode(r.getRequestParameters().getParameterValue("view").toString()); final DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withZone(PFUserContext.getDateTimeZone()); final DateMidnight start = fmt.parseDateTime(r.getRequestParameters().getParameterValue("start").toString()) .toDateMidnight();// w w w.ja v a2 s .c o m final DateMidnight end = fmt.parseDateTime(r.getRequestParameters().getParameterValue("end").toString()) .toDateMidnight(); final DateMidnight visibleStart = fmt .parseDateTime(r.getRequestParameters().getParameterValue("visibleStart").toString()) .toDateMidnight(); final DateMidnight visibleEnd = fmt .parseDateTime(r.getRequestParameters().getParameterValue("visibleEnd").toString()) .toDateMidnight(); final View view = new View(type, start, end, visibleStart, visibleEnd); final CalendarResponse response = new CalendarResponse(getCalendar(), target); onViewDisplayed(view, response); }