Example usage for java.util Calendar SUNDAY

List of usage examples for java.util Calendar SUNDAY

Introduction

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

Prototype

int SUNDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Sunday.

Usage

From source file:Spring.Repaso02.ProductoDAO.java

public ArrayList<Producto> consultaAll(GregorianCalendar fecha) {
    int dia = (7 + fecha.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY) % 7;
    String selQuery = "select * from TProductos where Disponible = 0 or Disponible = ?";
    List productos = jdbcTemplate.query(selQuery, new Object[] { dia },
            new BeanPropertyRowMapper(Producto.class));
    return (ArrayList) productos;

}

From source file:com.mirth.connect.donkey.model.channel.PollConnectorPropertiesAdvanced.java

public PollConnectorPropertiesAdvanced() {
    weekly = true;/*from  ww w .  ja  v  a 2 s. c  o m*/
    inactiveDays = new boolean[8];

    inactiveDays[Calendar.SUNDAY] = false; // true means to exclude
    inactiveDays[Calendar.MONDAY] = false;
    inactiveDays[Calendar.TUESDAY] = false;
    inactiveDays[Calendar.WEDNESDAY] = false;
    inactiveDays[Calendar.THURSDAY] = false;
    inactiveDays[Calendar.FRIDAY] = false;
    inactiveDays[Calendar.SATURDAY] = false;

    dayOfMonth = 1;

    allDay = true;

    startingHour = 8;
    startingMinute = endingMinute = 0;
    endingHour = 17;
}

From source file:srvmonitor.thGetAgendas.java

