Java Code Examples for org.joda.time.Period#getDays()
The following examples show how to use
org.joda.time.Period#getDays() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DremioStringUtils.java From dremio-oss with Apache License 2.0 | 6 votes |
/** * Formats a period similar to Oracle INTERVAL DAY TO SECOND data type.<br> * For example, the string "-001 18:25:16.766" defines an interval of - 1 day 18 hours 25 minutes 16 seconds and 766 milliseconds */ public static String formatIntervalDay(final Period p) { long millis = p.getDays() * (long) DateUtility.daysToStandardMillis + JodaDateUtility.millisFromPeriod(p); boolean neg = false; if (millis < 0) { millis = -millis; neg = true; } final int days = (int) (millis / DateUtility.daysToStandardMillis); millis = millis % DateUtility.daysToStandardMillis; final int hours = (int) (millis / DateUtility.hoursToMillis); millis = millis % DateUtility.hoursToMillis; final int minutes = (int) (millis / DateUtility.minutesToMillis); millis = millis % DateUtility.minutesToMillis; final int seconds = (int) (millis / DateUtility.secondsToMillis); millis = millis % DateUtility.secondsToMillis; return String.format("%c%03d %02d:%02d:%02d.%03d", neg ? '-':'+', days, hours, minutes, seconds, millis); }
Example 2
Source File: DateTimeService.java From hawkular-metrics with Apache License 2.0 | 6 votes |
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); } return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
Example 3
Source File: LocalDatePeriodCountCalculator.java From objectlabkit with Apache License 2.0 | 6 votes |
public int dayDiff(final LocalDate start, final LocalDate end, final PeriodCountBasis basis) { int diff; switch (basis) { case CONV_30_360: diff = diffConv30v360(start, end); break; case CONV_360E_ISDA: diff = diff360EIsda(start, end); break; case CONV_360E_ISMA: diff = diff360EIsma(start, end); break; default: final Period p = new Period(start, end, PeriodType.days()); diff = p.getDays(); } return diff; }
Example 4
Source File: ThirdEyeUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Guess time duration from period. * * @param granularity dataset granularity * @return */ public static int getTimeDuration(Period granularity) { if (granularity.getDays() > 0) { return granularity.getDays(); } if (granularity.getHours() > 0) { return granularity.getHours(); } if (granularity.getMinutes() > 0) { return granularity.getMinutes(); } if (granularity.getSeconds() > 0) { return granularity.getSeconds(); } return granularity.getMillis(); }
Example 5
Source File: ThirdEyeUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Guess time unit from period. * * @param granularity dataset granularity * @return */ public static TimeUnit getTimeUnit(Period granularity) { if (granularity.getDays() > 0) { return TimeUnit.DAYS; } if (granularity.getHours() > 0) { return TimeUnit.HOURS; } if (granularity.getMinutes() > 0) { return TimeUnit.MINUTES; } if (granularity.getSeconds() > 0) { return TimeUnit.SECONDS; } return TimeUnit.MILLISECONDS; }
Example 6
Source File: WeeklyWorkLoadDA.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public CurricularYearWeeklyWorkLoadView(final DegreeCurricularPlan degreeCurricularPlan, final ExecutionSemester executionSemester, final Set<ExecutionCourse> executionCourses) { final ExecutionDegree executionDegree = findExecutionDegree(executionSemester, degreeCurricularPlan); if (executionDegree != null) { this.interval = new Interval(new DateMidnight(getBegginingOfLessonPeriod(executionSemester, executionDegree)), new DateMidnight(getEndOfExamsPeriod(executionSemester, executionDegree))); final Period period = interval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = interval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } this.executionCourses.addAll(executionCourses); } }
Example 7
Source File: ExecutionCourse.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public WeeklyWorkLoadView(final Interval executionPeriodInterval) { this.executionPeriodInterval = executionPeriodInterval; final Period period = executionPeriodInterval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; numberResponses = new int[numberOfWeeks]; contactSum = new int[numberOfWeeks]; autonomousStudySum = new int[numberOfWeeks]; otherSum = new int[numberOfWeeks]; totalSum = new int[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = executionPeriodInterval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } }
Example 8
Source File: MyEvent.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
public String getDuration() { if (duration != null) { return duration; } final Period period = new Period(this.getStart(), this.getEnd()); int days = period.getDays(); if (isAllDay() == true) { ++days; } final int hours = period.getHours(); final int minutes = period.getMinutes(); final StringBuffer buf = new StringBuffer(); if (days > 0) { // days buf.append(days).append(PFUserContext.getLocalizedString("calendar.unit.day")).append(" "); } if (isAllDay() == false) { buf.append(hours).append(":"); // hours if (minutes < 10) { buf.append("0"); } buf.append(minutes); } duration = buf.toString(); return duration; }
Example 9
Source File: VectorOutput.java From Bats with Apache License 2.0 | 5 votes |
@Override public void writeInterval(boolean isNull) throws IOException { IntervalWriter intervalWriter = writer.interval(); if(!isNull){ final Period p = ISOPeriodFormat.standard().parsePeriod(parser.getValueAsString()); int months = DateUtilities.monthsFromPeriod(p); int days = p.getDays(); int millis = DateUtilities.periodToMillis(p); intervalWriter.writeInterval(months, days, millis); } }
Example 10
Source File: VectorOutput.java From Bats with Apache License 2.0 | 5 votes |
@Override public void writeInterval(boolean isNull) throws IOException { IntervalWriter intervalWriter = writer.interval(fieldName); if(!isNull){ final Period p = ISOPeriodFormat.standard().parsePeriod(parser.getValueAsString()); int months = DateUtilities.monthsFromPeriod(p); int days = p.getDays(); int millis = DateUtilities.periodToMillis(p); intervalWriter.writeInterval(months, days, millis); } }
Example 11
Source File: DateUtils.java From boot-actuator with MIT License | 5 votes |
/** * 取两个日期间隔 * @param startDate * @param endDate * @return */ public static String getDateTimeBetween(Date startDate, Date endDate) { DateTime start = new DateTime(startDate.getTime()); DateTime end = new DateTime(endDate.getTime()); Period period = new Period(start, end); String result = period.getDays() + "天" + period.getHours() + "小时" + period.getMinutes() + "分" + period.getSeconds() + "秒"; return result; }
Example 12
Source File: TimeCalculation.java From mangosta-android with Apache License 2.0 | 5 votes |
private static String getTimeStringAgoSinceDateTime(Context context, DateTime dateTime) { DateTime now = new DateTime(DateTimeZone.getDefault()); Period period = new Period(dateTime, now); String date; int count; if (period.getYears() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_years_ago, period.getYears()); count = period.getYears(); } else if (period.getMonths() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_months_ago, period.getMonths()); count = period.getMonths(); } else if (period.getWeeks() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_weeks_ago, period.getWeeks()); count = period.getWeeks(); } else if (period.getDays() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_days_ago, period.getDays()); count = period.getDays(); } else if (period.getHours() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_hours_ago, period.getHours()); count = period.getHours(); } else if (period.getMinutes() >= 1) { date = context.getResources().getQuantityString(R.plurals.date_minutes_ago, period.getMinutes()); count = period.getMinutes(); } else if (period.getSeconds() >= 3) { date = String.format(Locale.getDefault(), context.getString(R.string.date_seconds_ago), period.getSeconds()); count = period.getSeconds(); } else { return " " + context.getString(R.string.date_seconds_now); } return String.format(Locale.getDefault(), date, count); }
Example 13
Source File: Grouping.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static DateTime makeOrigin(DateTime first, Period period) { if (period.getYears() > 0) { return first.year().roundFloorCopy().toDateTime(); } else if (period.getMonths() > 0) { return first.monthOfYear().roundFloorCopy().toDateTime(); } else if (period.getWeeks() > 0) { return first.weekOfWeekyear().roundFloorCopy().toDateTime(); } else if (period.getDays() > 0) { return first.dayOfYear().roundFloorCopy().toDateTime(); } else if (period.getHours() > 0) { return first.hourOfDay().roundFloorCopy().toDateTime(); } else if (period.getMinutes() > 0) { return first.minuteOfHour().roundFloorCopy().toDateTime(); } else if (period.getSeconds() > 0) { return first.secondOfMinute().roundFloorCopy().toDateTime(); } else if (period.getMillis() > 0) { return first.millisOfSecond().roundFloorCopy().toDateTime(); } throw new IllegalArgumentException(String.format("Unsupported Period '%s'", period)); }
Example 14
Source File: WeeklyWorkLoadDA.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public WeeklyWorkLoadView(final Interval executionPeriodInterval) { this.executionPeriodInterval = executionPeriodInterval; final Period period = executionPeriodInterval.toPeriod(); int extraWeek = period.getDays() > 0 ? 1 : 0; numberOfWeeks = (period.getYears() * 12 + period.getMonths()) * 4 + period.getWeeks() + extraWeek + 1; intervals = new Interval[numberOfWeeks]; intervalTypes = new IntervalType[numberOfWeeks]; for (int i = 0; i < numberOfWeeks; i++) { final DateTime start = executionPeriodInterval.getStart().plusWeeks(i); final DateTime end = start.plusWeeks(1); intervals[i] = new Interval(start, end); } }
Example 15
Source File: Fixtures.java From dremio-oss with Apache License 2.0 | 4 votes |
private static Cell toCell(Object obj){ Preconditions.checkNotNull(obj, "Use Null constants to express nulls, such as NULL_VARCHAR, NULL_INT, etc."); if(obj instanceof Cell){ return (Cell) obj; } else if(obj instanceof String){ return new VarChar((String) obj); }else if(obj instanceof Long){ return new BigInt((Long)obj); }else if(obj instanceof Double){ return new DoublePrecision((Double)obj); }else if(obj instanceof Float){ return new Floating((Float)obj); }else if(obj instanceof Integer){ return new IntCell((Integer)obj); }else if(obj instanceof Boolean){ return new BooleanCell((Boolean)obj); }else if(obj instanceof byte[]){ return new VarBinary((byte[])obj); }else if(obj instanceof LocalDateTime) { return new Timestamp((LocalDateTime)obj); }else if(obj instanceof LocalTime) { return new Time((LocalTime)obj); }else if(obj instanceof LocalDate) { return new Date((LocalDate)obj); }else if(obj instanceof List) { return new ListCell((List<Integer>)obj); }else if(obj instanceof BigDecimal) { return new Decimal((BigDecimal) obj); } else if(obj instanceof Period) { Period p = (Period) obj; if (p.getYears() == 0 && p.getMonths() == 0) { return new IntervalDaySecond(p); } if (p.getDays() == 0) { return new IntervalYearMonth(p); } } throw new UnsupportedOperationException(String.format("Unable to interpret object of type %s.", obj.getClass().getSimpleName())); }