Java Code Examples for org.joda.time.Period#getWeeks()

The following examples show how to use org.joda.time.Period#getWeeks() . 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: DateTimeService.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
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 2
Source File: WeeklyWorkLoadDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 3
Source File: ExecutionCourse.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 4
Source File: TimeCalculation.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
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 5
Source File: Grouping.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
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 6
Source File: WeeklyWorkLoadDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
    }
}