@Override
public void run() {
    /*//w  w w . ja  va2 s. c  om
    Recupera Parametros Fecha Actual
    */
    logger.info("Buscando Agendas Activas");

    String[] ids = TimeZone.getAvailableIDs(-4 * 60 * 60 * 1000);
    String clt = ids[0];
    SimpleTimeZone tz = new SimpleTimeZone(-4 * 60 * 60 * 1000, clt);
    tz.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    tz.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(tz);

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH); // Jan = 0, dec = 11
    int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
    int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);

    int hour = calendar.get(Calendar.HOUR); // 12 hour clock
    int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);
    int millisecond = calendar.get(Calendar.MILLISECOND);

    int findHour = 12;
    int findMinutes = 5;

    /*
    calendar.add(Calendar.HOUR_OF_DAY, -1);
    int hourBefore = calendar.get(Calendar.HOUR_OF_DAY);
            
    calendar.add(Calendar.HOUR_OF_DAY, 2);
    int hourAfter = calendar.get(Calendar.HOUR_OF_DAY);
    */

    String posmonth = String.valueOf(month + 1);
    String posdayOfMonth = String.valueOf(dayOfMonth);
    String posdayOfWeek = String.valueOf(dayOfWeek);
    String posweekOfYear = String.valueOf(weekOfYear);
    String posweekOfMonth = String.valueOf(weekOfMonth);
    String poshourOfDay = String.valueOf(hourOfDay);
    String posminute = String.valueOf(minute);
    String possecond = String.valueOf(second);
    String posmillisecond = String.valueOf(millisecond);

    Calendar iteratorCalendar;
    String vSQL;
    String iteratorHour;
    String iteratorMinute;
    Statement stm;
    JSONObject jData;
    JSONObject jDataMinute;
    JSONArray jArray = new JSONArray();
    JSONArray jArrayMinute = new JSONArray();
    String posIteratorHour;
    String posIteratorMinute;

    /*
    Inicializa Lista de Agendas
    */
    gDatos.getLstShowAgendas().clear();
    gDatos.getLstActiveAgendas().clear();

    for (int i = -findHour; i <= findHour; i++) {
        iteratorCalendar = new GregorianCalendar(tz);
        iteratorCalendar.add(Calendar.HOUR_OF_DAY, i);
        iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY));
        posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1);

        vSQL = "select " + iteratorHour
                + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where "
                + "     ageEnable=1 " + "     and substr(month," + posmonth + ",1) = '1'"
                + "     and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + "     and substr(dayOfWeek,"
                + posdayOfWeek + ",1) = '1'" + "     and substr(weekOfYear," + posweekOfYear + ",1) = '1'"
                + "     and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + "     and substr(hourOfDay,"
                + posIteratorHour + ",1) = '1'";
        logger.debug("i: " + i + " vSQL: " + vSQL);
        try {
            stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);
            jData = new JSONObject();

            ResultSet rs = stm.executeQuery(vSQL);
            if (rs != null) {
                while (rs.next()) {
                    jData = new JSONObject();
                    jData.put("horaAgenda", rs.getString("horaAgenda"));
                    jData.put("ageID", rs.getString("ageID"));
                    jData.put("month", rs.getString("month"));
                    jData.put("dayOfMonth", rs.getString("dayOfMonth"));
                    jData.put("weekOfYear", rs.getString("weekOfYear"));
                    jData.put("weekOfMonth", rs.getString("weekOfMonth"));
                    jData.put("hourOfDay", rs.getString("hourOfDay"));
                    jArray.put(jData);
                    gDatos.getLstShowAgendas().add(jData);
                }
            } else {
                jData.put("horaAgenda", iteratorHour);
                jData.put("ageID", "");
                jData.put("month", "");
                jData.put("dayOfMonth", "");
                jData.put("weekOfYear", "");
                jData.put("weekOfMonth", "");
                jData.put("hourOfDay", "");
                jArray.put(jData);
                gDatos.getLstShowAgendas().add(jData);
                System.out.println("No hay registros");
            }
            stm.close();
        } catch (SQLException | JSONException e) {
            logger.error(e.getMessage());
        }
    }

    iteratorCalendar = new GregorianCalendar(tz);
    iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY));
    posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1);

    for (int i = -findMinutes; i <= 0; i++) {
        iteratorCalendar = new GregorianCalendar(tz);
        iteratorCalendar.add(Calendar.MINUTE, i);
        iteratorMinute = String.valueOf(iteratorCalendar.get(Calendar.MINUTE));
        posIteratorMinute = String.valueOf(Integer.valueOf(iteratorMinute) + 1);

        vSQL = "select " + iteratorMinute
                + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where "
                + "     ageEnable=1 " + "     and substr(month," + posmonth + ",1) = '1'"
                + "     and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + "     and substr(dayOfWeek,"
                + posdayOfWeek + ",1) = '1'" + "     and substr(weekOfYear," + posweekOfYear + ",1) = '1'"
                + "     and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + "     and substr(hourOfDay,"
                + posIteratorHour + ",1) = '1'" + "     and substr(minute," + posIteratorMinute + ",1) = '1'";
        logger.debug("i: " + i + " vSQL: " + vSQL);
        try {
            stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);

            ResultSet rs = stm.executeQuery(vSQL);
            if (rs != null) {
                while (rs.next()) {
                    jDataMinute = new JSONObject();
                    jDataMinute.put("horaAgenda", rs.getString("horaAgenda"));
                    jDataMinute.put("ageID", rs.getString("ageID"));
                    jDataMinute.put("month", rs.getString("month"));
                    jDataMinute.put("dayOfMonth", rs.getString("dayOfMonth"));
                    jDataMinute.put("weekOfYear", rs.getString("weekOfYear"));
                    jDataMinute.put("weekOfMonth", rs.getString("weekOfMonth"));
                    jDataMinute.put("hourOfDay", rs.getString("hourOfDay"));
                    jArrayMinute.put(jDataMinute);
                    gDatos.getLstActiveAgendas().add(jDataMinute);
                }
            }
            stm.close();
        } catch (SQLException | JSONException e) {
            logger.error(e.getMessage());
        }
    }

    for (int i = 0; i < gDatos.getLstShowAgendas().size(); i++) {
        logger.debug(gDatos.getLstShowAgendas().get(i).toString());
    }

    for (int i = 0; i < gDatos.getLstActiveAgendas().size(); i++) {
        logger.debug(gDatos.getLstActiveAgendas().get(i).toString());
    }

    logger.info("Finaliza busquenda agendas activas...");
}

From source file:com.easysoft.build.utils.PatchUtil.java

/**
 * ?//from  w  ww  .  j  a v a2 s. co m
 * @param date
 * @return
 */
