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:stepReport.model.PeriodoModel.java

private String calcPeriodoCustom(String data) {
    Calendar c = Calendar.getInstance();
    String dia = data.substring(0, 2);
    String mes = data.substring(3, 5);
    String ano = data.substring(6, 10);

    mes = Integer.toString(Integer.parseInt(mes) - 1);

    c.set(Integer.parseInt(ano), Integer.parseInt(mes), Integer.parseInt(dia));
    int day = c.get(Calendar.DAY_OF_WEEK);
    while (day != Calendar.SUNDAY) {
        c.add(Calendar.DAY_OF_WEEK, -1);
        day = c.get(Calendar.DAY_OF_WEEK);
    }/*from   ww  w  . ja v  a2 s  .  co m*/

    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
    String fmtData = fmt.format(c.getTime());

    return fmtData;
}

From source file:br.com.transport.report.ManagerReportBean.java

/**
 * Retorna lista com os dias da semana/*from   ww  w.  j ava 2s . co m*/
 * @return {@link List}< {@link Calendar} >
 */
private List<Calendar> createDayOfTheWeek() {

    Calendar firstDay = GregorianCalendar.getInstance();
    firstDay.setFirstDayOfWeek(Calendar.SUNDAY);
    firstDay.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    firstDay.set(Calendar.HOUR_OF_DAY, 0);
    firstDay.set(Calendar.MINUTE, 0);
    firstDay.set(Calendar.SECOND, 0);

    List<Calendar> daysOfTheWeek = new LinkedList<Calendar>();

    for (int count = 0; count < 7; count++) {

        Calendar temp = (Calendar) firstDay.clone();
        temp.roll(Calendar.DAY_OF_WEEK, count);
        temp.setTime(temp.getTime());
        daysOfTheWeek.add(temp);

    }

    return daysOfTheWeek;
}

From source file:org.structr.common.RecurringDateHelper.java

private static String getShortWeekday(final int wd) {

    switch (wd) {

    case Calendar.MONDAY:
        return ShortWeekday.Mo.name();

    case Calendar.TUESDAY:
        return ShortWeekday.Di.name();

    case Calendar.WEDNESDAY:
        return ShortWeekday.Mi.name();

    case Calendar.THURSDAY:
        return ShortWeekday.Do.name();

    case Calendar.FRIDAY:
        return ShortWeekday.Fr.name();

    case Calendar.SATURDAY:
        return ShortWeekday.Sa.name();

    case Calendar.SUNDAY:
        return ShortWeekday.So.name();

    }/*ww  w .j  a v  a 2 s . c  o m*/

    return "";

}

From source file:com.adobe.acs.commons.http.headers.impl.WeeklyExpiresHeaderFilterTest.java

@Test
public void testDoActivateSuccess() throws Exception {

    properties.put(WeeklyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_WEEK, Calendar.SUNDAY);

    Calendar actual = Calendar.getInstance();
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);
    actual.set(Calendar.HOUR_OF_DAY, 1);
    actual.set(Calendar.MINUTE, 29);

    filter.doActivate(componentContext);
    filter.adjustExpires(actual);//from w  ww  .  j av  a 2s .  co  m

    assertEquals(Calendar.SUNDAY, actual.get(Calendar.DAY_OF_WEEK));
    // Abstract class will pass expires, this checks we aren't messing with the time.
    assertEquals(1, actual.get(Calendar.HOUR_OF_DAY));
    assertEquals(29, actual.get(Calendar.MINUTE));
}

From source file:org.projectforge.calendar.DayHolder.java

public boolean isSunday() {
    return Calendar.SUNDAY == getDayOfWeek();
}

From source file:ca.mudar.parkcatcher.ui.fragments.FavoritesFragment.java

private String[] getSelectionArgs() {

    final GregorianCalendar parkingCalendar = parkingApp.getParkingCalendar();

    final int dayOfWeek = (parkingCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? 7
            : parkingCalendar.get(Calendar.DAY_OF_WEEK) - 1);
    final double parkingHour = parkingCalendar.get(Calendar.HOUR_OF_DAY)
            + Math.round(parkingCalendar.get(Calendar.MINUTE) / 0.6) / 100.00d;
    final double hourOfWeek = parkingHour + (dayOfWeek - 1) * 24;

    // API uses values 0-365 (or 364)
    final int dayOfYear = parkingCalendar.get(Calendar.DAY_OF_YEAR) - 1;

    final int duration = parkingApp.getParkingDuration();

    return new String[] { Double.toString(hourOfWeek), Integer.toString(duration),
            Integer.toString(dayOfYear) };
}

From source file:net.firejack.platform.core.utils.DateUtils.java

/**
 * Increments the date to round it on week level
 * @param date - date to be incremented/*from   w w  w.jav a 2 s .co m*/
 * @return incremented date
 */
public static Date ceilDateToWeek(Date date) {
    date = addWeeks(date, 1);
    Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
        cal.add(Calendar.DAY_OF_MONTH, -1);
    }
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return addMinutes(cal.getTime(), -1);
}

From source file:org.projectforge.framework.time.DayHolder.java

public boolean isWeekend() {
    final int dayOfWeek = getDayOfWeek();
    return Calendar.SUNDAY == dayOfWeek || Calendar.SATURDAY == dayOfWeek;
}

From source file:org.openmrs.web.servlet.QuickReportServlet.java

