Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

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

Prototype

int HOUR

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

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:helper.lang.DateHelperTest.java

@Test
public void testGetRangeDaysBeforeTwoDays() {
    int days = 2;
    Calendar localtime = Calendar.getInstance();
    CalendarRange range = DateHelper.getRangeFullDaysBefore(localtime, days);
    Calendar start = range.getStart();
    Calendar end = range.getEnd();
    System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(start));
    System.out.println(DateFormatUtils.SMTP_DATETIME_FORMAT.format(end));

    // end date is midnight of date passed in
    assertEquals(localtime.get(Calendar.YEAR), end.get(Calendar.YEAR));
    assertEquals(localtime.get(Calendar.MONTH), end.get(Calendar.MONTH));
    assertEquals(localtime.get(Calendar.DATE), end.get(Calendar.DATE));
    assertEquals(0, end.get(Calendar.HOUR));
    assertEquals(0, end.get(Calendar.MINUTE));
    assertEquals(0, end.get(Calendar.SECOND));
    assertEquals(0, end.get(Calendar.MILLISECOND));
    assertEquals(0, end.get(Calendar.HOUR_OF_DAY));
    assertEquals(DateHelper.UTC_TIME_ZONE, end.getTimeZone());

    // start date is 11:59:59 or 'days' time
    localtime.add(Calendar.DATE, -(days + 2));
    assertEquals(localtime.get(Calendar.YEAR), start.get(Calendar.YEAR));
    assertEquals(localtime.get(Calendar.MONTH), start.get(Calendar.MONTH));
    assertEquals(localtime.get(Calendar.DATE), start.get(Calendar.DATE));
    assertEquals(11, start.get(Calendar.HOUR));
    assertEquals(23, start.get(Calendar.HOUR_OF_DAY));
    assertEquals(59, start.get(Calendar.MINUTE));
    assertEquals(59, start.get(Calendar.SECOND));
    assertEquals(999, start.get(Calendar.MILLISECOND));
    assertEquals(DateHelper.UTC_TIME_ZONE, start.getTimeZone());
}

From source file:com.sentaca.spring.smpp.jsmpp.JSMPPGateway.java

private String formatTimeFromHours(int timeInHours) {
    if (timeInHours < 0) {
        return null;
    }/*from   www  .  j ava 2s .co  m*/
    Calendar cDate = Calendar.getInstance();
    cDate.clear();
    cDate.set(Calendar.YEAR, 0);
    cDate.add(Calendar.HOUR, timeInHours);

    int years = cDate.get(Calendar.YEAR) - cDate.getMinimum(Calendar.YEAR);
    int months = cDate.get(Calendar.MONTH);
    int days = cDate.get(Calendar.DAY_OF_MONTH) - 1;
    int hours = cDate.get(Calendar.HOUR_OF_DAY);

    String yearsString = (years < 10) ? "0" + years : years + "";
    String monthsString = (months < 10) ? "0" + months : months + "";
    String daysString = (days < 10) ? "0" + days : days + "";
    String hoursString = (hours < 10) ? "0" + hours : hours + "";

    return yearsString + monthsString + daysString + hoursString + "0000000R";
}

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  .j av a 2 s  .c  om*/

    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:CalendarUtils.java

