Example usage for java.util Calendar DAY_OF_YEAR

List of usage examples for java.util Calendar DAY_OF_YEAR

Introduction

In this page you can find the example usage for java.util Calendar DAY_OF_YEAR.

Prototype

int DAY_OF_YEAR

To view the source code for java.util Calendar DAY_OF_YEAR.

Click Source Link

Document

Field number for get and set indicating the day number within the current year.

Usage

From source file:com.microsoft.tfs.client.common.ui.teambuild.teamexplorer.sections.TeamExplorerBuildsMyBuildsSection.java

private void loadBuildItems() {
    final IBuildServer buildServer = context.getBuildServer();
    if (buildServer == null) {
        return;/*from  w  w  w . j a  va  2  s . c  o m*/
    }

    // Create a calendar for 7 days ago.
    final Calendar beginDate = Calendar.getInstance();
    beginDate.add(Calendar.DAY_OF_YEAR, -7);

    final String projectName = context.getCurrentProjectInfo().getName();
    final String uniqueUserName = context.getServer().getConnection().getAuthenticatedIdentity()
            .getUniqueName();

    // Query for the queued builds.
    final IQueuedBuildSpec queueSpec = buildServer.createBuildQueueSpec(projectName);
    final IQueuedBuildQueryResult[] queuedResult = buildServer
            .queryQueuedBuilds(new IQueuedBuildSpec[] { queueSpec });

    // Query for the completed builds.
    final IBuildDetailSpec detailSpec = buildServer.createBuildDetailSpec(projectName);
    detailSpec.setMinFinishTime(beginDate);
    detailSpec.setRequestedFor(uniqueUserName);
    detailSpec.setStatus(COMPLETED_BUILD_STATES);
    final IBuildQueryResult completedResult = buildServer.queryBuilds(detailSpec);

    final List<Object> list = new ArrayList<Object>();
    final IQueuedBuild[] queuedBuilds = queuedResult[0].getQueuedBuilds();
    Arrays.sort(queuedBuilds, new Comparator<IQueuedBuild>() {
        @Override
        public int compare(final IQueuedBuild o1, final IQueuedBuild o2) {
            return o2.getQueueTime().compareTo(o1.getQueueTime());
        }
    });

    for (final IQueuedBuild queuedBuild : queuedResult[0].getQueuedBuilds()) {
        if (queuedBuild.getRequestedFor().equals(uniqueUserName)) {
            list.add(queuedBuild);
        }
    }

    final IBuildDetail[] completedBuilds = completedResult.getBuilds();
    Arrays.sort(completedBuilds, new Comparator<IBuildDetail>() {
        @Override
        public int compare(final IBuildDetail o1, final IBuildDetail o2) {
            return o2.getFinishTime().compareTo(o1.getFinishTime());
        }
    });

    for (int i = 0; i < MAX_COMPLETED_BUILDS && i < completedBuilds.length; i++) {
        list.add(completedBuilds[i]);
    }

    buildItems = list.toArray();
}

From source file:net.rrm.ehour.ui.timesheet.panel.TimesheetRowList.java

private void addInputCells(ListItem<TimesheetRow> item, final TimesheetRow row) {
    Calendar currentDate = (Calendar) row.getFirstDayOfWeekDate().clone();

    ProjectAssignment assignment = row.getProjectAssignment();
    final DateRange range = new DateRange(assignment.getDateStart(), assignment.getDateEnd());

    final List<Calendar> dates = Lists.newArrayList();

    for (int i = 1; i <= 7; i++, currentDate.add(Calendar.DAY_OF_YEAR, 1)) {
        dates.add((Calendar) currentDate.clone());
    }//from  ww  w .  ja  v a 2 s.com

    item.add(new ListView<Calendar>("days", dates) {
        @Override
        protected void populateItem(ListItem<Calendar> item) {
            Calendar currentDate = item.getModelObject();

            int index = currentDate.get(Calendar.DAY_OF_WEEK) - 1;

            TimesheetCell timesheetCell = row.getTimesheetCells()[index];

            DayStatus dayStatus = determineDayStatus(timesheetCell, currentDate, range);

            Component day;

            switch (dayStatus) {
            case HIDDEN:
            default:
                day = createEmptyTimesheetEntry(DAY_ID);
                item.add(new WebMarkupContainer(DAY_OPTIONS_ID));
                break;
            case OPEN:
                day = createInputTimesheetEntry(DAY_ID, row, index);
                item.add(renderOptions(DAY_OPTIONS_ID, timesheetCell, dayStatus));
                break;
            case LOCKED:
                day = createLockedTimesheetEntry(DAY_ID, row, index);
                item.add(renderOptions(DAY_OPTIONS_ID, timesheetCell, dayStatus));
                item.add(AttributeModifier.append("class", "locked"));
                break;
            }

            String cssClass = "weekday";

            if (dayStatus == DayStatus.LOCKED) {
                cssClass += " lockedCell";
            } else if (item.getIndex() == 0) {
                cssClass = "sunday";
            } else if (item.getIndex() == 6) {
                cssClass = "saturday";
            }

            day.add(AttributeModifier.replace("class", cssClass));
            item.add(day);
        }
    });
}