private void doReturnVisitDate(VelocityContext velocityContext, PrintWriter report, HttpServletRequest request)
        throws ServletException {
    ObsService os = Context.getObsService();
    EncounterService es = Context.getEncounterService();
    ConceptService cs = Context.getConceptService();

    DateFormat dateFormat = Context.getDateFormat();

    Concept c = cs.getConcept(Integer.valueOf("5096")); // RETURN VISIT DATE
    Calendar cal = Calendar.getInstance();

    Date start;//from w w w .j a  v a 2s.c  om
    Date end;

    String startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");
    String location = request.getParameter("location");

    if (startDate != null && startDate.length() != 0) {
        try {
            cal.setTime(dateFormat.parse(startDate));
        } catch (ParseException e) {
            throw new ServletException("Error parsing 'Start Date'", e);
        }
    } else {
        cal.setTime(new Date());
    }

    // if they don't input an end date, assume they meant "this week"
    if (endDate == null || "".equals(endDate)) {
        while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            cal.add(Calendar.DAY_OF_MONTH, -1);
        }
        start = cal.getTime();
        cal.add(Calendar.DAY_OF_MONTH, 7);
        end = cal.getTime();
    } else {
        // they put in an end date, assume literal start and end
        start = cal.getTime();
        try {
            cal.setTime(dateFormat.parse(endDate));
        } catch (ParseException e) {
            throw new ServletException("Error parsing 'End Date'", e);
        }
        end = cal.getTime();
    }

    List<Obs> allObs = null;

    List<String> sort = new ArrayList<String>();
    sort.add("location.locationId asc");
    sort.add("obs.valueDatetime asc");

    List<Concept> questions = new ArrayList<Concept>();
    questions.add(c);

    List<OpenmrsConstants.PERSON_TYPE> personTypes = new ArrayList<OpenmrsConstants.PERSON_TYPE>();
    personTypes.add(OpenmrsConstants.PERSON_TYPE.PATIENT);

    if (location == null || "".equals(location)) {
        allObs = os.getObservations(null, null, questions, null, personTypes, null, sort, null, null, null,
                null, true);
    } else {
        Location locationObj = Context.getLocationService().getLocation(Integer.valueOf(location));
        List<Location> locations = new ArrayList<Location>();
        locations.add(locationObj);

        allObs = os.getObservations(null, null, questions, null, personTypes, locations, sort, null, null, null,
                null, true);
    }

    List<Obs> obs = new Vector<Obs>();

    for (Obs o : allObs) {
        if (o.getValueDatetime() != null && o.getValueDatetime().after(start)
                && o.getValueDatetime().before(end)) {
            obs.add(o);
        }
    }

    velocityContext.put("observations", obs);
}

From source file:com.clustercontrol.jobmanagement.factory.JobPlanSchedule.java

/**
 * ????Cron??//from   w  w  w .  ja  va  2 s. c om
 * 
 * @param cron
 */
private void createPlan(String cron) {

    /*
     * cron
     *       
     */

    // * 0 15 * * ? *         1500
    // * 0 23 ? * 1 *         2300
    // * */10 * * * ? *       10??

    String[] planSplit = cron.split(" ");
    String aster = "*";
    String question = "?";
    String slash = "/";
    if (!aster.equals(planSplit[0])) {
        secondType = 0;
        second = Integer.parseInt(planSplit[0]);
    }
    if (!aster.equals(planSplit[1])) {
        String[] slashSplit = planSplit[1].split(slash);
        int num = 0;
        for (String str : slashSplit) {
            m_log.trace("slashSplit[ " + num + " ] =" + str);
            num++;
        }
        //p?q????
        if (slashSplit.length == 2) {
            minuteType = 3;
            minute = Integer.parseInt(slashSplit[0]);
            fromMinutes = Integer.parseInt(slashSplit[0]);
            everyMinutes = Integer.parseInt(slashSplit[1]);
        } else {
            minuteType = 0;
            minute = Integer.parseInt(planSplit[1]);
            m_log.debug("minuteType=" + minuteType);
            m_log.debug("minute=" + minute);
        }
    }
    if (!aster.equals(planSplit[2])) {
        hourType = 0;
        hour = Integer.parseInt(planSplit[2]);
    }
    if (question.equals(planSplit[3])) {
        dayType = 2;
    } else if (!aster.equals(planSplit[3])) {
        dayType = 0;
        day = Integer.parseInt(planSplit[3]);
    }
    if (!aster.equals(planSplit[4])) {
        monthType = 0;
        month = Integer.parseInt(planSplit[4]);
    }
    if (question.equals(planSplit[5])) {
        weekType = 2;
    } else if (!aster.equals(planSplit[5])) {
        weekType = 0;
        week = Integer.parseInt(planSplit[5]);
    }
    switch (week) {
    case 1:
        weekCalendar = Calendar.SUNDAY;
        break;
    case 2:
        weekCalendar = Calendar.MONDAY;
        break;
    case 3:
        weekCalendar = Calendar.TUESDAY;
        break;
    case 4:
        weekCalendar = Calendar.WEDNESDAY;
        break;
    case 5:
        weekCalendar = Calendar.THURSDAY;
        break;
    case 6:
        weekCalendar = Calendar.FRIDAY;
        break;
    case 7:
        weekCalendar = Calendar.SATURDAY;
        break;
    default:
        weekCalendar = Calendar.SUNDAY;
    }
    // weekType?0??????????
    // ??????????*????0?? 
    if (weekType == 0 && isFireDayOfWeek() == false) {
        nextFireDay();
        if (hourType == 1) {
            hour = 0;
        }
    }
}