List of usage examples for org.joda.time Period Period
private Period(int[] values, PeriodType type)
From source file:org.thelq.pircbotx.commands.Alarm.java
License:Open Source License
protected String calcDrift() { return FORMATTER_DRIFT.print(new Period(alarmDate, DateTime.now(DateTimeZone.UTC))); }
From source file:org.thelq.pircbotx.commands.NewYearsCommand.java
License:Open Source License
@Override public void onMessage(MessageEvent event) throws Exception { String[] commandParts = event.getMessage().split(" ", 2); if (commandParts.length != 2 || !ListenerUtils.isCommand(commandParts[0], "newyears")) return;/*from ww w .j a va2 s. c om*/ if (commandParts[1].equals("start")) start(); else if (commandParts[1].equals("year")) event.respond("Next year is " + NEW_YEAR); else if (commandParts[1].equals("next")) { ListenerUtils.incrimentCommands(event); String prefix = null; DateTime nextNewYear = null; if (waitingNewYear != null) { prefix = "Waiting for next New Years "; nextNewYear = waitingNewYear; } else { prefix = "Next New Years is "; nextNewYear = getNextNewYears(); if (nextNewYear == null) { event.respond("No more New Years :-("); return; } } NavigableSet<DateTimeZone> timezones = getNyTimes().get(nextNewYear); event.respond(prefix + "in " + Alarm.FORMATTER_REMAIN.print(new Period(getNow(), nextNewYear)) + "for " + getUTCOffset(timezones.first()) + " - " + getExtendedNames(timezones)); } }
From source file:org.wso2.carbon.apimgt.usage.client.impl.APIUsageStatisticsRestClientImpl.java
License:Open Source License
/** * This method is used to get the breakdown of the duration between 2 days/timestamps in terms of years, * months, days, hours, minutes and seconds * * @param fromDate Start timestamp of the duration * @param toDate End timestamp of the duration * @return A map containing the breakdown * @throws APIMgtUsageQueryServiceClientException when there is an error during date parsing *///from w ww. jav a 2 s . c om private Map<String, Integer> getDurationBreakdown(String fromDate, String toDate) throws APIMgtUsageQueryServiceClientException { Map<String, Integer> durationBreakdown = new HashMap<String, Integer>(); DateTimeFormatter formatter = DateTimeFormat .forPattern(APIUsageStatisticsClientConstants.TIMESTAMP_PATTERN); LocalDateTime startDate = LocalDateTime.parse(fromDate, formatter); LocalDateTime endDate = LocalDateTime.parse(toDate, formatter); Period period = new Period(startDate, endDate); int numOfYears = period.getYears(); int numOfMonths = period.getMonths(); int numOfWeeks = period.getWeeks(); int numOfDays = period.getDays(); if (numOfWeeks > 0) { numOfDays += numOfWeeks * 7; } int numOfHours = period.getHours(); int numOfMinutes = period.getMinutes(); int numOfSeconds = period.getSeconds(); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_YEARS, numOfYears); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MONTHS, numOfMonths); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_DAYS, numOfDays); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_WEEKS, numOfWeeks); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_HOURS, numOfHours); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_MINUTES, numOfMinutes); durationBreakdown.put(APIUsageStatisticsClientConstants.DURATION_SECONDS, numOfSeconds); return durationBreakdown; }
From source file:org.wso2.security.tools.advisorytool.builders.CustomerSecurityAdvisoryBuilder.java
License:Open Source License
/** * Creating a Version object with the required details from the released products list and * adding the given patch name as an applicable patch. * * @param productName// w w w.java 2 s . c o m * @param versionNumber * @param patchName * @return */ private Version buildAffectedVersion(String productName, String versionNumber, String patchName) { DateTime dateTime = new DateTime(); boolean hasAMatchingProduct = false; boolean hasAMatchingVersion = false; boolean hasAnApplicableVersion = false; List<Product> releasedProductList = ProductDataHolder.getInstance().getProductList(); Version affectedVersion = new Version(); for (Product releasedProduct : releasedProductList) { if (releasedProduct.getName().equals(productName)) { hasAMatchingProduct = true; for (Version releasedVersion : releasedProduct.getVersionList()) { if (releasedVersion.getVersionNumber().equals(versionNumber)) { hasAMatchingVersion = true; DateTime productDate = new DateTime(releasedVersion.getReleasedDate()); Period period = new Period(productDate, dateTime); //check if the product is within the supported period or whether it is deprecated. if ((period.getYears() < Configuration.getInstance().getPatchSupportPeriod()) && !releasedVersion.isDeprecated()) { hasAnApplicableVersion = true; affectedVersion.getPatchNamesList().add(patchName); affectedVersion.setVersionNumber(releasedVersion.getVersionNumber()); affectedVersion.setPublicSupported(releasedVersion.isPublicSupported()); affectedVersion.setPatchSupported(releasedVersion.isPatchSupported()); affectedVersion.setWumSupported(releasedVersion.isWumSupported()); affectedVersion.setReleasedDate(releasedVersion.getReleasedDate()); affectedVersion.setKernelVersionNumber(releasedVersion.getKernelVersionNumber()); affectedVersion.setPlatformVersionNumber(releasedVersion.getPlatformVersionNumber()); } break; } } break; } } if (!hasAMatchingVersion) { logger.warn("Unable to find the version " + versionNumber + " for the product " + productName + " in the Products list"); } if (!hasAMatchingProduct) { logger.warn("Unable to find the product " + productName + " in the Products list"); } if (hasAnApplicableVersion) { //if the released product list contains a version with the given details and // within the supported period. return affectedVersion; } else { return null; } }
From source file:org.yamj.common.tools.DateTimeTools.java
License:Open Source License
/** * Format the duration in milliseconds in the given format * * @param milliseconds/*from w ww . j av a 2s . c o m*/ * @param format * @return */ public static String formatDuration(long milliseconds, PeriodFormatter format) { Period period = new Period(milliseconds, PeriodType.time()); period = period.normalizedStandard(); return format.print(period); }
From source file:projectresurrection.Eve.java
public static void main(String args[]) { init();//from w ww. j a v a2 s . c o m listener = new Listener(); voice = new VoiceSynthesis(); clock = new Clock(Clock.BRAIN, Clock.UPDATE, (String) preferences.get("time zone")); gui = new GUI(GUI.DEFAULT); gui.start(GUI.DEFAULT); while (true) { if (!commands.isEmpty()) { String command = commands.poll(); prevCommands.add(command); switch (command) { case "what is the current weather": Clock.addCommand("kill"); List currentWeather = Weather.getCurrent(); sb = "The Current Tempurature is " + currentWeather.get(1) + " degrees fahrenheit and " + ((currentWeather.get(2).equals("Thunderstorm In Vicinity")) ? "there is a " : "is ") + currentWeather.get(2); if (!currentWeather.get(3).equals("0")) { sb += ", with wind traveling at " + currentWeather.get(3) + " miles per hour "; switch ((String) currentWeather.get(5)) { case "N": sb += "North"; break; case "NNE": sb += "North North East"; break; case "NE": sb += "North East"; break; case "ENE": sb += "East North East"; break; case "E": sb += "East"; break; case "ESE": sb += "East South East"; break; case "SE": sb += "South East"; break; case "SSE": sb += "South South East"; break; case "S": sb += "South"; break; case "SSW": sb += "South South West"; break; case "SW": sb += "South West"; break; case "WSW": sb += "West South West"; break; case "W": sb += "West"; break; case "WNW": sb += "West North West"; break; case "NW": sb += "North West"; break; case "NNW": sb += "North North West"; break; } } voice.say(sb); break; case "what time is it": date = new DateTime(clock.getCurrent()); voice.say( "It is " + date.getHourOfDay() % 12 + ":" + ((date.getMinuteOfHour() < 10) ? "oh " : "") + date.getMinuteOfHour() + ((date.getHourOfDay() > 12) ? " P.M." : " A.M.")); break; case "what is the date": date = new DateTime(clock.getCurrent()); sb = "It is the "; switch (date.getDayOfMonth()) { case 1: sb += "first"; break; case 2: sb += "second"; break; case 3: sb += "third"; break; case 4: sb += "fourth"; break; case 5: sb += "fifth"; break; case 6: sb += "sixth"; break; case 7: sb += "seventh"; break; case 8: sb += "eighth"; break; case 9: sb += "ninth"; break; case 10: sb += "tenth"; break; case 11: sb += "eleventh"; break; case 12: sb += "twelth"; break; case 13: sb += "thirteenth"; break; case 14: sb += "fourteenth"; break; case 15: sb += "fifteenth"; break; case 16: sb += "sixteenth"; break; case 17: sb += "seventeenth"; break; case 18: sb += "eighteenth"; break; case 19: sb += "nineteenth"; break; case 20: sb += "twentieth"; break; case 21: sb += "twenty-first"; break; case 22: sb += "twenty-second"; break; case 23: sb += "twenty-third"; break; case 24: sb += "twenty-fourth"; break; case 25: sb += "twenty-fifth"; break; case 26: sb += "twenty-sixth"; break; case 27: sb += "twenty-seventh"; break; case 28: sb += "twenty-eighth"; break; case 29: sb += "twenty-ninth"; break; case 30: sb += "thirtieth"; break; case 31: sb += "thirty-first"; break; } sb += " of "; switch (date.getMonthOfYear()) { case 1: sb += "January"; break; case 2: sb += "Feburary"; break; case 3: sb += "March"; break; case 4: sb += "April"; break; case 5: sb += "May"; break; case 6: sb += "June"; break; case 7: sb += "July"; break; case 8: sb += "August"; break; case 9: sb += "September"; break; case 10: sb += "October"; break; case 11: sb += "November"; break; case 12: sb += "December"; break; } sb += ", " + date.getYear(); voice.say(sb); break; case "what day is it": date = new DateTime(clock.getCurrent()); sb = "Today is "; switch (date.getDayOfWeek()) { case (1): sb += "Mondaay"; break; case (2): sb += "Tuesdaay"; break; case (3): sb += "Wednesdaay"; break; case (4): sb += "Thursdaay"; break; case (5): sb += "Fridaay"; break; case (6): sb += "Saturdaay"; break; case (7): sb += "Sundaay"; break; } voice.say(sb); break; case "create a reminder": break; case "how old are you": sb = "I am "; DateTime current = clock.getCurrent(); Period diff = new Period(birth, current); int days = Days.daysBetween(birth, current).getDays(); int hours = Hours.hoursBetween(birth, current).getHours() % 24; int minutes = Minutes.minutesBetween(birth, current).getMinutes() % 60; int seconds = Seconds.secondsBetween(birth, current).getSeconds() % 60; switch (days) { case 0: sb += ""; break; case 1: if (hours == 0 && minutes == 0 && seconds == 0) { sb += days + " day old."; } else { sb += days + " day, "; } break; default: if (hours == 0 && minutes == 0 && seconds == 0) { sb += days + " days old."; } else { sb += days + " days, "; } break; } switch (hours) { case 0: sb += ""; break; case 1: if (minutes == 0 && seconds == 0) { sb += "and " + hours + " hour old."; } else { sb += hours + " hour, "; break; } break; default: if (minutes == 0 && seconds == 0) { sb += "and " + hours + " hours old."; } else { sb += hours + " hours, "; } break; } switch (minutes) { case 0: sb += ""; break; case 1: if (seconds == 0) { sb += "and " + minutes + " minute old."; } else { sb += minutes + " minute, "; } break; default: if (seconds == 0) { sb += "and " + minutes + " minutes old."; } else { sb += minutes + " minutes, "; } break; } switch (seconds) { case 0: sb += ""; break; case 1: sb += "and " + seconds + " second old."; default: sb += "and " + seconds + " seconds old."; break; } voice.say(sb); break; case "change preferences": updatePref(); break; case "": voice.say("Lee dul lee dul lee dul leeee"); break; case "repeat": voice.repeatSlow(); break; default: voice.say(command); break; } } else { try { Thread.sleep(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.CreateAndInitializeExecutionCourses.java
License:Open Source License
private int findOffset(final Lesson oldLesson) { final GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod = oldLesson.getExecutionCourse() .getMaxLessonsPeriod();// w w w. j a va2 s . co m final LessonInstance lessonInstance = oldLesson.getFirstLessonInstance(); final Period period; if (lessonInstance != null) { period = new Period(maxLessonsPeriod.getLeft(), lessonInstance.getDay()); } else if (oldLesson.getPeriod() != null) { final YearMonthDay start = oldLesson.getPeriod().getStartYearMonthDay(); period = new Period(maxLessonsPeriod.getLeft(), start); } else { period = null; } return period == null ? 0 : period.getMonths() * 4 + period.getWeeks() + (period.getDays() / 7); }
From source file:pt.ist.fenixedu.teacher.domain.reports.TeachersListFromGiafReportFile.java
License:Open Source License
private void listTeachers(Spreadsheet spreadsheet, final ExecutionYear executionYear) throws IOException { generateNameAndHeaders(spreadsheet, executionYear); for (final Teacher teacher : getRootDomainObject().getTeachersSet()) { PersonProfessionalData personProfessionalData = teacher.getPerson().getPersonProfessionalData(); if (personProfessionalData != null) { GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData(); if (personProfessionalData != null && giafProfessionalData != null) { PersonContractSituation personContractSituation = personProfessionalData .getCurrentOrLastPersonContractSituationByCategoryType(CategoryType.TEACHER, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); if (personContractSituation != null) { Unit unit = teacher.getPerson().getEmployee() != null ? teacher.getPerson().getEmployee() .getLastWorkingPlace(executionYear.getBeginDateYearMonthDay(), executionYear.getEndDateYearMonthDay()) : null;//from w ww .j a va 2 s .com ProfessionalCategory professionalCategory = personProfessionalData .getLastProfessionalCategoryByCategoryType(CategoryType.TEACHER, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); ProfessionalRegime professionalRegime = personProfessionalData.getLastProfessionalRegime( giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); ProfessionalRelation professionalRelation = personProfessionalData .getLastProfessionalRelation(giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); Double mandatoryLessonHours = TeacherCredits.calculateMandatoryLessonHours(teacher, getLastSemester(personContractSituation, executionYear)); Period yearsInHouse = new Period(giafProfessionalData.getInstitutionEntryDate(), (personContractSituation.getEndDate() == null ? new LocalDate() : personContractSituation.getEndDate())); writePersonInformationRow(spreadsheet, executionYear, teacher, "CONTRATADO", unit, professionalCategory.getTeacherCategory(), professionalRegime, professionalRelation, personContractSituation.getBeginDate(), personContractSituation.getEndDate(), mandatoryLessonHours, yearsInHouse.getYears()); } } } } for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { executionSemester.getTeacherAuthorizationStream().filter(a -> !a.isContracted()) .forEach((authorization) -> { writePersonInformationRow(spreadsheet, executionYear, authorization.getTeacher(), "AUTORIZADO", authorization.getDepartment().getDepartmentUnit(), authorization.getTeacherCategory(), null, null, authorization.getExecutionSemester().getBeginDateYearMonthDay().toLocalDate(), authorization.getExecutionSemester().getEndDateYearMonthDay().toLocalDate(), authorization.getLessonHours(), null); }); } }
From source file:pt.ist.fenixedu.teacher.evaluation.domain.reports.TeachersListFromGiafReportFile.java
License:Open Source License
private void listTeachers(Spreadsheet spreadsheet, final ExecutionYear executionYear) throws IOException { generateNameAndHeaders(spreadsheet, executionYear); for (final Teacher teacher : getRootDomainObject().getTeachersSet()) { PersonProfessionalData personProfessionalData = teacher.getPerson().getPersonProfessionalData(); if (personProfessionalData != null) { GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData(); if (personProfessionalData != null && giafProfessionalData != null) { PersonContractSituation personContractSituation = personProfessionalData .getCurrentOrLastPersonContractSituationByCategoryType(CategoryType.TEACHER, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); if (personContractSituation != null) { Unit unit = teacher.getPerson().getEmployee() != null ? teacher.getPerson().getEmployee() .getLastWorkingPlace(executionYear.getBeginDateYearMonthDay(), executionYear.getEndDateYearMonthDay()) : null;//from ww w . j a va2s .c o m ProfessionalCategory professionalCategory = teacher .getLastCategory(executionYear.getAcademicInterval()) .map(tc -> tc.getProfessionalCategory()).orElse(null); ProfessionalRegime professionalRegime = personProfessionalData.getLastProfessionalRegime( giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); ProfessionalRelation professionalRelation = personProfessionalData .getLastProfessionalRelation(giafProfessionalData, executionYear.getBeginDateYearMonthDay().toLocalDate(), executionYear.getEndDateYearMonthDay().toLocalDate()); Double mandatoryLessonHours = TeacherCredits.calculateMandatoryLessonHours(teacher, getLastSemester(personContractSituation, executionYear)); Period yearsInHouse = new Period(giafProfessionalData.getInstitutionEntryDate(), (personContractSituation.getEndDate() == null ? new LocalDate() : personContractSituation.getEndDate())); writePersonInformationRow(spreadsheet, executionYear, teacher, "CONTRATADO", unit, professionalCategory.getTeacherCategory(), professionalRegime, professionalRelation, personContractSituation.getBeginDate(), personContractSituation.getEndDate(), mandatoryLessonHours, yearsInHouse.getYears()); } } } } for (ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { executionSemester.getTeacherAuthorizationStream().filter(a -> !a.isContracted()) .forEach((authorization) -> { writePersonInformationRow(spreadsheet, executionYear, authorization.getTeacher(), "AUTORIZADO", authorization.getDepartment().getDepartmentUnit(), authorization.getTeacherCategory(), null, null, authorization.getExecutionSemester().getBeginDateYearMonthDay().toLocalDate(), authorization.getExecutionSemester().getEndDateYearMonthDay().toLocalDate(), authorization.getLessonHours(), null); }); } }
From source file:ru.codemine.ccms.entity.Task.java
License:Open Source License
public String getDeadlineString() { PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix(" ", " ") .appendSeparator(" ").appendHours().appendSuffix(" ?", " ?").appendSeparator(" ") .appendMinutes().appendSuffix(" ", " ").toFormatter(); if (!isOverdued()) { Period deadlinePeriod = new Period(DateTime.now(), deadline); return formatter.print(deadlinePeriod); }//from www . j a v a 2 s.c o m Period deadlinePeriod = new Period(deadline, DateTime.now()); return "? " + formatter.print(deadlinePeriod); }