From source file:co.com.runt.runistac.logica.TareasLogica.java

@Schedule(hour = "12", minute = "03", second = "0", persistent = false)
public void generarAlertasSinCarroceria() {
    if (nombreNodo()) {
        String valor = parametroSistemaLogica.obtener("FECHA_FIN_VIGENCIA").getValor();
        String valor1 = parametroSistemaLogica.obtener("DIAS_PARA_ALERTA_SIN_CARROCERIA").getValor();
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DAY_OF_YEAR, Integer.valueOf(valor1));
        if (sdf.format(c.getTime()).compareTo(valor) == 0) {
            try {
                int conteo = automotorLogica.validarSinCarroceria();
                registroTarea(conteo, TipoTarea.ALERTA_SIN_CARROCERIA);
            } catch (Throwable e) {
                registroTarea(0, TipoTarea.ALERTA_SIN_CARROCERIA, e);
            }/*from ww w. j  a v  a2s  .  c  o  m*/
        }
    }
}

From source file:es.ficonlan.web.backend.test.eventservice.EventServiceTest.java

@Test
public void testAddParticipantToEvent() throws ServiceException {
    Session anonymousSession = userService.newAnonymousSession();
    Session s = userService.login(anonymousSession.getSessionId(), ADMIN_LOGIN, ADMIN_PASS);
    Calendar regCloseDate = Calendar.getInstance();
    regCloseDate.add(Calendar.DAY_OF_YEAR, 1);
    Calendar dateStart = Calendar.getInstance();
    dateStart.add(Calendar.DAY_OF_YEAR, -1);
    Calendar dateEnd = Calendar.getInstance();
    dateEnd.add(Calendar.DAY_OF_YEAR, 1);

    Event event = new Event(0, "FicOnLan 2014", "FicOnLan 2014", 150, dateStart, dateEnd, dateStart, dateEnd,
            null, null, null, null, null);
    eventDao.save(event);//from   w ww . j a  v a2s  . c  o m
    User user = userService.addUser(anonymousSession.getSessionId(),
            new User("User1", "login1", "pass", "12345678R", "user1@gmail.com", "690047407", "L"));
    Registration r = eventService.addParticipantToEvent(s.getSessionId(), user.getUserId(), event.getEventId());
    assertTrue(r != null);
    assertTrue(r.getUser().getUserId() == user.getUserId());
    assertTrue(r.getEvent().getEventId() == event.getEventId());
    assertTrue(r.getState() == RegistrationState.registered);
}

From source file:DateUtility.java

public static boolean isSameDay(Calendar calA, Calendar calB) {
    return (calA.get(Calendar.YEAR) == calB.get(Calendar.YEAR)
            && calA.get(Calendar.DAY_OF_YEAR) == calB.get(Calendar.DAY_OF_YEAR));
}

From source file:helper.util.DateHelper.java

/**
 * @return the days between two calendars, including dealing with year boundary
 **//*  ww  w  .  j  av  a2  s .  co m*/
