Example usage for org.joda.time LocalDate toDateTimeAtCurrentTime

List of usage examples for org.joda.time LocalDate toDateTimeAtCurrentTime

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDateTimeAtCurrentTime.

Prototype

public DateTime toDateTimeAtCurrentTime() 

Source Link

Document

Converts this LocalDate to a full datetime using the default time zone setting the date fields from this instance and the time fields from the current time.

Usage

From source file:supply.CapacityHarvester.java

License:Apache License

public static int getCalculatedRemainingHours(String username) {
    // Find start and end date for current sprint
    // --> Lookup sprint setup

    // Business days To Sprint End
    DateTime sprintStartDate = new DateTime(2014, 02, 1, 0, 0, 0, 0);
    DateTime sprintEndDate = new DateTime(2014, 02, 28, 17, 0);
    logger.info("sprintEndDate WeekOfWeekyear=" + sprintEndDate.getWeekOfWeekyear());
    logger.info("sprintEndDate WeekOfWeekyear=" + sprintEndDate.getWeekOfWeekyear());
    LocalDate today = new LocalDate();

    // business days left in current week
    logger.info("Current week=" + today.getWeekOfWeekyear());
    if (today.getDayOfWeek() > 5) {
        logger.info("Not a business day. 0 hours left of availability as this is weekend.");
    }/*w ww .j a  v a  2s.c om*/
    SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy");
    Period weekPeriod = new Period().withWeeks(1);
    Interval i = new Interval(sprintStartDate, weekPeriod);
    int hours = 0;
    while (i.getEnd().isBefore(sprintEndDate)) {
        logger.info("week: " + i.getStart().getWeekOfWeekyear() + " start: " + df.format(i.getStart().toDate())
                + " end: " + df.format(i.getEnd().minusMillis(1).toDate()));
        i = new Interval(i.getStart().plus(weekPeriod), weekPeriod);
        int availabilityHours = Availability.getAvailability(i.getStart().toCalendar(Locale.US), username);
        logger.info("Reported availability hours for [" + username + "]: " + availabilityHours);
        hours += availabilityHours;
    }

    Days days = Days.daysBetween(today.toDateTimeAtStartOfDay(), sprintEndDate);

    int hoursRemaining = Hours.hoursBetween(today.toDateTimeAtCurrentTime(), sprintEndDate).getHours();
    if (hoursRemaining < 0)
        hoursRemaining = 0;
    logger.info("HoursToSprintEnd=" + hoursRemaining);
    logger.info("DayOfWeek=" + today.getDayOfWeek());
    logger.info("WeekOfWeekyear=" + today.getWeekOfWeekyear());
    logger.info("Hours from DB=" + hours);

    // --> Find week numbers
    // --> Check that current date is between start/end date of sprint

    // Lookup how many hours this user has for the sprint
    // --> lookup in HBase
    // --> 

    return hoursRemaining;
}