private static void modify(Calendar val, int field, boolean round) {
    boolean roundUp = false;
    for (int i = 0; i < fields.length; i++) {
        for (int j = 0; j < fields[i].length; j++) {
            if (fields[i][j] == field) {
                //This is our field... we stop looping
                if (round && roundUp) {
                    if (field == CalendarUtils.SEMI_MONTH) {
                        //This is a special case that's hard to generalize
                        //If the date is 1, we round up to 16, otherwise
                        //  we subtract 15 days and add 1 month
                        if (val.get(Calendar.DATE) == 1) {
                            val.add(Calendar.DATE, 15);
                        } else {
                            val.add(Calendar.DATE, -15);
                            val.add(Calendar.MONTH, 1);
                        }/*from  w  w  w .  ja  v  a 2  s  .  c o  m*/
                    } else {
                        //We need at add one to this field since the
                        //  last number causes us to round up
                        val.add(fields[i][0], 1);
                    }
                }
                return;
            }
        }
        //We have various fields that are not easy roundings
        int offset = 0;
        boolean offsetSet = false;
        //These are special types of fields that require different rounding rules
        switch (field) {
        case CalendarUtils.SEMI_MONTH:
            if (fields[i][0] == Calendar.DATE) {
                //If we're going to drop the DATE field's value,
                //  we want to do this our own way.
                //We need to subtrace 1 since the date has a minimum of 1
                offset = val.get(Calendar.DATE) - 1;
                //If we're above 15 days adjustment, that means we're in the
                //  bottom half of the month and should stay accordingly.
                if (offset >= 15) {
                    offset -= 15;
                }
                //Record whether we're in the top or bottom half of that range
                roundUp = offset > 7;
                offsetSet = true;
            }
            break;
        case Calendar.AM_PM:
            if (fields[i][0] == Calendar.HOUR) {
                //If we're going to drop the HOUR field's value,
                //  we want to do this our own way.
                offset = val.get(Calendar.HOUR);
                if (offset >= 12) {
                    offset -= 12;
                }
                roundUp = offset > 6;
                offsetSet = true;
            }
            break;
        }
        if (!offsetSet) {
            int min = val.getActualMinimum(fields[i][0]);
            int max = val.getActualMaximum(fields[i][0]);
            //Calculate the offset from the minimum allowed value
            offset = val.get(fields[i][0]) - min;
            //Set roundUp if this is more than half way between the minimum and maximum
            roundUp = offset > ((max - min) / 2);
        }
        //We need to remove this field
        val.add(fields[i][0], -offset);
    }
    throw new RuntimeException("We do not support that field.");

}

From source file:configuration.Util.java

/**
 * This return a time code JJMMYYMMSS used by the hashcode
 * @return/*from w w w  .j a  v  a 2s  . c o m*/
 */
public static int returnTimeCode() {
    Calendar today = Calendar.getInstance();
    int[] tt = { 0, 0, 0, 0, 0, 0 };
    tt[0] = today.get(Calendar.DAY_OF_MONTH);
    tt[1] = today.get(Calendar.MONTH);
    tt[2] = today.get(Calendar.HOUR);
    tt[3] = today.get(Calendar.MINUTE);
    return (tt[0] * 1000000 + tt[1] * 10000 + tt[2] * 100 + tt[3]);
}

From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java

private String getLabel(int scale, GregorianCalendar date) {

    String label = null;/*from  w  ww  .jav a  2 s. c  om*/

    SimpleDateFormat formatter;

    switch (scale) {
    case Calendar.HOUR:
        formatter = new SimpleDateFormat("kk00 yyyy-MMM-d");
        label = formatter.format(date.getTime());
        break;
    case Calendar.DAY_OF_MONTH:
        formatter = new SimpleDateFormat("yyyy-MMM-d");
        label = formatter.format(date.getTime());
        break;
    case Calendar.WEEK_OF_YEAR:
        formatter = new SimpleDateFormat("w yyyy");
        label = formatter.format(date.getTime());
        break;
    case Calendar.MONTH:
        formatter = new SimpleDateFormat("MMM yyyy");
        label = formatter.format(date.getTime());
        break;
    case Calendar.YEAR:
        formatter = new SimpleDateFormat("yyyy");
        label = formatter.format(date.getTime());
        break;
    default:
        label = date.getTime().toString();
    }

    return label;
}

From source file:org.auraframework.integration.test.http.AuraResourceServletHttpTest.java

/**
 * GET with If-Modified-Since header from an hour ago, will return 304 if the UID is correct.
 *///from   w ww. jav a2 s.co  m
@AuraTestLabels("auraSanity")
@Test
public void testGetWithIfModifiedSinceOld() throws Exception {
    String requestContext = getSimpleContext(Format.JS, false);
    String url = "/l/" + AuraTextUtil.urlencode(requestContext) + "/app.js";

    Calendar stamp = Calendar.getInstance();
    stamp.add(Calendar.HOUR, -1);

    Header[] headers = new Header[] { new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE,
            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(stamp.getTime())) };

    HttpGet get = obtainGetMethod(url, headers);
    HttpResponse httpResponse = perform(get);
    int statusCode = getStatusCode(httpResponse);
    String response = getResponseBody(httpResponse);
    get.releaseConnection();

    assertEquals(HttpStatus.SC_NOT_MODIFIED, statusCode);
    assertNull(response);
}

