Example usage for org.joda.time Weeks getWeeks

List of usage examples for org.joda.time Weeks getWeeks

Introduction

In this page you can find the example usage for org.joda.time Weeks getWeeks.

Prototype

public int getWeeks() 

Source Link

Document

Gets the number of weeks that this period represents.

Usage

From source file:com.cisco.dvbu.ps.utils.date.DateDiffDate.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *//*from   ww w. j  ava2s . c o m*/
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    java.util.Date startDate = null;
    java.util.Date endDate = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startDate = (java.util.Date) inputValues[1];
        startCal = Calendar.getInstance();
        startCal.setTime(startDate);

        endDate = (java.util.Date) inputValues[2];
        endCal = Calendar.getInstance();
        endCal.setTime(endDate);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);

        if (datePart.equalsIgnoreCase("second")) {
            Seconds seconds = Seconds.secondsBetween(startDateTime, endDateTime);
            dateLength = seconds.getSeconds();
        }

        if (datePart.equalsIgnoreCase("minute")) {
            Minutes minutes = Minutes.minutesBetween(startDateTime, endDateTime);
            dateLength = minutes.getMinutes();
        }

        if (datePart.equalsIgnoreCase("hour")) {
            Hours hours = Hours.hoursBetween(startDateTime, endDateTime);
            dateLength = hours.getHours();
        }

        if (datePart.equalsIgnoreCase("day")) {
            Days days = Days.daysBetween(startDateTime, endDateTime);
            dateLength = days.getDays();
        }

        if (datePart.equalsIgnoreCase("week")) {
            Weeks weeks = Weeks.weeksBetween(startDateTime, endDateTime);
            dateLength = weeks.getWeeks();
        }

        if (datePart.equalsIgnoreCase("month")) {
            Months months = Months.monthsBetween(startDateTime, endDateTime);
            dateLength = months.getMonths();
        }

        if (datePart.equalsIgnoreCase("year")) {
            Years years = Years.yearsBetween(startDateTime, endDateTime);
            dateLength = years.getYears();
        }

        result = new Long(dateLength);
    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.cisco.dvbu.ps.utils.date.DateDiffTimestamp.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *///from w  w w  .j  a  va2s .c  o  m
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    Timestamp startTimestamp = null;
    Timestamp endTimestamp = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startTimestamp = (Timestamp) inputValues[1];
        // long startMilliseconds = startTimestamp.getTime() +
        // (startTimestamp.getNanos() / 1000000);
        long startMilliseconds = startTimestamp.getTime()
                + (startTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);
        startCal = Calendar.getInstance();
        startCal.setTimeInMillis(startMilliseconds);

        endTimestamp = (Timestamp) inputValues[2];
        // long endMilliseconds = endTimestamp.getTime() +
        // (endTimestamp.getNanos() / 1000000);
        long endMilliseconds = endTimestamp.getTime() + (endTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);

        endCal = Calendar.getInstance();
        endCal.setTimeInMillis(endMilliseconds);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY),
                startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND),
                startCal.get(Calendar.MILLISECOND));
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), endCal.get(Calendar.HOUR_OF_DAY),
                endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), endCal.get(Calendar.MILLISECOND));

        Interval interval = new Interval(startDateTime, endDateTime);

        if (datePart.equalsIgnoreCase("second") || datePart.equalsIgnoreCase("ss")) {
            Seconds seconds = Seconds.secondsIn(interval);
            dateLength = seconds.getSeconds();
        } else if (datePart.equalsIgnoreCase("minute") || datePart.equalsIgnoreCase("mi")) {
            Minutes minutes = Minutes.minutesIn(interval);
            dateLength = minutes.getMinutes();
        } else if (datePart.equalsIgnoreCase("hour") || datePart.equalsIgnoreCase("hh")) {
            Hours hours = Hours.hoursIn(interval);
            dateLength = hours.getHours();
        } else if (datePart.equalsIgnoreCase("day") || datePart.equalsIgnoreCase("dd")) {
            Days days = Days.daysIn(interval);
            dateLength = days.getDays();
        } else if (datePart.equalsIgnoreCase("week") || datePart.equalsIgnoreCase("wk")) {
            Weeks weeks = Weeks.weeksIn(interval);
            dateLength = weeks.getWeeks();
        } else if (datePart.equalsIgnoreCase("month") || datePart.equalsIgnoreCase("mm")) {
            Months months = Months.monthsIn(interval);
            dateLength = months.getMonths();
        } else if (datePart.equalsIgnoreCase("year") || datePart.equalsIgnoreCase("yy")) {
            Years years = Years.yearsIn(interval);
            dateLength = years.getYears();
        } else if (datePart.equalsIgnoreCase("millisecond") || datePart.equalsIgnoreCase("ms")) {
            dateLength = (endTimestamp.getTime() - startTimestamp.getTime()); // millis
        } else if (datePart.equalsIgnoreCase("microsecond") || datePart.equalsIgnoreCase("mcs")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000L // micros
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()) / 1000; // nanos/1000
        } else if (datePart.equalsIgnoreCase("nanosecond") || datePart.equalsIgnoreCase("ns")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000000L // nanos
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()); // nanos
        } else {
            throw new IllegalArgumentException(datePart);
        }

        result = new Long(dateLength);

    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.simopuve.helper.POIHelper.java

