Example usage for java.util Calendar MONDAY

List of usage examples for java.util Calendar MONDAY

Introduction

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

Prototype

int MONDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Monday.

Usage

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";
    }//from   w  w w .  j a  v  a  2 s  .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 a  2  s  .  c o m*/
 *
 * @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: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 . j  av a2s.c o  m
        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:verdandi.model.WeekSelectorModel.java

public WeekSelectorModel(CurrentWeekModel parentModel) {
    super();
    parent = parentModel;
    cal = parentModel.getCurrentWeek();
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
}

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!/*from   ww  w.  j av  a2s . 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;
}

From source file:org.apache.hadoop.hive.ql.udf.UDFWeekOfYear.java

public UDFWeekOfYear() {
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setMinimalDaysInFirstWeek(4);
}

From source file:org.kuali.student.r2.core.scheduling.util.SchedulingServiceUtil.java

/**
 * Converts a list of Calendar constants (i.e. Calendar.MONDAY, Calendar.FRIDAY) into a string of characters representing those days
 * Used in DTO/Entity translations for TimeSlot
 *
 * @param weekdaysList//w w  w  . java 2 s .  com
 * @return
 */
public static String weekdaysList2WeekdaysString(List<Integer> weekdaysList) {
    StringBuilder result = new StringBuilder();

    for (Integer day : weekdaysList) {
        switch (day) {
        case Calendar.MONDAY: {
            result.append(SchedulingServiceConstants.MONDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.TUESDAY: {
            result.append(SchedulingServiceConstants.TUESDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.WEDNESDAY: {
            result.append(SchedulingServiceConstants.WEDNESDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.THURSDAY: {
            result.append(SchedulingServiceConstants.THURSDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.FRIDAY: {
            result.append(SchedulingServiceConstants.FRIDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.SATURDAY: {
            result.append(SchedulingServiceConstants.SATURDAY_TIMESLOT_DAY_CODE);
            break;
        }
        case Calendar.SUNDAY: {
            result.append(SchedulingServiceConstants.SUNDAY_TIMESLOT_DAY_CODE);
            break;
        }
        }
    }

    return result.toString();
}

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();/*from   ww w. j a v a 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();/*  w  w w.  ja  v a 2 s .  co  m*/
    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.model.WeekSelectorModel.java

private String getDateValue(int diff) {
    Calendar other = (Calendar) cal.clone();
    StringBuffer buf = new StringBuffer();
    buf.append(WEEK_OF_YEAR_PREFIX);/*from   w  ww .j  av  a2  s. c  o m*/
    if (diff != 0) {
        other.add(Calendar.WEEK_OF_YEAR, diff);
        LOG.debug("Current date: " + cal.getTime() + ", New Date: " + other.getTime() + ", diff: " + diff);

    }
    if (other.get(Calendar.WEEK_OF_YEAR) < 10) {
        buf.append("0");
    }
    buf.append(other.get(Calendar.WEEK_OF_YEAR));
    buf.append(": ");
    other.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    buf.append(dfmt.format(other.getTime()));
    buf.append(" - ");
    other.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    buf.append(dfmt.format(other.getTime()));
    return buf.toString();
}