List of usage examples for org.joda.time DateTime minusDays
public DateTime minusDays(int days)
From source file:org.xwiki.git.script.GitScriptService.java
License:Open Source License
/** * Count commits done by all authors in the passed repositories and since the passed date. * * @param sinceDays the number of days to look back in the past or look from the beginning if set to 0 * @param repositories the list of repositories in which to look for commits * @return the author commit activity/* w ww. j a va2 s.co m*/ * @since 5.3M2 */ public UserCommitActivity[] countAuthorCommits(int sinceDays, List<Repository> repositories) { Date date = null; if (sinceDays > 0) { // Compute today - since days DateTime now = new DateTime(); date = now.minusDays(sinceDays).toDate(); } return this.gitManager.countAuthorCommits(date, repositories); }
From source file:ph.fingra.statisticsweb.common.util.DateTimeUtil.java
License:Apache License
public static String[] getDashboardFromToWithPrev(String numType) { int num = Integer.parseInt(numType.substring(0, numType.length() - 1)); String type = numType.substring(numType.length() - 1).toLowerCase(); final DateTime now = DateTime.now(); final DateTime to = now.minusDays(1); final DateTime from = type.equals("w") ? to.minusDays(num * 7 - 1) : (type.equals("m") ? to.minusMonths(num) : to.withMonthOfYear(1).withDayOfMonth(1)); final DateTime prevTo = type.equals("y") ? to.minusYears(1) : from.minusDays(1); final DateTime prevFrom = type.equals("w") ? prevTo.minusDays(num * 7 - 1) : (type.equals("m") ? prevTo.minusMonths(num) : prevTo.withMonthOfYear(1).withDayOfMonth(1)); final DateTime yesterday = now.minusDays(1); final DateTime beforeYesterday = now.minusDays(2); String nowTime = ""; String prevTime = ""; // before or after 10 minutes if (now.getMinuteOfHour() < 10) { // before 10 minutes String nowTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); nowTime = (nowTemp.length() < 2) ? nowTemp = "0" + nowTemp : nowTemp; String prevTemp = nowTime.equals("00") ? "23" : String.valueOf(Integer.parseInt(nowTime) - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; System.out.println("10 " + now.getMinuteOfHour() + ""); } else { // after 10 minutes nowTime = (String.valueOf(now.getHourOfDay()).length() < 2) ? "0" + String.valueOf(now.getHourOfDay()) : String.valueOf(now.getHourOfDay()); String prevTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; System.out.println("10 " + now.getMinuteOfHour() + ""); }/* www . jav a 2 s . c o m*/ return new String[] { from.toString("yyyy-MM-dd"), to.toString("yyyy-MM-dd"), prevFrom.toString("yyyy-MM-dd"), prevTo.toString("yyyy-MM-dd"), yesterday.toString("yyyy-MM-dd"), beforeYesterday.toString("yyyy-MM-dd"), now.toString("yyyy-MM-dd"), nowTime, prevTime }; }
From source file:ph.fingra.statisticsweb.service.DashBoardServiceImpl.java
License:Apache License
@Override public App getTodaySectionInfo(DashBoardSearchParam param) { App app = getApp(param);/* ww w . j a v a2s . c om*/ DashBoard dashBoard = app.getDashBoard(); //TODAY SNAPSHOT dashBoard.setTodayNewUsers(dashBoardDao.getTodayNewUsers(param)); dashBoard.setTodayActiveUsers(dashBoardDao.getTodayActiveUsers(param)); dashBoard.setTodaySessions(dashBoardDao.getTodaySessions(param)); dashBoard.setTodaySessionLength(dashBoardDao.getTodaySessionLength(param)); dashBoard.setTodayPageViews(dashBoardDao.getTodayPageViews(param)); //Time of TODAY SNAPSHOT DateTime now = DateTime.now(); String nowTime = ""; String prevTime = ""; // Show statistics after 10 minutes if (now.getMinuteOfHour() < 10) { // Before 10 minutes String nowTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); nowTime = (nowTemp.length() < 2) ? nowTemp = "0" + nowTemp : nowTemp; String prevTemp = nowTime.equals("00") ? "23" : String.valueOf(Integer.parseInt(nowTime) - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; } else { // After 10 minutes nowTime = (String.valueOf(now.getHourOfDay()).length() < 2) ? "0" + String.valueOf(now.getHourOfDay()) : String.valueOf(now.getHourOfDay()); String prevTemp = now.equals("0") ? "23" : String.valueOf(now.getHourOfDay() - 1); prevTime = (prevTemp.length() < 2) ? prevTemp = "0" + prevTemp : prevTemp; } dashBoard.setTodayNowTime(nowTime); dashBoard.setTodayPrevTime(prevTime); dashBoard.setToday(now.toString("yyyy-MM-dd")); dashBoard.setYesterday(now.minusDays(1).toString("yyyy-MM-dd")); app.setDashBoard(dashBoard); return app; }
From source file:pl.edu.icm.coansys.statisticsgenerator.operationcomponents.DateRangesPartitioner.java
License:Open Source License
@Override public void setup(String... params) { List<Integer> numbers = new ArrayList<Integer>(); DateTime end = new DateTime(DateTimeZone.forTimeZone(timezone)).withMillisOfDay(0).plusDays(1); for (String param : params) { if (param.contains("=")) { int eqIndex = param.indexOf('='); String paramName = param.substring(0, eqIndex); String paramValue = param.substring(eqIndex + 1); if (paramName.equals("timezone")) { timezone = TimeZone.getTimeZone(paramValue); TimeZone.setDefault(timezone); } else if (paramName.equals("logsEnd")) { end = new DateTime(DatatypeConverter.parseTime(paramValue)).withMillisOfDay(0).plusDays(1); } else { throw new IllegalArgumentException("Unknown param name: " + paramName); }/*from ww w . jav a2s . co m*/ } else { numbers.add(Integer.parseInt(param)); } } Collections.sort(numbers); timeBuckets = new ArrayList<TimeBucket>(); for (Integer period : numbers) { DateTime start = end.minusDays(period).withMillisOfDay(0); timeBuckets.add(new TimeBucket(start, period.toString() + " days")); } timeBuckets.add(new TimeBucket("all")); }
From source file:Presentacion.frmreserva.java
private Boolean validarDisponibilidade() { DefaultTableModel modelo;//from www .j ava2 s .com DefaultTableModel modelo2; freserva freserva = new freserva(); vreserva vReserva = new vreserva(); freserva func = new freserva(); Boolean validacao = false; DateTime dtEntrada = new DateTime(dcfecha_ingresa.getDate().getTime()); DateTime dtSaida = new DateTime(dcfecha_salida.getDate().getTime()); dtEntrada = dtEntrada.plusDays(1); dtSaida = dtSaida.minusDays(1); vReserva.setIdhabitacion(Integer.valueOf(txtnumero.getText())); vReserva.setFecha_ingresa(new java.sql.Date(dtEntrada.getMillis())); vReserva.setFecha_salida(new java.sql.Date(dtSaida.getMillis())); if (!this.txtidreserva.getText().isEmpty()) { vReserva.setIdreserva(Integer.valueOf(this.txtidreserva.getText())); } modelo = freserva.validarDisponibilidade(vReserva); if (modelo.getRowCount() > 0) { tablalistado.setModel(modelo); ocultar_columnas(); validacao = true; } dtEntrada = dtEntrada.minusDays(1); dtSaida = dtSaida.plusDays(1); vReserva.setIdhabitacion(Integer.valueOf(txtnumero.getText())); vReserva.setFecha_ingresa(new java.sql.Date(dtEntrada.getMillis())); vReserva.setFecha_salida(new java.sql.Date(dtSaida.getMillis())); if (!this.txtidreserva.getText().isEmpty()) { vReserva.setIdreserva(Integer.valueOf(this.txtidreserva.getText())); } modelo2 = freserva.verificarReservaMesmaDataPorQuarto(vReserva); if (modelo2.getRowCount() > 0) { tablalistado.setModel(modelo2); ocultar_columnas(); validacao = true; } return validacao; }
From source file:pt.ist.fenixedu.integration.api.infra.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 = FenixEduIstIntegrationConfiguration.getConfiguration().getFenixApiCanteenUrl(); try {//from www .ja v a2 s . c om 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:pt.ist.fenixedu.integration.api.infra.FenixAPIFromExternalServer.java
License:Open Source License
public static String getCanteen(String daySearch, String canteenName) { String canteenUrl = FenixEduIstIntegrationConfiguration.getConfiguration().getFenixApiCanteenUrl() .concat("?name=" + canteenName); JsonObject canteenInfo = getInformation(canteenUrl); String lang = I18N.getLocale().toLanguageTag(); if (!canteenInfo.has(lang)) { return empty.toString(); }/*from w ww . j av a2 s . com*/ JsonArray jsonArrayWithLang = canteenInfo.getAsJsonObject().getAsJsonArray(lang); 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); } Interval validInterval = new Interval(dayToCompareStart, dayToCompareEnd); JsonArray jsonResult = new JsonArray(); for (JsonElement jObj : jsonArrayWithLang) { DateTime dateToCompare = DateTime.parse(((JsonObject) jObj).get("day").getAsString(), DateTimeFormat.forPattern(datePattern)); if (validInterval.contains(dateToCompare)) { jsonResult.add(jObj); } } return gson.toJson(jsonResult); }
From source file:pt.ist.fenixedu.quc.ui.spring.controller.gep.inquiries.CreateQucInquiriesController.java
License:Open Source License
@Atomic(mode = TxMode.WRITE) private void createInquiries(ExecutionSemester executionSemester) { //setting dates do the past, so that the inquiries only be active when set through interface DateTime begin = new DateTime(); int dayOfMonth = begin.get(DateTimeFieldType.dayOfMonth()); DateTime end = begin.minusDays(dayOfMonth); begin = end.minusDays(dayOfMonth);//w w w. ja v a2s . c o m // Curricular inquiry CurricularCourseInquiryTemplate newCourseInquiryTemplate = new CurricularCourseInquiryTemplate(begin, end); newCourseInquiryTemplate.setExecutionPeriod(executionSemester); CurricularCourseInquiryTemplate previousCourseInquiryTemplate = CurricularCourseInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousCourseInquiryTemplate.getInquiryBlocksSet()) { newCourseInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Teachers inquiry StudentTeacherInquiryTemplate newStudentTeacherInquiryTemplate = new StudentTeacherInquiryTemplate(begin, end); newStudentTeacherInquiryTemplate.setExecutionPeriod(executionSemester); StudentTeacherInquiryTemplate previousStudentTeacherInquiryTemplate = StudentTeacherInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousStudentTeacherInquiryTemplate.getInquiryBlocksSet()) { newStudentTeacherInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Delegates inquiry DelegateInquiryTemplate newDelegateInquiryTemplate = new DelegateInquiryTemplate(begin, end); newDelegateInquiryTemplate.setExecutionPeriod(executionSemester); DelegateInquiryTemplate previousDelegateInquiryTemplate = DelegateInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousDelegateInquiryTemplate.getInquiryBlocksSet()) { newDelegateInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Teachers inquiry TeacherInquiryTemplate newTeacherInquiryTemplate = new TeacherInquiryTemplate(begin, end); newTeacherInquiryTemplate.setExecutionPeriod(executionSemester); TeacherInquiryTemplate previousTeacherInquiryTemplate = TeacherInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousTeacherInquiryTemplate.getInquiryBlocksSet()) { newTeacherInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Regents inquiry RegentInquiryTemplate newRegentInquiryTemplate = new RegentInquiryTemplate(begin, end); newRegentInquiryTemplate.setExecutionPeriod(executionSemester); RegentInquiryTemplate previousRegentInquiryTemplate = RegentInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousRegentInquiryTemplate.getInquiryBlocksSet()) { newRegentInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Coordinators inquiry CoordinatorInquiryTemplate newCoordinatorInquiryTemplate = new CoordinatorInquiryTemplate(begin, end, true); newCoordinatorInquiryTemplate.setExecutionPeriod(executionSemester); CoordinatorInquiryTemplate previousCoordinatorInquiryTemplate = CoordinatorInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousCoordinatorInquiryTemplate.getInquiryBlocksSet()) { newCoordinatorInquiryTemplate.addInquiryBlocks(inquiryBlock); } // Results inquiry ResultsInquiryTemplate newResultsInquiryTemplate = new ResultsInquiryTemplate(); newResultsInquiryTemplate.setExecutionPeriod(executionSemester); ResultsInquiryTemplate previousResultsInquiryTemplate = ResultsInquiryTemplate .getTemplateByExecutionPeriod(executionSemester.getPreviousExecutionPeriod()); for (InquiryBlock inquiryBlock : previousResultsInquiryTemplate.getInquiryBlocksSet()) { newResultsInquiryTemplate.addInquiryBlocks(inquiryBlock); } }
From source file:rapture.common.USCalendar.java
License:Open Source License
public static DateTime getPreviousBusinessDay(final DateTime date) { DateTime prevDay = date; do {//from w w w. j ava 2 s .c o m prevDay = prevDay.minusDays(1); } while (!isBusinessDay(prevDay)); return prevDay; }
From source file:rapture.dp.invocable.ArchiveRepoStep.java
License:Open Source License
@Override public String invoke(CallingContext context) { List<String> docRepoNames = readListFromContext(context, DOC_REPO_NAMES); List<String> sysRepoNames = readListFromContext(context, SYS_REPO_NAMES); String versionLimitStr = Kernel.getDecision().getContextValue(context, getWorkerURI(), VERSION_LIMIT); String timeLimitStr = Kernel.getDecision().getContextValue(context, getWorkerURI(), TIME_LIMIT); if (StringUtils.isEmpty(versionLimitStr) && StringUtils.isEmpty(timeLimitStr)) { log.warn("No version limit or time limit is specified, nothing to archive"); return NEXT; }/*from ww w .j a va2 s . com*/ int versionLimit = StringUtils.isEmpty(versionLimitStr) ? Integer.MAX_VALUE : Integer.parseInt(versionLimitStr); long timeLimit = 0; if (!StringUtils.isEmpty(timeLimitStr)) { DateTime dateTime = DateTime.now(); int number = Integer.valueOf(timeLimitStr.substring(0, timeLimitStr.length() - 1)); char dateUnit = timeLimitStr.charAt(timeLimitStr.length() - 1); switch (dateUnit) { case 'M': dateTime = dateTime.minusMonths(number); break; case 'W': dateTime = dateTime.minusWeeks(number); break; case 'D': dateTime = dateTime.minusDays(number); break; default: throw RaptureExceptionFactory.create("Invalid date unit " + dateUnit); } timeLimit = dateTime.getMillis(); } boolean ensureVersionLimit = Boolean .parseBoolean(Kernel.getDecision().getContextValue(context, getWorkerURI(), ENSURE_VERSION_LIMIT)); log.info(String.format("Configured to archive %s doc repos and %s system repos.", docRepoNames.size(), sysRepoNames.size())); for (String repoName : docRepoNames) { log.info(String.format("About to archive doc repo %s", repoName)); Kernel.getDoc().archiveRepoDocs(context, repoName, versionLimit, timeLimit, ensureVersionLimit); } for (String repoName : sysRepoNames) { Repository repo = Kernel.INSTANCE.getRepo(repoName); if (repo == null) { log.info(String.format("Repo not found for name '%s'", repoName)); } else { if (repo.isVersioned() && repo instanceof NVersionedRepo) { log.info(String.format("About to archive sys repo %s", repoName)); ((NVersionedRepo) repo).archiveRepoVersions(repoName, versionLimit, timeLimit, ensureVersionLimit, context.getUser()); } else { log.info(String.format( "Sys repo %s is not of type NVersionedRepo, instead it is of type %s, skipping...", repoName, repo.getClass().getName())); } } } return NEXT; }