From source file:com.hangum.tadpole.rdb.core.dialog.job.CreateJobDialog.java

/**
 * Create contents of the dialog.//from  w  ww .  j av a 2  s  .  co m
 * 
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite containerInput = (Composite) super.createDialogArea(parent);
    GridLayout gl_containerInput = (GridLayout) containerInput.getLayout();
    gl_containerInput.verticalSpacing = 1;
    gl_containerInput.horizontalSpacing = 1;
    gl_containerInput.marginHeight = 1;
    gl_containerInput.marginWidth = 1;

    Composite compositeHead = new Composite(containerInput, SWT.NONE);
    compositeHead.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    compositeHead.setLayout(new GridLayout(2, false));

    lblJobId = new Label(compositeHead, SWT.NONE);
    lblJobId.setText("Job ID");

    textJob = new Text(compositeHead, SWT.BORDER | SWT.READ_ONLY | SWT.RIGHT);
    GridData gd_textJob = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
    gd_textJob.widthHint = 100;
    textJob.setLayoutData(gd_textJob);
    textJob.setText(this.jobDao.getJob() + "");

    Label lblObjectType = new Label(compositeHead, SWT.NONE);
    lblObjectType.setText(Messages.get().CreateJobDialog_FirstStartDatetime);

    Composite composite = new Composite(compositeHead, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    btnSpecify = new Button(composite, SWT.RADIO);
    btnSpecify.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            //  ? ? ?? ?...
            dateStartDate.setEnabled(true);
            dateStartTime.setEnabled(true);

            Calendar c = Calendar.getInstance();
            dateStartDate.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
            dateStartTime.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
            dateStartTime.setTime(c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND));

            createScript();
        }
    });
    btnSpecify.setText(Messages.get().CreateJobDialog_specification);

    btnNext = new Button(composite, SWT.RADIO);
    btnNext.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            dateStartDate.setEnabled(false);
            dateStartTime.setEnabled(false);
            createScript();
        }
    });
    btnNext.setText(Messages.get().CreateJobDialog_NextIterationExecutionCycle);

    if (this.jobDao.getJob() > 0) {
        btnNext.setSelection(true);
    } else {
        btnSpecify.setSelection(true);
    }

    dateStartDate = new DateTime(composite, SWT.BORDER);
    dateStartDate.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            createScript();
        }
    });
    GridData gd_dateStartDate = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_dateStartDate.widthHint = 120;
    dateStartDate.setLayoutData(gd_dateStartDate);

    dateStartTime = new DateTime(composite, SWT.BORDER | SWT.TIME);
    dateStartTime.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            createScript();
        }
    });
    GridData gd_dateStartTime = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
    gd_dateStartTime.widthHint = 120;
    dateStartTime.setLayoutData(gd_dateStartTime);
    dateStartTime.setSize(104, 27);

    Label lblObjectName = new Label(compositeHead, SWT.NONE);
    lblObjectName.setText(Messages.get().CreateJobDialog_IterationExecutionCycle);

    Composite composite_3 = new Composite(compositeHead, SWT.NONE);
    composite_3.setLayout(new GridLayout(2, false));

    comboRepeat = new Combo(composite_3, SWT.READ_ONLY);
    comboRepeat.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            setRepeatString();
            createScript();
        }
    });

    //      "? ? ??",       "7? ??",          "30? ??",             "??  ??",          "?  6?",           
    comboRepeat.setItems(new String[] { Messages.get().EveryNight, Messages.get().Every7Days,
            Messages.get().Every30Days, Messages.get().EverySunday, Messages.get().Every6Morning,
            //       "3? ",                   " 1? ??",          " 1?  6 30?"
            Messages.get().Every3Hours, Messages.get().EveryFristDayMonth, Messages.get().EveryFirstDayAm });
    GridData gd_comboRepeat = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_comboRepeat.widthHint = 250;
    comboRepeat.setLayoutData(gd_comboRepeat);
    comboRepeat.setVisibleItemCount(8);

    textRepeat = new Text(composite_3, SWT.BORDER);
    textRepeat.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            createScript();
        }
    });
    GridData gd_textRepeat = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_textRepeat.minimumWidth = 200;
    gd_textRepeat.widthHint = 300;
    textRepeat.setLayoutData(gd_textRepeat);

    if (this.jobDao.getJob() <= 0) {
        comboRepeat.select(0);
        this.setRepeatString();
    } else {
        textRepeat.setText(this.jobDao.getInterval());
    }

    Label lblParsing = new Label(compositeHead, SWT.NONE);
    lblParsing.setText(Messages.get().CreateJobDialog_analysis);

    Composite composite_2 = new Composite(compositeHead, SWT.NONE);
    composite_2.setLayout(new GridLayout(2, false));

    btnParse = new Button(composite_2, SWT.RADIO);
    btnParse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            createScript();
        }
    });

    GridData gd_btnParse = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_btnParse.widthHint = 120;
    btnParse.setLayoutData(gd_btnParse);
    btnParse.setText("Parse");

    btnNoParse = new Button(composite_2, SWT.RADIO);
    btnNoParse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            createScript();
        }
    });
    GridData gd_btnNoParse = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_btnNoParse.widthHint = 120;
    btnNoParse.setLayoutData(gd_btnNoParse);
    btnNoParse.setText("No Parse");

    btnParse.setSelection(true);

    //  ? ?. ? .
    composite_2.setEnabled(this.jobDao.getJob() <= 0);

    lblNewLabel = new Label(compositeHead, SWT.NONE);
    lblNewLabel.setText("");

    Composite composite_1 = new Composite(compositeHead, SWT.NONE);
    composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    composite_1.setLayout(new GridLayout(3, false));

    comboType = new Combo(composite_1, SWT.READ_ONLY);
    comboType.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (StringUtils.startsWithIgnoreCase(PublicTadpoleDefine.OBJECT_TYPE.PACKAGES.name(),
                    comboType.getText())
                    || StringUtils.startsWithIgnoreCase(PublicTadpoleDefine.OBJECT_TYPE.PROCEDURES.name(),
                            comboType.getText())) {
                initMainObject(comboType.getText());
            } else {
                //PL/SQL ? ?.
                textScript.setText("DBMS_OUTPUT.PUT_LINE('today is ' || to_char(sysdate)); ");
                createScript();
            }
        }
    });
    comboType.setItems(new String[] { "Procedure", "Package", "PL/SQL Block" });
    comboType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboType.select(0);

    comboObject = new Combo(composite_1, SWT.READ_ONLY);
    comboObject.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (StringUtils.startsWithIgnoreCase(PublicTadpoleDefine.OBJECT_TYPE.PACKAGES.name(),
                    comboType.getText())) {
                //  ?  ?(, ) .
                initPackgeBodys(comboObject.getText());
            } else if (StringUtils.startsWithIgnoreCase(PublicTadpoleDefine.OBJECT_TYPE.PROCEDURES.name(),
                    comboType.getText())) {
                // ?  ?? .
                initParameters(comboObject.getSelectionIndex());
            }
            createScript();
        }
    });
    GridData gd_comboObject = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_comboObject.widthHint = 200;
    comboObject.setLayoutData(gd_comboObject);

    comboSubObject = new Combo(composite_1, SWT.READ_ONLY);
    comboSubObject.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            initParameters(comboSubObject.getSelectionIndex());
            createScript();
        }
    });
    comboSubObject.setEnabled(false);
    GridData gd_comboSubObject = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_comboSubObject.widthHint = 200;
    comboSubObject.setLayoutData(gd_comboSubObject);

    SashForm sashForm = new SashForm(containerInput, SWT.VERTICAL);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    grpTables = new Group(sashForm, SWT.NONE);
    GridLayout gl_grpTables = new GridLayout(1, false);
    gl_grpTables.horizontalSpacing = 2;
    gl_grpTables.verticalSpacing = 2;
    gl_grpTables.marginHeight = 2;
    gl_grpTables.marginWidth = 2;
    grpTables.setLayout(gl_grpTables);
    grpTables.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    grpTables.setText(Messages.get().CreateJobDialog_executedScript);

    textScript = new Text(grpTables, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    textScript.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent event) {
            createScript();
        }
    });
    textScript.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            createScript();
        }
    });
    GridData gd_textScript = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_textScript.heightHint = 100;
    gd_textScript.minimumHeight = 100;
    textScript.setLayoutData(gd_textScript);

    textScript.setText(this.jobDao.getWhat());

    label_1 = new Label(grpTables, SWT.NONE);
    label_1.setText(Messages.get().Preview);

    textPreview = new Text(grpTables, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    textPreview.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    initMainObject(this.comboType.getText());

    createScript();

    // google analytic
    AnalyticCaller.track(this.getClass().getName());

    return containerInput;
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java

/**
 * Set the view to MONTH.// w  w  w. j av a  2 s .c om
 */
