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.greenline.guahao.biz.util.DateUtils.java

public static String getTimeDesc(Date date) {
    if (null == date) {
        return null;
    }//from  w  w w.  j  ava2  s .  c  o m
    Calendar now = Calendar.getInstance();
    Calendar time = Calendar.getInstance();
    time.setTime(date);
    // ???
    long t = (now.getTimeInMillis() - time.getTimeInMillis()) / 1000;
    // ?2012-01-08?2012-01-08 09:20
    if ((t < 0) || (t > ((now.get(Calendar.HOUR_OF_DAY) + 24) * 3600 + now.get(Calendar.MINUTE) + 60
            + now.get(Calendar.SECOND))) || (t < 0)) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
        return df.format(date);
    }

    // 1?" 09:30"
    if (t > 3600) {
        SimpleDateFormat df = new SimpleDateFormat("HH:mm");
        String str = df.format(date);
        int day_time = time.get(Calendar.DAY_OF_YEAR);// 
        int now_time = now.get(Calendar.DAY_OF_YEAR);// ?

        // 1?"11:59"
        if (day_time < now_time) {
            str = " ".concat(str);
        } else {
            str = " ".concat(str);
        }
        return str;
    }
    // 11?"XX?"
    if (t >= 60) {
        return t / 60 + "?";
    }
    // ?1
    return "";
}

From source file:com.ms.app.web.commons.tools.DateViewTools.java

public static String yesterday() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    return getFormat(SIMPLE_DATE_FORMAT_PATTERN).format(calendar.getTime());
}

From source file:com.lk.ofo.util.DateUtil.java

/**
 * /*from  www  .j  av  a  2  s .c o  m*/
 *
 * @param fDate
 * @param oDate
 * @return
 */
public static int dateSubtract(Date fDate, Date oDate) {
    Calendar aCalendar = Calendar.getInstance();
    aCalendar.setTime(fDate);
    int startDay = aCalendar.get(Calendar.DAY_OF_YEAR);
    int startYear = aCalendar.get(Calendar.YEAR);
    aCalendar.setTime(oDate);
    int endDay = aCalendar.get(Calendar.DAY_OF_YEAR);
    int endyear = aCalendar.get(Calendar.YEAR);

    return (endyear - startYear) * ONE_YEAR + (endDay - startDay);

}

From source file:edu.monash.merc.util.DMUtil.java

public static boolean isToday(Date dateTime) {
    Calendar someCa = GregorianCalendar.getInstance();
    someCa.setTime(dateTime);//from   w  w w.  ja  v a  2  s .  c  o  m

    int syear = someCa.get(Calendar.YEAR);
    int smonth = someCa.get(Calendar.MONTH);
    int sday = someCa.get(Calendar.DAY_OF_YEAR);

    Calendar currentCa = GregorianCalendar.getInstance();

    int cyear = currentCa.get(Calendar.YEAR);
    int cmonth = currentCa.get(Calendar.MONTH);
    int cday = currentCa.get(Calendar.DAY_OF_YEAR);
    if (syear == cyear && smonth == cmonth && sday == cday) {
        return true;
    }
    return false;
}

From source file:net.audumla.climate.bom.ObserverTest.java

@Test
public void testAllStations() throws IOException {
    ClimateCalculations cc = new ClimateCalculations();
    Calendar c = GregorianCalendar.getInstance();
    c.add(Calendar.DAY_OF_YEAR, -3);
    Date now = c.getTime();//from   ww w . j  a v  a  2 s  . com
    CSVReader csv = new CSVReader(BOMDataLoader.instance().getData(BOMDataLoader.FTP, BOMDataLoader.BOMFTP,
            BOMClimateObserverCatalogue.generateStationCatalogueURL()));
    String[] line;
    double error = 0;
    double count = 0;
    while ((line = csv.readNext()) != null && count < 20) {
        try {
            if (line.length > 2) {
                ++count;
                String id = line[0].replace("\"", "");
                ClimateDataSource source = ClimateDataSourceFactory.getInstance().newInstance();
                source.setId(id);
                ClimateObserver station = ClimateObserverCatalogue.getInstance().getClimateObserver(source);
                double v2 = station.getClimateData(now).getEvapotranspiration();
                double v1 = cc.calculateEvapotranspiration(station, now, 24);
                double e = 1 - Math.min(v1, v2) / Math.max(v1, v2);
                //System.out.println(e);
                error += e;
            }
        } catch (Exception e) {
            //System.out.println("Station Catalogue error - " + e);
        }

    }
    Assert.assertEquals(error / count, 0.01, 0.01);

}

From source file:at.ac.uniklu.mobile.sportal.api.UnikluSportalApiClient.java

