List of usage examples for org.joda.time PeriodType millis
public static PeriodType millis()
From source file:com.nestedbird.models.eventtime.EventTime.java
License:Open Source License
/** * Gets all occurrences of an event time * * @param fromTime the from time// ww w . j a v a 2 s.c o m * @return list of occurrences */ @JsonIgnore public List<ParsedEventData> getOccurrences(final long fromTime) { List<ParsedEventData> parsedResults = new ArrayList<>(); if (getStartTime() == null) { return parsedResults; } final long startTime = getStartTime().getMillis(); if (startTime >= fromTime) { parsedResults.add(generateParsedEventData(startTime, getDuration(), event.getId())); } if ((getRepeatTime() != null) && (getRepeatTime().normalizedStandard(PeriodType.hours()).getHours() >= 24)) { final long finalTime = DateTime.now().plusWeeks(6).getMillis(); final long lastTime = (getRepeatEnd() != null) ? getRepeatEnd().getMillis() : finalTime; final long newLastTime = lastTime <= finalTime ? lastTime : finalTime; final long timeDifference = newLastTime - startTime; if (timeDifference > 0) { final long repeatTime = getRepeatTime().normalizedStandard(PeriodType.millis()).getMillis(); final int repeatOccurrences = (int) Math.floor((double) timeDifference / (double) repeatTime); for (int i = 1; i <= Math.min(repeatOccurrences, 10); i++) { final long occurrenceTime = startTime + (repeatTime * i); if (occurrenceTime >= fromTime) { parsedResults.add(generateParsedEventData(occurrenceTime, getDuration(), event.getId())); } } } } return parsedResults; }
From source file:ee.ut.soras.test_ajavt.KiiruseTestiTulemus.java
License:Open Source License
private String convertToOtherFields(double timeInMills) { Period p = new Period((long) timeInMills, PeriodType.millis()); p = p.normalizedStandard();/*from w w w .j a va 2s. co m*/ DurationFieldType[] fieldTypes = p.getFieldTypes(); int[] values = p.getValues(); if (values.length == fieldTypes.length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.length; i++) { if (values[i] != 0) { sb.append(values[i] + " " + fieldTypes[i].getName() + " "); } } return sb.toString(); } return p.toString(); }
From source file:org.cish4380.groupproject.utility.ApplicationPerformanceCounter.java
@Override public String getDuration() { return new Duration(startTime, DateTime.now()).toPeriod(PeriodType.millis()).toString(); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnPeriodMapper.java
License:Apache License
private PeriodType determinePeriodType(String s) { PeriodType periodType = PeriodType.standard(); String current = s;//from w ww.ja va2 s . c o m if (current.startsWith(PeriodType.standard().getName())) { periodType = PeriodType.standard(); current = s.substring(PeriodType.standard().getName().length()); } else if (current.startsWith(PeriodType.yearMonthDayTime().getName())) { periodType = PeriodType.yearMonthDayTime(); current = s.substring(PeriodType.yearMonthDayTime().getName().length()); } else if (current.startsWith(PeriodType.yearMonthDay().getName())) { periodType = PeriodType.yearMonthDay(); current = s.substring(PeriodType.yearMonthDay().getName().length()); } else if (current.startsWith(PeriodType.yearWeekDayTime().getName())) { periodType = PeriodType.yearWeekDayTime(); current = s.substring(PeriodType.yearWeekDayTime().getName().length()); } else if (current.startsWith(PeriodType.yearWeekDay().getName())) { periodType = PeriodType.yearWeekDay(); current = s.substring(PeriodType.yearWeekDay().getName().length()); } else if (current.startsWith(PeriodType.yearDayTime().getName())) { periodType = PeriodType.yearDayTime(); current = s.substring(PeriodType.yearDayTime().getName().length()); } else if (current.startsWith(PeriodType.yearDay().getName())) { periodType = PeriodType.yearDay(); current = s.substring(PeriodType.yearDay().getName().length()); } else if (current.startsWith(PeriodType.dayTime().getName())) { periodType = PeriodType.dayTime(); current = s.substring(PeriodType.dayTime().getName().length()); } else if (current.startsWith(PeriodType.time().getName())) { periodType = PeriodType.time(); current = s.substring(PeriodType.time().getName().length()); } else if (current.startsWith(PeriodType.years().getName())) { periodType = PeriodType.years(); current = s.substring(PeriodType.years().getName().length()); } else if (current.startsWith(PeriodType.months().getName())) { periodType = PeriodType.months(); current = s.substring(PeriodType.months().getName().length()); } else if (current.startsWith(PeriodType.weeks().getName())) { periodType = PeriodType.weeks(); current = s.substring(PeriodType.weeks().getName().length()); } else if (current.startsWith(PeriodType.days().getName())) { periodType = PeriodType.days(); current = s.substring(PeriodType.days().getName().length()); } else if (current.startsWith(PeriodType.hours().getName())) { periodType = PeriodType.hours(); current = s.substring(PeriodType.hours().getName().length()); } else if (current.startsWith(PeriodType.minutes().getName())) { periodType = PeriodType.minutes(); current = s.substring(PeriodType.minutes().getName().length()); } else if (current.startsWith(PeriodType.seconds().getName())) { periodType = PeriodType.seconds(); current = s.substring(PeriodType.seconds().getName().length()); } else if (current.startsWith(PeriodType.millis().getName())) { periodType = PeriodType.millis(); current = s.substring(PeriodType.millis().getName().length()); } while (current.length() > 0) { if (current.startsWith("NoYears")) { periodType = periodType.withYearsRemoved(); current = s.substring("NoYears".length()); } else if (current.startsWith("NoMonths")) { periodType = periodType.withMonthsRemoved(); current = s.substring("NoMonths".length()); } else if (current.startsWith("NoWeeks")) { periodType = periodType.withWeeksRemoved(); current = s.substring("NoWeeks".length()); } else if (current.startsWith("NoDays")) { periodType = periodType.withDaysRemoved(); current = s.substring("NoDays".length()); } else if (current.startsWith("NoHours")) { periodType = periodType.withHoursRemoved(); current = s.substring("NoHours".length()); } else if (current.startsWith("NoMinutes")) { periodType = periodType.withMinutesRemoved(); current = s.substring("NoMinutes".length()); } else if (current.startsWith("NoSeconds")) { periodType = periodType.withSecondsRemoved(); current = s.substring("NoSeconds".length()); } else if (current.startsWith("NoMillis")) { periodType = periodType.withMillisRemoved(); current = s.substring("NoMillis".length()); } else { throw new IllegalArgumentException("Unrecognised PeriodType: " + s + "{" + current + "}"); } } return periodType; }