List of usage examples for org.joda.time DateTime withTime
public DateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
From source file:com.onboard.web.api.user.UserAPIController.java
License:Apache License
/** * ??bugs/* ww w .j a va2 s. c o m*/ * * @param companyId * @param userId * @param until * @return */ @RequestMapping(value = "/{companyId}/user/{userId}/completedBugs", method = RequestMethod.GET) @Interceptors({ CompanyMemberRequired.class, UserChecking.class }) @ResponseBody public Map<String, Object> viewUserCompletedBugs(@PathVariable int companyId, @PathVariable int userId, @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until) { Builder<String, Object> builder = ImmutableMap.builder(); DateTime dt = until == null ? new DateTime() : new DateTime(until); until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate(); List<Integer> projectList = getProjectListOfCurrentUser(companyId); TreeMap<Date, Map<Integer, List<Bug>>> map = bugService.getCompletedBugsGroupByDateByUser(companyId, userId, projectList, until, PER_PAGE); TreeMap<String, Map<Integer, List<BugDTO>>> mapDTO = makeUserCompletedBugsMapSerilizable(map); builder.put("completedBugs", mapDTO); Map<Integer, String> projectIdToName = getProjectIdAndNameByCompanyId(companyId); builder.put("projectsName", projectIdToName); boolean hasNext = false; if (map != null && map.size() > 0) { Date newUntil = new DateTime(map.firstKey()).withTime(0, 0, 0, 0).plusMillis(-1).toDate(); TreeMap<Date, Map<Integer, List<Bug>>> nextMap = bugService.getCompletedBugsGroupByDateByUser(companyId, userId, projectList, newUntil, PER_PAGE); hasNext = nextMap.size() > 0; builder.put("nextPage", dtf.print(new DateTime(newUntil))); } builder.put("hasNext", hasNext); return builder.build(); }
From source file:com.onboard.web.api.user.UserAPIController.java
License:Apache License
/** * ??steps// ww w .j ava2 s . com * * @param companyId * @param userId * @param until * @return */ @RequestMapping(value = "/{companyId}/user/{userId}/completedSteps", method = RequestMethod.GET) @Interceptors({ CompanyMemberRequired.class, UserChecking.class }) @ResponseBody public Map<String, Object> viewUserCompletedSteps(@PathVariable int companyId, @PathVariable int userId, @RequestParam(value = "until", required = false) @DateTimeFormat(iso = ISO.DATE) Date until) { Builder<String, Object> builder = ImmutableMap.builder(); DateTime dt = until == null ? new DateTime() : new DateTime(until); until = dt.withTime(0, 0, 0, 0).plusDays(1).plusMillis(-1).toDate(); List<Integer> projectList = getProjectListOfCurrentUser(companyId); TreeMap<Date, Map<Integer, List<Step>>> map = stepService.getCompletedStepsGroupByDateByUser(companyId, userId, projectList, until, PER_PAGE); TreeMap<String, Map<Integer, List<StepDTO>>> mapDTO = makeUserCompletedStepsMapSerilizable(map); builder.put("completedSteps", mapDTO); Map<Integer, String> projectIdToName = getProjectIdAndNameByCompanyId(companyId); builder.put("projectsName", projectIdToName); boolean hasNext = false; if (map != null && map.size() > 0) { Date newUntil = new DateTime(map.firstKey()).withTime(0, 0, 0, 0).plusMillis(-1).toDate(); TreeMap<Date, Map<Integer, List<Bug>>> nextMap = bugService.getCompletedBugsGroupByDateByUser(companyId, userId, projectList, newUntil, PER_PAGE); hasNext = nextMap.size() > 0; builder.put("nextPage", dtf.print(new DateTime(newUntil))); } builder.put("hasNext", hasNext); return builder.build(); }
From source file:course_generator.dialogs.frmTrackSettings.java
License:Open Source License
public boolean showDialog(CgSettings settings, TrackData track) { this.settings = settings; this.track = track; this.timezone = track.TrackTimeZone; this.summertime = track.TrackUseSumerTime; // Set field//ww w . ja va 2s .c o m tfTrackName.setText(this.track.CourseName); tfDescription.setText(this.track.Description); jMonthView.setSelectionDate(this.track.StartTime.toDate()); spinStartTimeModel.setValue(this.track.StartTime.toDate()); chkElevationEffect.setSelected(this.track.bElevEffect); chkNightEffect.setSelected(this.track.bNightCoeff); spinStartNightModel.setValue(this.track.StartNightTime.toDate()); spinEndNightModel.setValue(this.track.EndNightTime.toDate()); spinAscCoeff.setValue(this.track.NightCoeffAsc); spinDescCoeff.setValue(this.track.NightCoeffDesc); // End set field ok = false; //-- Update the display Refresh(); //-- Show the dialog setVisible(true); if (ok) { // Copy fields track.CourseName = tfTrackName.getText(); track.Description = tfDescription.getText(); DateTime std = new DateTime(jMonthView.getSelectionDate()); DateTime stt = new DateTime(spinStartTimeModel.getValue()); std = std.withTime(stt.getHourOfDay(), stt.getMinuteOfHour(), 0, 0); track.StartTime = std; track.bElevEffect = chkElevationEffect.isSelected(); track.bNightCoeff = chkNightEffect.isSelected(); track.StartNightTime = new DateTime(spinStartNightModel.getValue()); track.EndNightTime = new DateTime(spinEndNightModel.getValue()); track.NightCoeffAsc = spinAscCoeff.getValueAsDouble(); track.NightCoeffDesc = spinDescCoeff.getValueAsDouble(); track.TrackTimeZone = this.timezone; track.TrackUseSumerTime = this.summertime; } return ok; }
From source file:divconq.scheduler.limit.LimitHelper.java
License:Open Source License
public boolean isDateBlocked(DateTime tlast) { if (this.zone != null) tlast = new DateTime(tlast, this.zone); // if this time was ended at mid or before midnight then entire day is blocked if (this.isEnded(tlast.withTime(0, 0, 0, 0))) return true; // if this time was not started by the end of the then entire day is blocked if (!this.isStarted(tlast.withTime(23, 59, 59, 0))) return true; if (this.parent != null) return this.parent.isDateBlocked(tlast); CheckInfo ci = new CheckInfo(); ci.setWhen(tlast);//from w ww . ja va2s .c o m // if there are any months, those take precedence over other if (this.monthly.size() > 0) { for (MonthWindow ww : this.monthly) if (ww.appliesTo(ci)) return false; return true; } // if there are any weeks, those take precedence over daily else if (this.weekly.size() > 0) { // only need to find one window to return false for (WeekdayWindow ww : this.weekly) if (ww.appliesTo(ci)) return false; return true; } return this.dailyWindow.excludeAll(); }
From source file:divconq.util.TimeUtil.java
License:Open Source License
/** * try to supply a time for a date, if it fails it may be because of DST and that time (hour) is skipped on that date. * So try again to supply a time +1 hour to see if it helps. * /*from w w w . j av a2 s.co m*/ * @param d date to set time into * @param t time to set to * @return datetime with the supplied time (maybe +1 hour) or null */ static public DateTime withTime(DateTime d, LocalTime t) { try { return d.withTime(t.getHourOfDay(), t.getMinuteOfHour(), t.getSecondOfMinute(), t.getMillisOfSecond()); } catch (Exception x) { // TODO hour +1 is a hack, should work in USA/Canada - and probably lots of places - but maybe not everywhere if (TimeUtil.checkDST(d) == DaylightTransition.START) return d.withTime(t.getHourOfDay() + 1, t.getMinuteOfHour(), t.getSecondOfMinute(), t.getMillisOfSecond()); } return null; }
From source file:divconq.util.TimeUtil.java
License:Open Source License
/** * try to supply a time for a date, if it fails it may be because of DST and that time (hour) is skipped on that date. * So try again to supply a time +1 hour to see if it helps. * //from ww w . ja v a 2 s . c om * @param dt date to set time into * @param clt time to set to * @return datetime with the supplied time (maybe +1 hour) or null */ static public DateTime withTime(DateTime dt, CoreLocalTime clt) { return dt.withTime(clt.getHour(), clt.getMinute(), clt.getSecond(), clt.getMillSec()); }
From source file:divconq.util.TimeUtil.java
License:Open Source License
/** * try to get a date at midnight tomorrow, if no midnight due to DST then it may be 1am * /*from w ww. ja v a 2 s .com*/ * @param d date from which to calculate tomorrow * @return datetime of midnight, or closest to midnight, tomorrow */ static public DateTime nextDayAtMidnight(DateTime d) { return d.withTime(0, 0, 0, 0).plusDays(1); }
From source file:dk.dma.arcticweb.service.AppDataServiceBean.java
License:Apache License
private void createCarnivalLegendTestData() { logger.info("BEFORE CREATION - CARNIVAL LEGEND"); // Create vessel and user Vessel newVessel = new Vessel(); newVessel.getAisData().setName("CARNIVAL LEGEND"); newVessel.setMmsi(354237000L);/*from w ww .ja v a 2s . co m*/ newVessel.getAisData().setCallsign("H3VT"); newVessel.getAisData().setImoNo(9224726L); newVessel.setGrossTonnage(85942); newVessel = vesselDao.saveEntity(newVessel); SailorRole sailorRole = new SailorRole(); sailorRole.setVessel(newVessel); vesselDao.saveEntity(sailorRole); SecuredUser user = SecurityUtil.createUser("carnivalLegend", testPassword, testEmail, null); user.setRole(sailorRole); vesselDao.saveEntity(user); DateTime now = DateTime.now(DateTimeZone.UTC); newVessel.addVoyageEntry(new Voyage("Copenhagen", "55 67.61N", "12 56.83E", null, now.withTime(12, 57, 0, 0), 12, 300, true)); newVessel.addVoyageEntry( new Voyage("Nuuk", "64 10.4N", "051 43.5W", now.plusDays(10).withTime(7, 10, 0, 0), null)); for (Voyage v : newVessel.getSchedule()) { vesselDao.saveEntity(v); } }
From source file:dk.nsi.sdm4.ydelse.simulation.RandomSSR.java
License:Open Source License
private void setRandomTreatmentTime() { DateTime earliestTreatmentStart = new DateTime(2010, 12, 24, 0, 0, 0, 0); DateTime latestTreatmentStart = new DateTime(2011, 1, 31, 0, 0, 0, 0); DateTime treatet = testDataUtil.randomTime(earliestTreatmentStart, latestTreatmentStart); treatet = treatet.withTime(0, 0, 0, 0); treatmentInterval = new Interval(treatet, treatet.plusDays(1)); }
From source file:influent.server.data.PropertyMatchBuilder.java
License:MIT License
private void _parseTerm(String termName, String termValue, FL_PropertyDescriptors descriptors) { if (termValue == null || termValue.isEmpty()) return;/*from w w w.jav a2 s .co m*/ boolean isQuoted = false; boolean isRange = false; boolean isFuzzy = false; boolean isNegation = false; // Start a term builder FL_PropertyMatchDescriptor.Builder termBuilder = FL_PropertyMatchDescriptor.newBuilder(); boolean isFreeText = termName == null; if (!isFreeText) { // Negation if (termName.startsWith("-")) { termName = termName.substring(1); termBuilder.setInclude(false); isNegation = true; } } // Term Boosting Matcher boostMatch = boostPattern.matcher(termValue); if (boostMatch.find()) { String weightStr = boostMatch.group(1); try { Float weight = Float.valueOf(weightStr); termValue = termValue.substring(0, termValue.length() - weightStr.length() - 1); termBuilder.setWeight(weight); } catch (Exception e) { } } // Fuzzy matching Matcher similarityMatch = similarityPattern.matcher(termValue); if (similarityMatch.find()) { String similarityStr = similarityMatch.group(1); try { Float similarity = similarityStr == null ? 0.5f : Float.valueOf(similarityStr); termValue = similarityMatch.group(1); termBuilder.setSimilarity(similarity); isFuzzy = true; } catch (Exception e) { } } // Quotes and ranges Matcher quoteMatch = quotePattern.matcher(termValue); Matcher rangeMatch = rangePattern.matcher(termValue); String rangeStart = null; String rangeEnd = null; if (quoteMatch.find()) { termValue = quoteMatch.group(2); isQuoted = true; } if (rangeMatch.find()) { isRange = true; rangeStart = rangeMatch.group(1); rangeEnd = rangeMatch.group(2); } // Constraints if (!isFuzzy && (isQuoted || isFreeText || isRange || isNegation)) { if (_matchType == null || _matchType.equalsIgnoreCase("any")) { termBuilder.setConstraint(FL_Constraint.OPTIONAL_EQUALS); } else { termBuilder.setConstraint(FL_Constraint.REQUIRED_EQUALS); } } else { if (_matchType == null || _matchType.equalsIgnoreCase("any")) { termBuilder.setConstraint(FL_Constraint.FUZZY_PARTIAL_OPTIONAL); } else { termBuilder.setConstraint(FL_Constraint.FUZZY_REQUIRED); } } // Match properties to Search Descriptors for (FL_PropertyDescriptor pd : descriptors.getProperties()) { String propertyKey = pd.getKey(); if (propertyKey.equals(termName) || isFreeText) { for (FL_TypeMapping td : pd.getMemberOf()) { if (isFreeText && !FL_SearchableBy.FREE_TEXT.equals(pd.getSearchableBy())) { // If the term is freetext, but this isn't a freetext searchable property, continue; continue; } else if (_dataTypes != null && !_dataTypes.contains(td.getType())) { // If the term doesn't match the given datatypes, then continue; continue; } termBuilder.setKey(pd.getKey()); // Special handling for dates if (pd.getPropertyType() == FL_PropertyType.DATE) { // Dates become unfuzzied if (_matchType == null || _matchType.equalsIgnoreCase("any")) { termBuilder.setConstraint(FL_Constraint.OPTIONAL_EQUALS); } else { termBuilder.setConstraint(FL_Constraint.REQUIRED_EQUALS); } if (!isRange) { // Singleton dates become ranges across the whole 24h day DateTime date = new DateTime(termValue); rangeStart = dateFormatter.print(date.withTime(0, 0, 0, 0)); rangeEnd = dateFormatter.print(date.withTime(23, 59, 59, 59)); isRange = true; } else { if (!rangeStart.equals("*")) { DateTime startDate = new DateTime(rangeStart); rangeStart = dateFormatter.print(startDate.withTime(0, 0, 0, 0)); // From 0h on start date.. } if (!rangeEnd.equals("*")) { DateTime endDate = new DateTime(rangeEnd); rangeEnd = dateFormatter.print(endDate.minusMillis(3)); // .. to 23:59:59.997 exclusive of the end date (max SQL millisecond precision) } } } // Set the term value in the builder if (isRange) { termBuilder.setRange(FL_BoundedRange.newBuilder().setStart(rangeStart).setEnd(rangeEnd) .setInclusive(true).setType(pd.getPropertyType()).build()); } else { // freetext is comma/space delimited (as long as it's not quoted). Everything else is comma delimited. List<Object> values = new ArrayList<Object>(Arrays.asList( termValue.split(isFreeText && !isQuoted ? "(?<!\\\\)( |,)" : "(?<!\\\\),"))); if (pd.getKey().equals(FL_RequiredPropertyKey.FROM.name()) || pd.getKey().equals(FL_RequiredPropertyKey.TO.name()) || pd.getKey().equals(FL_RequiredPropertyKey.ENTITY.name()) || pd.getKey().equals(FL_RequiredPropertyKey.LINKED.name())) { values = processIds(values, td); } if (values.size() == 0) { // Stripped out all the values? Throw it out continue; } else if (values.size() == 1) { // Singletons termBuilder.setRange(FL_SingletonRange.newBuilder().setType(pd.getPropertyType()) .setValue(values.get(0)).build()); } else { // Lists termBuilder.setRange(FL_ListRange.newBuilder().setType(pd.getPropertyType()) .setValues(new ArrayList<Object>(values)).build()); } } if (isFreeText) { // Freetext, but not the correct type? if (!_typeCheckPropertyValue(pd, termBuilder.getRange())) { continue; } } termBuilder.setTypeMappings(Collections.singletonList(td)); List<FL_PropertyMatchDescriptor> termList = _descriptorMap.get(td.getType()); if (termList == null) { termList = new ArrayList<FL_PropertyMatchDescriptor>(); } termList.add(termBuilder.build()); _descriptorMap.put(td.getType(), termList); } } } }