List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:net.rrm.ehour.util.DateUtil.java
License:Open Source License
/** * Get week number for date but compensate with configured first day of week. * Week officially starts on monday but when it's configured to start on sunday we have to compensate * because the day falls in the previous week. *//*from w w w.j a va2s .c o m*/ public static int getWeekNumberForDate(Date date, int configuredFirstDayOfWeek) { DateTime dateTime = new DateTime(date); return configuredFirstDayOfWeek == Calendar.SUNDAY ? dateTime.plusDays(1).getWeekOfWeekyear() : dateTime.getWeekOfWeekyear(); }
From source file:net.sf.jacclog.service.analyzer.commands.internal.AnalyzeLogEntriesShellCommand.java
License:Apache License
private void analyzeEntries() { if (service != null) { final DateTimeFormatter format = DateTimeFormat.forPattern("yyyyMMdd"); final DateTime from = format.parseDateTime(this.from); final DateTime to = (this.to != null) ? format.parseDateTime(this.to) : from.plusDays(1); final Interval interval = new Interval(from, to); final Period period = interval.toPeriod(); final StringBuffer buffer = new StringBuffer(); buffer.append("Analyse the log entries from '"); buffer.append(from.toString()).append('\''); buffer.append(" to '").append(to); // print the period final String space = " "; buffer.append("'. The period includes "); final PeriodFormatter dateFormat = new PeriodFormatterBuilder().appendYears() .appendSuffix(" year", " years").appendSeparator(space).appendMonths() .appendSuffix(" month", " months").appendSeparator(space).appendWeeks() .appendSuffix(" week", " weeks").appendSeparator(space).appendDays() .appendSuffix(" day", " days").appendSeparator(space).appendHours() .appendSuffix(" hour", " hours").appendSeparator(space).appendMinutes() .appendSuffix(" minute", " minutes").appendSeparator(space).toFormatter(); dateFormat.printTo(buffer, period); buffer.append('.'); System.out.println(buffer.toString()); final long maxResults = service.count(interval); if (maxResults > 0) { int maxCount = 0; if (proceed(maxResults)) { final long startTime = System.currentTimeMillis(); final LogEntryAnalysisResult result = analyzerService.analyze(interval).toResult(); final Map<UserAgentInfo, AtomicInteger> stats = result.getUserAgentInfos(); System.out.println("User agent information count: " + stats.size()); String name;//from ww w .ja v a 2s. co m String osName; int count; for (final Entry<UserAgentInfo, AtomicInteger> entry : stats.entrySet()) { name = entry.getKey().getName(); osName = entry.getKey().getOsName(); count = entry.getValue().get(); maxCount += count; System.out.println(name + " (" + osName + ") \t" + count); } System.out.println("Sum: " + maxCount); final long elapsedTime = System.currentTimeMillis() - startTime; final Period p = new Period(elapsedTime); System.out.println("Total processing time: " + p.toString(FORMATTER)); } } else { System.out.println("There is nothing to analyze."); } } }
From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java
License:Open Source License
/** * Returns a date a number of workdays away. Saturday and Sundays are not considered working days. *//*from w w w. ja va 2 s. com*/ @Function("WORKDAY") @FunctionParameters({ @FunctionParameter("dateObject"), @FunctionParameter("workdays") }) public Date WORKDAY(Object dateObject, Integer workdays) { Date convertedDate = convertDateObject(dateObject); if (convertedDate == null) { logCannotConvertToDate(); return null; } else { DateTime cursorDT = new DateTime(convertedDate); int remainingDays = workdays; while (remainingDays > 0) { int dayOfWeek = cursorDT.getDayOfWeek(); if (!(dayOfWeek == DateTimeConstants.SATURDAY || dayOfWeek == DateTimeConstants.SUNDAY)) { // Decrement remaining days only when it is not Saturday or Sunday remainingDays--; } cursorDT = dayOfWeek == DateTimeConstants.FRIDAY ? cursorDT.plusDays(3) : cursorDT.plusDays(1); } return cursorDT.toDate(); } }
From source file:net.sf.jasperreports.functions.standard.DateTimeFunctions.java
License:Open Source License
/** * Returns the number of working days between two dates (inclusive). Saturday and Sunday are not considered working days. *///from w ww. j av a 2s . c o m @Function("NETWORKDAYS") @FunctionParameters({ @FunctionParameter("startDate"), @FunctionParameter("endDate") }) public Integer NETWORKDAYS(Object startDate, Object endDate) { Date startDateObj = convertDateObject(startDate); if (startDateObj == null) { logCannotConvertToDate(); return null; } Date endDateObj = convertDateObject(endDate); if (endDateObj == null) { logCannotConvertToDate(); return null; } else { DateTime cursorDateTime = new DateTime(startDateObj); DateTime endDateTime = new DateTime(endDateObj); int workingDays = 0; if (cursorDateTime.isAfter(endDateTime)) { // Swap data information DateTime tmp = cursorDateTime; cursorDateTime = endDateTime; endDateTime = tmp; } while (Days.daysBetween(cursorDateTime, endDateTime).getDays() > 0) { int dayOfWeek = cursorDateTime.getDayOfWeek(); if (!(dayOfWeek == DateTimeConstants.SATURDAY || dayOfWeek == DateTimeConstants.SUNDAY)) { workingDays++; } cursorDateTime = cursorDateTime.plusDays(1); } return workingDays; } }
From source file:net.sourceforge.fenixedu.domain.Person.java
License:Open Source License
public boolean getCanValidateContacts() { final DateTime now = new DateTime(); final DateTime requestDate = getLastValidationRequestDate(); if (requestDate == null || getNumberOfValidationRequests() == null) { return true; }/*from w w w . java 2s . com*/ final DateTime plus30 = requestDate.plusDays(30); if (now.isAfter(plus30) || now.isEqual(plus30)) { setNumberOfValidationRequests(0); } return getNumberOfValidationRequests() <= MAX_VALIDATION_REQUESTS; }
From source file:net.sourceforge.fenixedu.domain.vigilancy.VigilantWrapper.java
License:Open Source License
public UnavailableTypes getWhyIsUnavailabeFor(WrittenEvaluation writtenEvaluation) { DateTime begin = writtenEvaluation.getBeginningDateTime(); DateTime end = writtenEvaluation.getEndDateTime(); if (!this.isAvailableOnDate(begin, end)) { return UnavailableTypes.UNAVAILABLE_PERIOD; }/* w w w. j a va 2s .c om*/ if (!this.isAvailableInCampus(writtenEvaluation.getCampus())) { return UnavailableTypes.NOT_AVAILABLE_ON_CAMPUS; } if (!this.hasNoEvaluationsOnDate(begin, end)) { return UnavailableTypes.ALREADY_CONVOKED_FOR_ANOTHER_EVALUATION; } Teacher teacher = this.getPerson().getTeacher(); if (teacher != null) { Set<PersonContractSituation> validTeacherServiceExemptions = teacher .getValidTeacherServiceExemptions(new Interval(begin, end.plusDays(1))); if (!validTeacherServiceExemptions.isEmpty()) { return UnavailableTypes.SERVICE_EXEMPTION; } } if (teacher != null && teacher.hasLessons(begin, end)) { return UnavailableTypes.LESSON_AT_SAME_TIME; } Person person = this.getPerson().getIncompatibleVigilantPerson(); if (person != null) { Collection<Vigilancy> convokes = writtenEvaluation.getVigilanciesSet(); for (Vigilancy convoke : convokes) { if (convoke.getVigilantWrapper().getPerson().equals(person)) { return UnavailableTypes.INCOMPATIBLE_PERSON; } } } return UnavailableTypes.UNKNOWN; }
From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java
License:Open Source License
private void calculateFirstAndLastInstantInWeeklyMode(YearMonthDay begin) { if (begin == null) { throw new IllegalArgumentException(); }/*from w w w. j av a2 s . c om*/ DateTime beginDateTime = begin.toDateTimeAtMidnight(); beginDateTime = (beginDateTime.getDayOfWeek() != 1) ? beginDateTime.withDayOfWeek(1) : beginDateTime; setFirstInstant(beginDateTime); setLastInstant(beginDateTime.plusDays(6)); }
From source file:net.sourceforge.fenixedu.util.renderer.GanttDiagram.java
License:Open Source License
private void generateYearsViewMonthsViewAndDays() { DateTime firstMonthDateTime = getFirstInstant(); DateTime lastMontDateTime = getLastInstant(); if (firstMonthDateTime != null && lastMontDateTime != null) { while ((firstMonthDateTime.getYear() < lastMontDateTime.getYear()) || (firstMonthDateTime.getYear() == lastMontDateTime.getYear() && firstMonthDateTime.getDayOfYear() <= lastMontDateTime.getDayOfYear())) { getDays().add(firstMonthDateTime); YearMonthDay day = firstMonthDateTime.toYearMonthDay().withDayOfMonth(1); if (getMonthsView().containsKey(day)) { getMonthsView().put(day, getMonthsView().get(day) + 1); } else { getMonthsView().put(day, 1); }/*from www . j av a 2s. c o m*/ if (getYearsView().containsKey(Integer.valueOf(firstMonthDateTime.getYear()))) { getYearsView().put(Integer.valueOf(firstMonthDateTime.getYear()), getYearsView().get(Integer.valueOf(firstMonthDateTime.getYear())) + 1); } else { getYearsView().put(Integer.valueOf(firstMonthDateTime.getYear()), 1); } firstMonthDateTime = firstMonthDateTime.plusDays(1); } } }
From source file:net.sourceforge.fenixedu.webServices.jersey.api.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 = FenixConfigurationManager.getConfiguration().getFenixApiCanteenUrl(); try {//ww w . j a v 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:net.tourbook.device.garmin.GarminSAXHandler.java
License:Open Source License
public static void main(final String[] args) { // final String pattern = "w dd.MM.yyyy"; final String jodPattern = "ww xx "; //$NON-NLS-1$ final String jdkPattern = "ww yy"; //$NON-NLS-1$ final DateTimeFormatter jodaFormatter = DateTimeFormat.forPattern(jodPattern); final StringBuilder sbJdk = new StringBuilder(); final StringBuilder sbJoda = new StringBuilder(); final Locale[] locales = Locale.getAvailableLocales(); for (int i = 0; i < locales.length; i++) { final Locale locale = locales[i]; final String language = locale.getLanguage(); final String country = locale.getCountry(); final String locale_name = locale.getDisplayName(); if ((i == 120 || i == 132) == false) { continue; }//from w w w .j a va 2 s . co m final SimpleDateFormat jdkFormatter = new SimpleDateFormat(jdkPattern, locale); final Calendar calendar = GregorianCalendar.getInstance(locale); System.out.println(); System.out.println(i + ": " + language + ", " + country + ", " + locale_name); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ for (int year = 2005; year < 2011; year++) { sbJoda.append(year + ": "); //$NON-NLS-1$ sbJdk.append(year + ": "); //$NON-NLS-1$ int days = 0; final DateTime dt = new DateTime(year, 12, 22, 8, 0, 0, 0); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); sbJoda.append(" "); //$NON-NLS-1$ sbJdk.append(" "); //$NON-NLS-1$ formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); formatDT(jodaFormatter, jdkFormatter, sbJdk, sbJoda, dt.plusDays(days++), calendar); System.out.println(sbJoda.toString()); System.out.println(sbJdk.toString()); System.out.println(); sbJoda.setLength(0); sbJdk.setLength(0); } } }