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:com.microsoft.mimickeralarm.model.Alarm.java

public boolean isOneShot() {
    boolean isOneShot = true;
    for (int dayOfWeek = Calendar.SUNDAY; dayOfWeek <= Calendar.SATURDAY; ++dayOfWeek) {
        if (getRepeatingDay(dayOfWeek - 1)) {
            isOneShot = false;//ww  w  .  ja v a2 s  .c o m
            break;
        }
    }
    return isOneShot;
}

From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java

public static String generateYear() {
    StringBuffer guid = new StringBuffer();

    // Create a calendar to get the date formatted properly
    String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);/*from  w  ww. j  av  a  2 s . c o m*/
    guid.append(calendar.get(Calendar.YEAR));

    return guid.toString();
}

From source file:com.autentia.jsf.component.ocupation.HtmlOcupationCalendarRenderer.java

private int mapCalendarDayToCommonDay(int day) {
    switch (day) {
    case Calendar.TUESDAY:
        return 1;
    case Calendar.WEDNESDAY:
        return 2;
    case Calendar.THURSDAY:
        return 3;
    case Calendar.FRIDAY:
        return 4;
    case Calendar.SATURDAY:
        return 5;
    case Calendar.SUNDAY:
        return 6;
    default://from  www.  j  a va  2s  .c o  m
        return 0;
    }
}

From source file:org.squale.welcom.outils.DateUtil.java

/**
 * @param dateDebut : date de dbut (java.util.Date)
 * @param dateFin : date de fin (java.util.Date)
 * @param unit : unit de temps dans laquelle doit tre calcule la dure (MILLI_SEC,SEC,DAY,HOUR,MIN)
 * @return retourne le nombre de jour entre deux dates les samedi et dimanche n'tant pas inclu
 *///from   ww  w .j  a  v  a2 s .c  o m