public static int calculateIntervalInDays(CalendarRange range) {
    Calendar start = range.getStart();
    Calendar end = range.getEnd();
    int startYear = start.get(Calendar.YEAR);
    int endYear = end.get(Calendar.YEAR);
    if (startYear == endYear) {
        if (start.get(Calendar.DAY_OF_YEAR) == end.get(Calendar.DAY_OF_YEAR)) {
            return 0;
        }
        return end.get(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR);
    } else if (start.getTimeInMillis() < end.getTimeInMillis()) {
        // let the calendar do the thinking, just increment date until we hit our end date
        Calendar startCopy = (Calendar) start.clone();
        int days = 0;
        while (true) {
            startCopy.add(Calendar.DATE, 1);
            days++;
            if (startCopy.get(Calendar.DAY_OF_YEAR) == end.get(Calendar.DAY_OF_YEAR)) {
                return days;
            }
        }
    } else {
        // let the calendar do the thinking, just increment date until we hit our end date
        Calendar startCopy = (Calendar) start.clone();
        int days = 0;
        while (true) {
            startCopy.add(Calendar.DATE, -1);
            days--;
            if (startCopy.get(Calendar.DAY_OF_YEAR) == end.get(Calendar.DAY_OF_YEAR)) {
                return days;
            }
        }
    }
}

From source file:es.udc.fic.test.model.CerrarMangaTest.java

@Test
public void cerrarMangaTCompensadoSinPenal() {
    //Creamos una sola regata con la instancia de todos los objetos en memoria
    Regata regata = new Regata();
    regata.setNombre("Mock Regata");
    regata.setDescripcion("Mock Desc");
    regataDao.save(regata);/*w  w  w . java  2  s. co m*/

    Tipo tipoCrucero = new Tipo("Crucero", "Desc Crucero", false);
    tipoDao.save(tipoCrucero);
    Tipo tipoLanchas = new Tipo("Lanchas", "Desc Lanchas", true);
    tipoDao.save(tipoLanchas);

    Barco b1 = new Barco(204566, "Juan Sebastian El Cano", tipoCrucero, (float) 1.5, "Lagoon 421");
    inscripcionService.inscribir(regata, b1, "Iago Surez");

    Barco b2 = new Barco(199012, "El Holandes Errante", tipoCrucero, (float) 2.5, "SWAN 66 FD");
    inscripcionService.inscribir(regata, b2, "Samu Paredes");

    Barco b3 = new Barco(201402, "La Perla Negra", tipoCrucero, (float) 1.5, "X6");
    inscripcionService.inscribir(regata, b3, "Adrian Pallas");
    //Ponemos otro tipo para ver como funciona la clasificacion
    Barco b4 = new Barco(206745, "Apolo", tipoLanchas, null, "Laser Radial");
    inscripcionService.inscribir(regata, b4, "Diego Bascoy");

    Calendar dia1 = Calendar.getInstance();
    dia1.add(Calendar.DAY_OF_YEAR, -18);

    Calendar dia2 = Calendar.getInstance();
    dia2.add(Calendar.DAY_OF_YEAR, -18);
    dia2.add(Calendar.HOUR, 2);

    Calendar dia3 = Calendar.getInstance();
    dia3.add(Calendar.DAY_OF_YEAR, -17);

    Manga manga1 = new Manga(dia1, regata, null, 100);

    List<Posicion> posManga1 = new ArrayList<Posicion>();

    //Velas Ligeras
    //Tiempo -> 3200 + 1.5 * 100  = 3350 -> Primero   
    posManga1.add(new Posicion((long) 3200, Posicion.Penalizacion.NAN, manga1, b1, (long) 0));
    //Tiempo-> 3300 + 2.5 * 100 = 3550 -> Segundo
    posManga1.add(new Posicion((long) 3300, Posicion.Penalizacion.NAN, manga1, b2, (long) 0));
    //Tiempo -> 3500 + 1.5 * 100 = 3650 -> Tercero
    posManga1.add(new Posicion((long) 3500, Posicion.Penalizacion.NAN, manga1, b3, (long) 0));

    //Lanchas
    //Primero -> Puntos 1
    posManga1.add(new Posicion((long) 3300, Posicion.Penalizacion.NAN, manga1, b4, (long) 0));

    manga1.setPosiciones(posManga1);
    mangaService.cerrarYGuardarManga(manga1);
    regata.addManga(manga1);

    //Comprobamos que todas las posiciones tienen puntos mayores que 0
    for (Posicion p : manga1.getPosiciones()) {
        assertTrue(p.getPuntos() > 0);
    }

    //Comprobamos que los puntos son correctos
    //Guardamos las posiciones por tipos
    Map<Barco, Posicion> posPorBarco = new HashMap<Barco, Posicion>();
    for (Posicion p : manga1.getPosiciones()) {
        //Aadimos la posicionActual
        posPorBarco.put(p.getBarco(), p);
    }

    //Velas Ligeras
    //Primero -> Puntos 1 
    assertEquals(posPorBarco.get(b1).getPuntos(), 1);
    //Segundo-> Puntos 2
    assertEquals(posPorBarco.get(b2).getPuntos(), 2);
    //Tercero -> Puntos 3
    assertEquals(posPorBarco.get(b3).getPuntos(), 3);

    //Lanchas
    //Primero -> Puntos 1
    assertEquals(posPorBarco.get(b4).getPuntos(), 1);

}