private void setMonthView() {

    actualStart = (GregorianCalendar) actualDay.clone();
    actualStart.set(Calendar.DAY_OF_MONTH, 1);
    actualStart.set(Calendar.HOUR, 0);
    actualStart.set(Calendar.MINUTE, 0);

    actualEnd = (GregorianCalendar) actualDay.clone();
    actualEnd.set(Calendar.DAY_OF_MONTH, actualEnd.getActualMaximum(Calendar.DAY_OF_MONTH));
    actualEnd.set(Calendar.HOUR, 23);
    actualEnd.set(Calendar.MINUTE, 59);

    actualStart.add(Calendar.HOUR, -1);
    actualEnd.add(Calendar.HOUR, 1);

    actualView = MONTH;

    GregorianCalendar helper = (GregorianCalendar) actualEnd.clone();
    helper.add(Calendar.DATE, -1);

    makeChart(new SimpleDateFormat("MMMM yyyy").format(helper.getTime()));
}

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

@Test
public void testDiaIniDiaFin() {

    //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);//from w  w  w .j  av a  2s  .  c  om

    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), Penalizacion.DNC, manga1, b1, (long) 0));
    posManga1.add(new Posicion(new Long(3700), Penalizacion.OCS, manga1, b2, (long) 0));
    posManga1.add(new Posicion(new Long(3750), Penalizacion.NAN, manga1, b3, (long) 0));
    posManga1.add(new Posicion(new Long(3900), Penalizacion.NAN, manga1, b4, (long) 0));
    posManga1.add(new Posicion(new Long(3400), Penalizacion.SCP, manga1, b5, (long) 0));
    posManga1.add(new Posicion(new Long(2400), Penalizacion.NAN, 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), Penalizacion.NAN, manga2, b1, (long) 0));
    posManga2.add(new Posicion(new Long(3600), Penalizacion.NAN, manga2, b2, (long) 0));
    posManga2.add(new Posicion(new Long(3950), Penalizacion.NAN, manga2, b3, (long) 0));
    posManga2.add(new Posicion(new Long(3200), Penalizacion.RDG, manga2, b4, (long) 0));
    posManga2.add(new Posicion(new Long(3100), Penalizacion.NAN, manga2, b5, (long) 0));
    posManga2.add(new Posicion(new Long(2800), Penalizacion.RET, 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), Penalizacion.RDG, manga3, b1, (long) 0));
    posManga3.add(new Posicion(new Long(13200), Penalizacion.NAN, manga3, b2, (long) 0));
    posManga3.add(new Posicion(new Long(13350), Penalizacion.DGM, manga3, b3, (long) 0));
    posManga3.add(new Posicion(new Long(13900), Penalizacion.NAN, manga3, b4, (long) 0));
    posManga3.add(new Posicion(new Long(14400), Penalizacion.DNE, manga3, b5, (long) 0));
    posManga3.add(new Posicion(new Long(15400), Penalizacion.NAN, manga3, b6, (long) 0));
    manga3.setPosiciones(posManga3);
    mangaService.cerrarYGuardarManga(manga3);
    regata.addManga(manga3);

    assertEquals(dia1, regata.getDiaIni());
    assertEquals(dia3, regata.getDiaFin());

    assertEquals(regata.getDiasManga().size(), 2);
    assertEquals(regata.getDiasManga().get(0), dia1);
    assertEquals(regata.getDiasManga().get(1), dia3);
}