public static Integer getWeekNumber(Date currentDate) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(currentDate);/*from   w  w  w  . j av a  2  s .  c  o m*/
    Logger.getLogger(POIHelper.class.getName()).log(Level.INFO, "Received date: "
            + cal.get(Calendar.DAY_OF_MONTH) + "-" + (cal.get(Calendar.MONTH)) + "-" + cal.get(Calendar.YEAR));
    org.joda.time.format.DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyy");
    DateTime nowDate = fmt.parseLocalDate(
            cal.get(Calendar.DAY_OF_MONTH) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.YEAR))
            .toDateTimeAtCurrentTime();
    //DateTime nowDate = new DateTime(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);
    Weeks w = Weeks.weeksBetween(initDateWeek, nowDate);
    return w.getWeeks() + 435;
}

From source file:de.sub.goobi.forms.ProjekteForm.java

License:Open Source License

private Double getThroughputPerDay() {
    DateTime start = new DateTime(this.myProjekt.getStartDate().getTime());
    DateTime end = new DateTime(this.myProjekt.getEndDate().getTime());
    Weeks weeks = Weeks.weeksBetween(start, end);
    logger.trace(weeks.getWeeks());
    int days = (weeks.getWeeks() * 5);

    if (days < 1) {
        days = 1;// ww w.j a v a  2 s. c om
    }
    return (double) this.myProjekt.getNumberOfVolumes() / (double) days;
}

From source file:de.sub.goobi.forms.ProjekteForm.java

License:Open Source License

/**
 * calculate throughput of pages per day.
 *
 * @return calculation//  w w w .j av a 2  s  .c o  m
 */

private Double getThroughputPagesPerDay() {
    DateTime start = new DateTime(this.myProjekt.getStartDate().getTime());
    DateTime end = new DateTime(this.myProjekt.getEndDate().getTime());

    Weeks weeks = Weeks.weeksBetween(start, end);
    int days = (weeks.getWeeks() * 5);
    if (days < 1) {
        days = 1;
    }
    return (double) this.myProjekt.getNumberOfPages() / (double) days;
}

From source file:influent.server.utilities.DateRangeBuilder.java

License:MIT License

public static FL_DateRange getDateRange(DateTime startDate, DateTime endDate) {

    if (startDate == null || endDate == null) {
        return null;
    }/*from   www.  j  a  va2  s.  co  m*/

    // TODO: add support for numIntervalsPerBin, but on the client resource side in charts only.
    Days days = Days.daysBetween(startDate, endDate);
    if (days.getDays() == 14) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 14L);
    }
    //      if (days.getDays() == 30) { return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 15L, 2); }
    //      if (days.getDays() == 60) { return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 15L, 4); }
    Weeks weeks = Weeks.weeksBetween(startDate, endDate);
    if (weeks.getWeeks() == 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 16L);
    }
    //      if (weeks.getWeeks() == 32) { return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 16L, 2); }
    Months months = Months.monthsBetween(startDate, endDate);
    if (months.getMonths() == 12) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 12L);
    }
    if (months.getMonths() == 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 16L);
    }
    //      if (months.getMonths() == 24) { return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 16L, 2); }
    if (months.getMonths() == 32) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 12L);
    }
    Years years = Years.yearsBetween(startDate, endDate);
    if (years.getYears() == 4) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 16L);
    }
    //      if (years.getYears() == 8) { return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 16L, 2); }
    if (years.getYears() == 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.YEARS, 16L);
    }

    throw new RuntimeException("Unsupported chart date range: " + startDate + " to " + endDate);
}

From source file:influent.server.utilities.DateRangeBuilder.java

License:MIT License