public static long durationNoWeekEnd(final java.util.Date dateDebut, final java.util.Date dateFin,
        final long unit) {
    long duration = duration(dateDebut, dateFin, unit);
    final GregorianCalendar gc = new GregorianCalendar();

    if (duration != 0) {
        gc.setTime(dateDebut);

        while (gc.getTime().getTime() <= dateFin.getTime()) {
            if ((gc.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
                    || (gc.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)) {
                duration--;
            }

            gc.add(Calendar.DATE, 1);
        }
    }

    return duration;
}

From source file:org.eobjects.datacleaner.monitor.server.SchedulingServiceImplTest.java

public void testToCronExpressionWeekly() throws Exception {
    CronExpression dailyExpr = SchedulingServiceImpl.toCronExpression("@weekly");
    Date callTime = new Date();

    Calendar cal = Calendar.getInstance();
    cal.setTime(callTime);/* ww w. j av  a  2  s .co m*/
    if (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
        cal.add(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            cal.add(Calendar.DAY_OF_YEAR, 1);
        }
        Date time = cal.getTime();
        assertEquals(time, dailyExpr.getNextValidTimeAfter(callTime));
    }

    callTime = DateUtils.get(2012, Month.MARCH, 21);
    assertEquals("2012-03-25",
            new SimpleDateFormat("yyyy-MM-dd").format(dailyExpr.getNextValidTimeAfter(callTime)));

    callTime = DateUtils.get(2012, Month.MARCH, 24);
    assertEquals("2012-03-25",
            new SimpleDateFormat("yyyy-MM-dd").format(dailyExpr.getNextValidTimeAfter(callTime)));

    callTime = DateUtils.get(2012, Month.MARCH, 25);
    assertEquals("2012-04-01",
            new SimpleDateFormat("yyyy-MM-dd").format(dailyExpr.getNextValidTimeAfter(callTime)));

    callTime = DateUtils.get(2012, Month.MARCH, 26);
    assertEquals("2012-04-01",
            new SimpleDateFormat("yyyy-MM-dd").format(dailyExpr.getNextValidTimeAfter(callTime)));
}

From source file:com.ubundude.timesheet.ReportFragment.java

/**
 * Method to get the Calendar day of week Integer
 * //from ww w .  j av a  2 s.  c  o m
 * @param lFirstDay The day of the from the shared preferences
 * @return DOW The integer for the day of the week
 */
private int getFirstDay(String lFirstDay) {
    int DOW = Calendar.SUNDAY;

    if (lFirstDay == "MONDAY")
        DOW = Calendar.MONDAY;
    else if (lFirstDay == "TUESDAY")
        DOW = Calendar.TUESDAY;
    else if (lFirstDay == "WEDNESDAY")
        DOW = Calendar.WEDNESDAY;
    else if (lFirstDay == "THURSDAY")
        DOW = Calendar.THURSDAY;
    else if (lFirstDay == "FRIDAY")
        DOW = Calendar.FRIDAY;
    else if (lFirstDay == "SATURDAY")
        DOW = Calendar.SATURDAY;

    return DOW;
}

From source file:org.activequant.util.charting.IntradayMarketTimeline.java

/**
 * Translates a value relative to this timeline into a domain value. The
 * domain value obtained by this method is not always the same domain value
 * that could have been supplied to/*from  w w w .j  a v a  2  s .c o  m*/
 * translateDomainValueToTimelineValue(domainValue).
 * This is because the original tranformation may not be complete
 * reversable.
 *
 * @see org.jfree.chart.axis.SegmentedTimeline
 *
 * @param timelineValue  a timeline value.
 *
 * @return A domain value.
 */
public long toMillisecond(long timelineValue) {

    if (this.activeTimePerWeek == 0L)
        return 0;

    //starting from Jan 1, 1970 work backwards.
    //find out the number of whole weeks in the timelineValue
    Long l = new Long(timelineValue / this.activeTimePerWeek);
    int numWeeks = (int) Math.floor(l.doubleValue());

    //the amount of time left on the timeline from the last thursday
    long timeLeftSinceThursday = timelineValue - (numWeeks * this.activeTimePerWeek);

    int day = Calendar.THURSDAY;
    int numDays = 0;

    //from last friday until the current day
    //if the amount of time left is greater than
    //the active time for that day, increment the number of
    //days and subtract from the time left
    while (numDays < 7) {
        if (day == Calendar.SUNDAY) {
            if (timeLeftSinceThursday > this.sundayActive) {
                timeLeftSinceThursday -= this.sundayActive;
                numDays++;
            } else {
                break;
            }
        } else if (day == Calendar.MONDAY) {
            if (timeLeftSinceThursday > this.mondayActive) {
                timeLeftSinceThursday -= this.mondayActive;
                numDays++;
            } else {
                break;
            }
        } else if (day == Calendar.TUESDAY) {
            if (timeLeftSinceThursday > this.tuesdayActive) {
                timeLeftSinceThursday -= this.tuesdayActive;
                numDays++;
            } else {
                break;
            }
        } else if (day == Calendar.WEDNESDAY) {
            if (timeLeftSinceThursday > this.wednesdayActive) {
                timeLeftSinceThursday -= this.wednesdayActive;
                numDays++;
            } else {
                break;
            }
        } else if (day == Calendar.THURSDAY) {

            if (timeLeftSinceThursday > this.thursdayActive) {
                timeLeftSinceThursday -= this.thursdayActive;
                numDays++;

                //thursday numDays =  " + Integer.toString(numDays));
            } else {

                break;
            }
        } else if (day == Calendar.FRIDAY) {
            if (timeLeftSinceThursday > this.fridayActive) {
                timeLeftSinceThursday -= this.fridayActive;
                numDays++;
            } else {
                break;
            }
        } else if (day == Calendar.SATURDAY) {
            if (timeLeftSinceThursday > this.saturdayActive) {
                timeLeftSinceThursday -= this.saturdayActive;
                numDays++;
            } else {
                break;
            }
        }

        day = this.nextDay(day);
    }

    long millis = numWeeks * MILLIS_PER_WEEK + numDays * MILLIS_PER_DAY + this.getStartTime(day)
            + timeLeftSinceThursday;

    return millis;
}

From source file:com.android.calendar.month.SimpleDayPickerFragment.java

/**
 * Sets up the strings to be used by the header. Override this method to use
 * different strings or modify the view params.
 *///  w  ww. j  a  va 2  s .com
protected void setUpHeader() {
    mDayLabels = new String[7];
    for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
        mDayLabels[i - Calendar.SUNDAY] = DateUtils.getDayOfWeekString(i, DateUtils.LENGTH_SHORTEST)
                .toUpperCase();
    }
}

From source file:de.feanor.yeoldemensa.data.MensaFactory.java

/**
 * Returns the Date for next Saturday midnight. Used for valiTo in Mensa.
 * //from w w w . j  a v a2s . c  om
 * @return Date of next Saturday
 */
private static Date getNextSaturday() {
    Calendar calendar = Calendar.getInstance();
    int weekday = calendar.get(Calendar.DAY_OF_WEEK);

    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR, 0);

    // TODO: Better solved with locales probably
    if (weekday == Calendar.SATURDAY) {
        calendar.add(Calendar.DAY_OF_MONTH, 7);
        return calendar.getTime();
    } else if (weekday == Calendar.SUNDAY) {
        calendar.add(Calendar.DAY_OF_MONTH, 6);
        return calendar.getTime();
    } else {
        calendar.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY - weekday);
    }

    return calendar.getTime();
}

From source file:edu.harvard.iq.dvn.core.doi.DOIEZIdServiceBean.java

public static String generateTimeString() {
    StringBuffer guid = new StringBuffer();

    // Create a calendar to get the date formatted properly
    String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);//from w ww  .  j a v a  2 s . c  om
    guid.append(calendar.get(Calendar.YEAR));
    guid.append(calendar.get(Calendar.DAY_OF_YEAR));
    guid.append(calendar.get(Calendar.HOUR_OF_DAY));
    guid.append(calendar.get(Calendar.MINUTE));
    guid.append(calendar.get(Calendar.SECOND));
    guid.append(calendar.get(Calendar.MILLISECOND));
    double random = Math.random();
    guid.append(random);

    return guid.toString();
}