public List<Termin> getTermineHeute(Integer[] lvkeys) throws ApiClientException, ApiServerException {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date todayBegin = calendar.getTime();
    calendar.add(Calendar.DAY_OF_YEAR, 1);
    Date todayEnd = calendar.getTime();
    return getTermine(todayBegin, todayEnd, null, lvkeys);
}

From source file:DateUtils.java

/**
 * <p>Checks if the first calendar date is after the second calendar date ignoring time.</p>
 * @param cal1 the first calendar, not altered, not null.
 * @param cal2 the second calendar, not altered, not null.
 * @return true if cal1 date is after cal2 date ignoring time.
 * @throws IllegalArgumentException if either of the calendars are <code>null</code>
 *//* w  w  w.  j  a  v  a 2s . c  om*/
public static boolean isAfterDay(Calendar cal1, Calendar cal2) {
    if (cal1 == null || cal2 == null) {
        throw new IllegalArgumentException("The dates must not be null");
    }
    if (cal1.get(Calendar.ERA) < cal2.get(Calendar.ERA))
        return false;
    if (cal1.get(Calendar.ERA) > cal2.get(Calendar.ERA))
        return true;
    if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR))
        return false;
    if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR))
        return true;
    return cal1.get(Calendar.DAY_OF_YEAR) > cal2.get(Calendar.DAY_OF_YEAR);
}

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