public static FL_DateRange getBigChartDateRange(DateTime startDate, DateTime endDate) {
    if (startDate == null || endDate == null) {
        return null;
    }// ww w  .  j ava 2  s  .  c  om

    Days days = Days.daysBetween(startDate, endDate);
    if (days.getDays() <= 14) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 14L);
    }
    if (days.getDays() <= 30) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 30L);
    }
    if (days.getDays() <= 60) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 60L);
    }
    Weeks weeks = Weeks.weeksBetween(startDate, endDate);
    if (weeks.getWeeks() <= 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.DAYS, 112L);
    }
    if (weeks.getWeeks() <= 32) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 32L);
    }
    Months months = Months.monthsBetween(startDate, endDate);
    if (months.getMonths() <= 12) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 52);
    }
    if (months.getMonths() <= 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.WEEKS, 70L);
    }
    if (months.getMonths() <= 24) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 24L);
    }
    if (months.getMonths() <= 32) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 32L);
    }
    Years years = Years.yearsBetween(startDate, endDate);
    if (years.getYears() <= 4) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 48L);
    }
    if (years.getYears() <= 5) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 60L);
    }
    if (years.getYears() <= 6) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 72L);
    }
    if (years.getYears() <= 7) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 84L);
    }
    if (years.getYears() <= 8) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.MONTHS, 96L);
    }
    if (years.getYears() <= 16) {
        return new ConstrainedDateRange(startDate, FL_DateInterval.QUARTERS, 64L);
    }

    throw new RuntimeException("Unsupported chart date range: " + startDate + " to " + endDate);
}

From source file:influent.server.utilities.DateRangeBuilder.java

License:MIT License

public static int determineInterval(DateTime date, DateTime startDate, FL_DateInterval interval,
        int numIntervalsPerBin) {
    switch (interval) {
    case SECONDS:
        Seconds seconds = Seconds.secondsBetween(startDate, date);
        return seconds.getSeconds() / numIntervalsPerBin;
    case HOURS://from w  ww. j  av a 2  s  .com
        Hours hours = Hours.hoursBetween(startDate, date);
        return hours.getHours() / numIntervalsPerBin;
    case DAYS:
        Days days = Days.daysBetween(startDate, date);
        return days.getDays() / numIntervalsPerBin;
    case WEEKS:
        Weeks weeks = Weeks.weeksBetween(startDate, date);
        return weeks.getWeeks() / numIntervalsPerBin;
    case MONTHS:
        Months months = Months.monthsBetween(startDate, date);
        return months.getMonths() / numIntervalsPerBin;
    case QUARTERS:
        months = Months.monthsBetween(startDate, date);
        return months.getMonths() / 3 / numIntervalsPerBin;
    case YEARS:
        Years years = Years.yearsBetween(startDate, date);
        return years.getYears() / numIntervalsPerBin;
    }
    return 0;
}

From source file:it.webappcommon.lib.DateUtils.java

License:Open Source License

public static int differenzaInSettimane(Date start, Date end) {
    int res = 0;/*from   w  ww.  j  a va 2s .co  m*/

    DateTime startDate = new DateTime(start);
    DateTime endDate = new DateTime(end);

    Weeks settimane = Weeks.weeksBetween(startDate, endDate);
    res = settimane.getWeeks();

    return res;
}

From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java

License:Open Source License

@Cacheable(value = "diaCache")
@Transactional(readOnly = true)/*from   w ww.ja  va2  s.  c o  m*/
@Override
public Inicio inicio(Calendar hoy) {
    log.debug("Hoy: {}", hoy.getTime());

    if (hoy.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && hoy.get(Calendar.HOUR_OF_DAY) < 12) {
        hoy.add(Calendar.DAY_OF_WEEK, -1);
    }

    Trimestre trimestre = trimestreService.obtiene(hoy.getTime());

    if (trimestre != null) {
        DateTime a = new DateTime(trimestre.getInicia());
        DateTime b = new DateTime(hoy);
        Weeks c = Weeks.weeksBetween(a, b);
        int weeks = c.getWeeks() + 1;
        log.debug("Weeks: {}", weeks);
        StringBuilder leccion = new StringBuilder();
        leccion.append("l").append(dosDigitos.format(weeks));

        Inicio inicio = new Inicio();
        inicio.setAnio(trimestre.getNombre().substring(0, 4));
        inicio.setTrimestre(trimestre.getNombre().substring(4));
        inicio.setLeccion(leccion.toString());
        inicio.setDia(obtieneDia(hoy.get(Calendar.DAY_OF_WEEK)));
        return inicio;
    } else {
        return null;
    }

}