public static String getBackupDir(Date date, boolean isWeekbug) {
    if (isWeekbug) {//BUG
        Calendar cal = Calendar.getInstance();
        String dir = new SimpleDateFormat("yyyyMMdd/").format(date);

        if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {//08
            dir += "08/";
        } else {//02-07
            dir += new DecimalFormat("00/").format(cal.get(Calendar.DAY_OF_WEEK));
        }
        return dir;
    } else {
        return new SimpleDateFormat("yyyy/MM/dd/").format(date);
    }
}

From source file:service.RentalServiceImpl.java

@Override
public List<Machine> findAllMachinesRentedCurrentWeek() {
    List<Rental> rentals = findAllRentals();
    List<Machine> rentedMachines = new ArrayList<>();

    Calendar c1 = Calendar.getInstance();
    Calendar c2 = Calendar.getInstance();
    c1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    c2.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    for (int i = 0; i < rentals.size(); i++) {
        Rental r = rentals.get(i);/*  w  w  w . jav  a2 s  .  c  om*/
        if ((r.getDateFrom().after(c1.getTime()) && r.getDateTo().after(c2.getTime()))
                || (r.getDateTo().after(c1.getTime()) && r.getDateTo().before(c2.getTime()))) {
            rentedMachines.add(r.getMachine());
        }
    }

    return rentedMachines;
}

From source file:TimeUtil.java

public static String dayStringFormat(long msecs) {
    GregorianCalendar cal = new GregorianCalendar();

    cal.setTime(new Date(msecs));

    int dow = cal.get(Calendar.DAY_OF_WEEK);

    switch (dow) {
    case Calendar.MONDAY:
        return "Monday";
    case Calendar.TUESDAY:
        return "Tuesday";
    case Calendar.WEDNESDAY:
        return "Wednesday";
    case Calendar.THURSDAY:
        return "Thursday";
    case Calendar.FRIDAY:
        return "Friday";
    case Calendar.SATURDAY:
        return "Saturday";
    case Calendar.SUNDAY:
        return "Sunday";
    }/*ww w. j av  a2s.c o  m*/

    return "Unknown";
}

From source file:org.exoplatform.addons.sdpDemo.populator.services.Utils.java

/**
 * Gets the day as int.//from w  w  w . j  a v a2s  .c  om
 *
 * @param day the day
 * @return the day as int
 */
public static int getDayAsInt(String day) {
    if ("monday".equals(day))
        return Calendar.MONDAY;
    else if ("tuesday".equals(day))
        return Calendar.TUESDAY;
    else if ("wednesday".equals(day))
        return Calendar.WEDNESDAY;
    else if ("thursday".equals(day))
        return Calendar.THURSDAY;
    else if ("friday".equals(day))
        return Calendar.FRIDAY;
    else if ("saturday".equals(day))
        return Calendar.SATURDAY;
    else if ("sunday".equals(day))
        return Calendar.SUNDAY;
    return Calendar.MONDAY;
}

From source file:JapaneseCalendar.java

public void paintComponent(Graphics g) {
    int width = 400;
    int height = 400;

    Calendar cal = Calendar.getInstance(locale);
    cal.setTime(new Date());

    String header = cal.getDisplayName(Calendar.MONTH, Calendar.LONG, locale);
    header += " " + cal.get(Calendar.YEAR);

    FontMetrics fm = g.getFontMetrics();
    Insets insets = getInsets();/*  w ww  .j  a  va 2  s.com*/
    g.setColor(Color.black);
    g.drawString(header, (width - fm.stringWidth(header)) / 2, insets.top + fm.getHeight());

    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    String[] weekdayNames = dfs.getShortWeekdays();
    int fieldWidth = (width - insets.left - insets.right) / 7;
    g.drawString(weekdayNames[Calendar.SUNDAY],
            insets.left + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SUNDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.MONDAY],
            insets.left + fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.MONDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.TUESDAY],
            insets.left + 2 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.TUESDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.WEDNESDAY],
            insets.left + 3 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.WEDNESDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.THURSDAY],
            insets.left + 4 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.THURSDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.FRIDAY],
            insets.left + 5 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.FRIDAY])) / 2,
            insets.top + 3 * fm.getHeight());
    g.drawString(weekdayNames[Calendar.SATURDAY],
            insets.left + 6 * fieldWidth + (fieldWidth - fm.stringWidth(weekdayNames[Calendar.SATURDAY])) / 2,
            insets.top + 3 * fm.getHeight());

    int dom = cal.get(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    int col = 0;
    switch (cal.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        col = 1;
        break;

    case Calendar.TUESDAY:
        col = 2;
        break;

    case Calendar.WEDNESDAY:
        col = 3;
        break;

    case Calendar.THURSDAY:
        col = 4;
        break;

    case Calendar.FRIDAY:
        col = 5;
        break;

    case Calendar.SATURDAY:
        col = 6;
    }
    cal.set(Calendar.DAY_OF_MONTH, dom);

    int row = 5 * fm.getHeight();
    for (int i = 1; i <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
        g.drawString("" + i, insets.left + fieldWidth * col + (fieldWidth - fm.stringWidth("" + i)) / 2, row);
        if (++col > 6) {
            col = 0;
            row += fm.getHeight();
        }
    }
}