From source file:Main.java

/**
 * Calendar-version for fragment-calculation in any unit
 * /*from   www.  ja  va 2 s  .  c om*/
 * @param calendar the calendar to work with, not null
 * @param fragment the Calendar field part of calendar to calculate 
 * @param unit Calendar field defining the unit
 * @return number of units within the fragment of the calendar
 * @throws IllegalArgumentException if the date is <code>null</code> or 
 * fragment is not supported
 * @since 2.4
 */
private static long getFragment(Calendar calendar, int fragment, int unit) {
    if (calendar == null) {
        throw new IllegalArgumentException("The date must not be null");
    }
    long millisPerUnit = getMillisPerUnit(unit);
    long result = 0;

    // Fragments bigger than a day require a breakdown to days
    switch (fragment) {
    case Calendar.YEAR:
        result += (calendar.get(Calendar.DAY_OF_YEAR) * MILLIS_PER_DAY) / millisPerUnit;
        break;
    case Calendar.MONTH:
        result += (calendar.get(Calendar.DAY_OF_MONTH) * MILLIS_PER_DAY) / millisPerUnit;
        break;
    }

    switch (fragment) {
    // Number of days already calculated for these cases
    case Calendar.YEAR:
    case Calendar.MONTH:

        // The rest of the valid cases
    case Calendar.DAY_OF_YEAR:
    case Calendar.DATE:
        result += (calendar.get(Calendar.HOUR_OF_DAY) * MILLIS_PER_HOUR) / millisPerUnit;
    case Calendar.HOUR_OF_DAY:
        result += (calendar.get(Calendar.MINUTE) * MILLIS_PER_MINUTE) / millisPerUnit;
    case Calendar.MINUTE:
        result += (calendar.get(Calendar.SECOND) * MILLIS_PER_SECOND) / millisPerUnit;
    case Calendar.SECOND:
        result += (calendar.get(Calendar.MILLISECOND) * 1) / millisPerUnit;
        break;
    case Calendar.MILLISECOND:
        break;//never useful
    default:
        throw new IllegalArgumentException("The fragment " + fragment + " is not supported");
    }
    return result;
}

From source file:com.netflix.simianarmy.basic.BasicCalendar.java

/**
 * Day of year./* w  w w.  ja v  a  2  s.  c o m*/
 *
 * @param year
 *            the year
 * @param month
 *            the month
 * @param dayOfWeek
 *            the day of week
 * @param weekInMonth
 *            the week in month
 * @return the day of the year
 */
private int dayOfYear(int year, int month, int dayOfWeek, int weekInMonth) {
    Calendar holiday = now();
    holiday.set(Calendar.YEAR, year);
    holiday.set(Calendar.MONTH, month);
    holiday.set(Calendar.DAY_OF_WEEK, dayOfWeek);
    holiday.set(Calendar.DAY_OF_WEEK_IN_MONTH, weekInMonth);
    return holiday.get(Calendar.DAY_OF_YEAR);
}

From source file:HSSFDateUtil.java

/**
 * Given a Calendar, return the number of days since 1600/12/31.
 * //from  w  ww. j  a  v  a 2 s . c  o m
 * @return days number of days since 1600/12/31
 * @param cal
 *          the Calendar
 * @exception IllegalArgumentException
 *              if date is invalid
 */

private static int absoluteDay(final Calendar cal) {
    return cal.get(Calendar.DAY_OF_YEAR) + daysInPriorYears(cal.get(Calendar.YEAR));
}