@Test
public void getClasificacionTest() {

    //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  .  j  a  v  a  2  s .c o m

    Tipo tipoCatamaran = new Tipo("Catamarn", "Desc Catamarn", false);
    tipoDao.save(tipoCatamaran);

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

    Tipo tipoLigero = new Tipo("Vela ligera", "Desc Vela ligera", true);
    tipoDao.save(tipoLigero);

    Barco b1 = new Barco(204566, "Juan Sebastian El Cano", tipoCatamaran, new Float(1.5), "Lagoon 421");
    inscripcionService.inscribir(regata, b1, "Iago Surez");
    Barco b2 = new Barco(199012, "El Holandes Errante", tipoCrucero, new Float(2.5), "SWAN 66 FD");
    inscripcionService.inscribir(regata, b2, "Samu Paredes");
    Barco b3 = new Barco(201402, "La Perla Negra", tipoCrucero, new Float(1.5), "X6");
    inscripcionService.inscribir(regata, b3, "Adrian Pallas");
    Barco b4 = new Barco(202102, "La Pinta", tipoCrucero, new Float(1.5), "X6");
    inscripcionService.inscribir(regata, b4, "Pedro Cabalar");
    Barco b5 = new Barco(182345, "Venus", tipoLigero, null, "Laser Standar");
    inscripcionService.inscribir(regata, b5, "Jesus Lopez");
    Barco b6 = new Barco(206745, "Apolo", tipoLigero, null, "Laser Radial");
    inscripcionService.inscribir(regata, b6, "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);
    Manga manga2 = new Manga(dia2, regata, null, 100);
    Manga manga3 = new Manga(dia3, regata, null, 100);

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

    posManga1.add(new Posicion(new Long(3600), Posicion.Penalizacion.ZFP, manga1, b1, (long) 0));
    posManga1.add(new Posicion(new Long(3700), Posicion.Penalizacion.NAN, manga1, b2, (long) 0));
    posManga1.add(new Posicion(new Long(3750), Posicion.Penalizacion.ZFP, manga1, b3, (long) 0));
    posManga1.add(new Posicion(new Long(3900), Posicion.Penalizacion.NAN, manga1, b4, (long) 0));
    posManga1.add(new Posicion(new Long(3400), Posicion.Penalizacion.NAN, manga1, b5, (long) 0));
    posManga1.add(new Posicion(new Long(2400), Posicion.Penalizacion.SCP, manga1, b6, (long) 0));
    manga1.setPosiciones(posManga1);

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

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

    posManga2.add(new Posicion(new Long(3400), Posicion.Penalizacion.ZFP, manga2, b1, (long) 0));
    posManga2.add(new Posicion(new Long(3600), Posicion.Penalizacion.NAN, manga2, b2, (long) 0));
    posManga2.add(new Posicion(new Long(3950), Posicion.Penalizacion.ZFP, manga2, b3, (long) 0));
    posManga2.add(new Posicion(new Long(3200), Posicion.Penalizacion.NAN, manga2, b4, (long) 0));
    posManga2.add(new Posicion(new Long(3100), Posicion.Penalizacion.ZFP, manga2, b5, (long) 0));
    posManga2.add(new Posicion(new Long(2800), Posicion.Penalizacion.SCP, manga2, b6, (long) 0));
    manga2.setPosiciones(posManga2);
    mangaService.cerrarYGuardarManga(manga2);
    regata.addManga(manga2);

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

    posManga3.add(new Posicion(new Long(13500), Posicion.Penalizacion.SCP, manga3, b1, (long) 0));
    posManga3.add(new Posicion(new Long(13200), Posicion.Penalizacion.NAN, manga3, b2, (long) 0));
    posManga3.add(new Posicion(new Long(13350), Posicion.Penalizacion.NAN, manga3, b3, (long) 0));
    posManga3.add(new Posicion(new Long(13900), Posicion.Penalizacion.ZFP, manga3, b4, (long) 0));
    posManga3.add(new Posicion(new Long(14400), Posicion.Penalizacion.NAN, manga3, b5, (long) 0));
    posManga3.add(new Posicion(new Long(15400), Posicion.Penalizacion.SCP, manga3, b6, (long) 0));
    manga3.setPosiciones(posManga3);
    mangaService.cerrarYGuardarManga(manga3);
    regata.addManga(manga3);

    //        //Mostrar los datos:
    //        for(List<Posicion> lp : posicionesGeneralFinal){
    //            int total = 0;
    //            System.out.print(lp.get(0).getBarco().getVela() + ": ");
    //            for(Posicion p : lp){
    //                System.out.print(p.getPuntos() + " | ");
    //                total += p.getPuntos();
    //            }
    //            System.out.println("Tot: " + total);
    //        }

    //Testeamos la clasificacion Final por Tipo
    Tipo tipo = tipoCrucero;
    List<List<Posicion>> posicionesFinalTipo = regataService.getClasificacion(regata, null, tipo);

    //Comprobamos que estn todos los barcos y que no estn repetido
    assertEquals(inscripcionService.getInscripcionesByTipo(regata, tipo).size(), posicionesFinalTipo.size());

    //Comprobamos que hay tantas posiciones como mangas
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        assertEquals(posBarco.size(), regata.getMangas().size());
    }

    //Comprobamos que todas las posiciones de la misma sublista pertenecen 
    // al mismo Barco.
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        Barco barcoAct = posBarco.get(0).getBarco();
        for (Posicion p : posBarco) {
            assertEquals(barcoAct, p.getBarco());
        }
    }

    Calendar fechaAnterior = null;
    //Comprobamos que las listas internas estn ordenadas por la fecha de 
    // la manga
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        for (int i = 0; i < posBarco.size(); i++) {
            Calendar fechaActual = posBarco.get(i).getManga().getFecha();
            if (i > 0) {
                //Comparamos los calendars:
                assertTrue(fechaAnterior.before(fechaActual));
            }
            fechaAnterior = fechaActual;
        }
    }

    int puntActual;
    int puntAnterior = 0;
    //Comprobamos que el resultado viene bien ordenado por la puntuacion
    for (List<Posicion> posBarco : posicionesFinalTipo) {
        puntActual = 0;
        for (Posicion p : posBarco) {
            puntActual += p.getPuntos();
        }
        assertTrue(puntActual >= puntAnterior);
        puntAnterior = puntActual;
    }

    for (List<Posicion> posBarco : posicionesFinalTipo) {
        for (Posicion posicion : posBarco) {
            assertEquals(tipo, posicion.getBarco().getTipo());
        }
    }

    //Testeamos la clasificacion General por Dia
    Calendar dia = dia2;
    List<List<Posicion>> posicionesDiaGeneral = regataService.getClasificacion(regata, dia, null);

    for (List<Posicion> posBarco : posicionesDiaGeneral) {
        for (Posicion posicion : posBarco) {
            assertTrue(TimeUtil.compareByDay(dia, posicion.getManga().getFecha()));
        }
    }

    //Testeamos la clisificacion de un Tipo en un Dia
    Tipo tipoEspecifico = tipoCrucero;
    Calendar diaEspecifico = dia2;
    List<List<Posicion>> posicionesDiaTipo = regataService.getClasificacion(regata, diaEspecifico,
            tipoEspecifico);

    for (List<Posicion> posBarco : posicionesDiaTipo) {
        for (Posicion posicion : posBarco) {
            assertEquals(tipoEspecifico, posicion.getBarco().getTipo());
            assertTrue(TimeUtil.compareByDay(diaEspecifico, posicion.getManga().getFecha()));
        }
    }
}

From source file:com.ms.app.web.commons.tools.DateViewTools.java

public static String yesterdayFull() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_YEAR, -1);
    return getFormat(FULL_DATE_FORMAT_PATTERN).format(calendar.getTime());
}

From source file:com.bjorsond.android.timeline.utilities.Utilities.java

public static boolean isSameHour(Date date1, Date date2) {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    cal1.setTime(date1);/*w w w  .  jav  a 2 s  .  c o  m*/
    cal2.setTime(date2);
    boolean sameHour = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
            && cal1.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY);
    return sameHour;
}