From source file:calendar.services.transformers.EntryToWeekRowTransformer.java

private BigDecimal setEntryToDayInWeekRow(Entry entry, WeekRow weekRow) {
    Date date = entry.getDate();/*from  www  .  ja v  a  2s.c  om*/
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    Integer dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    BigDecimal entryHours = entry.getHours();
    switch (cal.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.SUNDAY:
        weekRow.setDay7Total(weekRow.getDay7Total().add(entryHours));
        weekRow.setDay7(entry.getDate());
        break;
    case Calendar.MONDAY:
        weekRow.setDay1Total(weekRow.getDay1Total().add(entryHours));
        weekRow.setDay1(entry.getDate());
        break;
    case Calendar.TUESDAY:
        weekRow.setDay2Total(weekRow.getDay2Total().add(entryHours));
        weekRow.setDay2(entry.getDate());
        break;
    case Calendar.WEDNESDAY:
        weekRow.setDay3Total(weekRow.getDay3Total().add(entryHours));
        weekRow.setDay3(entry.getDate());
        break;
    case Calendar.THURSDAY:
        weekRow.setDay4Total(weekRow.getDay4Total().add(entryHours));
        weekRow.setDay4(entry.getDate());
        break;
    case Calendar.FRIDAY:
        weekRow.setDay5Total(weekRow.getDay5Total().add(entryHours));
        weekRow.setDay5(entry.getDate());
        break;
    case Calendar.SATURDAY:
        weekRow.setDay6Total(weekRow.getDay6Total().add(entryHours));
        weekRow.setDay6(entry.getDate());
        break;

    }

    return entryHours;
}

From source file:verdandi.plugin.CurrentWeekPlugin.java

/**
 * Gets the borders of the current week. If a months change is in between then
 * tow will be returned!// w  ww  .j a  v a 2 s.  c o  m
 * 
 * @return
 */
protected List<Pair<Date, Date>> getCurrentWeekBorders() {
    List<Pair<Date, Date>> res = new ArrayList<Pair<Date, Date>>(2);

    Calendar currentWeek = VerdandiModel.getCurrentWeekModel().getCurrentWeek();
    currentWeek.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    setToBeginningOfDay(currentWeek);
    int currentMonth = currentWeek.get(Calendar.MONTH);

    Date dStart = new Date(currentWeek.getTime().getTime());
    Date dEnd;

    while (currentWeek.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
        currentWeek.add(Calendar.DAY_OF_WEEK, 1);
        if (currentWeek.get(Calendar.MONTH) != currentMonth) {
            LOG.debug("Month change detected:" + currentWeek.getTime());
            currentMonth = currentWeek.get(Calendar.MONTH);
            // Einen tag zurck, weil es hier quasi zu spt ist
            currentWeek.add(Calendar.DAY_OF_WEEK, -1);

            setToEndOfDay(currentWeek);
            dEnd = new Date(currentWeek.getTime().getTime());
            res.add(new Pair<Date, Date>(dStart, dEnd));
            currentWeek.add(Calendar.DAY_OF_WEEK, 1);
            setToBeginningOfDay(currentWeek);
            dStart = new Date(currentWeek.getTime().getTime());
            setToEndOfDay(currentWeek);
        }

    }

    currentWeek.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    setToEndOfDay(currentWeek);
    dEnd = new Date(currentWeek.getTime().getTime());
    res.add(new Pair<Date, Date>(dStart, dEnd));

    return res;
}