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.hihframework.core.utils.DateUtils.java

/**
 * ?//from   w  w  w.j  a  v  a  2 s.  c o m
 *
 * @param date java.sql.Date ??
 * @return Date[] java.sql.Date 
 */
public static java.sql.Date[] getWeekDays(java.sql.Date date) {

    Calendar cale = Calendar.getInstance();
    cale.setTime(date);
    cale.setFirstDayOfWeek(Calendar.SUNDAY);

    int days = 7;
    int today = cale.get(Calendar.DAY_OF_WEEK);
    long millis = cale.getTimeInMillis();

    java.sql.Date dates[] = new java.sql.Date[days];
    for (int i = 1; i <= days; i++) {
        long sub = (today - i) * 24 * 60 * 60 * 1000L;
        dates[i - 1] = new java.sql.Date(millis - sub);
    }

    cale = null;
    return dates;
}

From source file:com.feilong.core.date.DateUtil.java

/**
 * date <span style="color:red"> ()</span> <code>00:00:00.000</code> .
 * //from   w w  w .ja va2  s .c o  m
 * <pre class="code">
 * DateUtil.getFirstDateOfThisWeek(2012-10-11 17:10:30.701)  =2012-10-07 00:00:00.000
 * DateUtil.getFirstDateOfThisWeek(2014-01-01 05:00:00)      =2013-12-29 00:00:00.000 //
 * </pre>
 * 
 * <h3>?:</h3>
 * <blockquote>
 * <ol>
 * <li>,<span style="color:red">,?</span></li>
 * <li>,?</li>
 * </ol>
 * </blockquote>
 * 
 * @param date
 *            ?
 * @return  <code>date</code> null, {@link NullPointerException}
 * @see #toCalendar(Date)
 * @see Calendar#set(int, int)
 * @see CalendarUtil#resetDayBegin(Calendar)
 * @see Calendar#getTime()
 */
public static Date getFirstDateOfThisWeek(Date date) {
    Calendar calendar = toCalendar(date);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    return CalendarUtil.toDate(CalendarUtil.resetDayBegin(calendar));
}

From source file:org.sakaiproject.util.CalendarUtil.java

/**
* Get the day of the week//www . ja v  a2 s .c  o m
*
* @param useLocale return locale specific day of week
* e.g. <code>SUNDAY = 1, MONDAY = 2, ...</code> in the U.S.,
*       <code>MONDAY = 1, TUESDAY = 2, ...</code> in France. 
* @return the day of the week.
*/
public int getDay_Of_Week(boolean useLocale) {
    int dayofweek = m_calendar.get(Calendar.DAY_OF_WEEK);
    if (useLocale) {
        if (dayofweek >= m_calendar.getFirstDayOfWeek())
            dayofweek = dayofweek - (m_calendar.getFirstDayOfWeek() - Calendar.SUNDAY);
        else
            dayofweek = dayofweek + Calendar.SATURDAY - (m_calendar.getFirstDayOfWeek() - Calendar.SUNDAY);
    }
    return dayofweek;

}

From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java

/** 
 * Test times near midnight./*from w ww  . ja  va 2 s  .c  o  m*/
 * 
 * @throws Exception
 */
@Test
public void testCreateBlocksExample3() throws Exception {
    SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat();
    Date startDate = dateFormat.parse("20080624");
    Date endDate = dateFormat.parse("20080630");
    Set<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("12:00 AM", "12:59 AM", "MTWRF", startDate,
            endDate);

    assertEquals(5, blocks.size());
    for (AvailableBlock block : blocks) {
        assertEquals(59, block.getDurationInMinutes());
        Calendar cal = Calendar.getInstance();
        cal.setTime(block.getStartTime());
        assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
        assertEquals(0, cal.get(Calendar.MINUTE));
        cal.setTime(block.getEndTime());
        assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
        assertEquals(59, cal.get(Calendar.MINUTE));
        assertNotSame(Calendar.SATURDAY, cal.get(Calendar.DAY_OF_WEEK));
        assertNotSame(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK));
        assertEquals(1, block.getVisitorLimit());
    }

    blocks = AvailableBlockBuilder.createBlocks("12:00 AM", "12:59 AM", "MTWRF", startDate, endDate, 27);

    assertEquals(5, blocks.size());
    for (AvailableBlock block : blocks) {
        assertEquals(59, block.getDurationInMinutes());
        Calendar cal = Calendar.getInstance();
        cal.setTime(block.getStartTime());
        assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
        assertEquals(0, cal.get(Calendar.MINUTE));
        cal.setTime(block.getEndTime());
        assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
        assertEquals(59, cal.get(Calendar.MINUTE));
        assertNotSame(Calendar.SATURDAY, cal.get(Calendar.DAY_OF_WEEK));
        assertNotSame(Calendar.SUNDAY, cal.get(Calendar.DAY_OF_WEEK));
        assertEquals(27, block.getVisitorLimit());
    }
}

From source file:org.power.commons.lang.util.time.DateUtils.java

private static Calendar getADayOfWeek(Calendar day, int dayOfWeek) {
    int week = day.get(Calendar.DAY_OF_WEEK);
    if (week == dayOfWeek) {
        return day;
    }//from   w  w  w .j av a2  s .  c  o m
    int diffDay = dayOfWeek - week;
    if (week == Calendar.SUNDAY) {
        diffDay -= 7;
    } else if (dayOfWeek == Calendar.SUNDAY) {
        diffDay += 7;
    }
    day.add(Calendar.DATE, diffDay);
    return day;
}

From source file:br.msf.commons.util.AbstractDateUtils.java

public static boolean isBusinessDay(final Object date, final Collection<? extends Object> holidays) {
    if (date == null) {
        return false;
    }/* w ww  .ja v a  2 s .  c o  m*/
    int dayOfWeek = castToCalendar(date).get(Calendar.DAY_OF_WEEK);
    return dayOfWeek != Calendar.SATURDAY && dayOfWeek != Calendar.SUNDAY && !isHoliday(date, holidays);
}

From source file:org.b3log.symphony.processor.JournalProcessor.java

/**
 * Generates journal chapter this week.//from w w  w .  j a  v  a2s .c  om
 *
 * @param context the specified context
 * @param request the specified request
 * @param response the specified response
 * @throws IOException io exception
 * @throws ServletException servlet exception
 */
@RequestProcessing(value = "/journal/gen/chapter", method = HTTPRequestMethod.GET)
@Before(adviceClass = StopwatchStartAdvice.class)
@After(adviceClass = StopwatchEndAdvice.class)
public void genChapter(final HTTPRequestContext context, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException, ServletException {
    final String key = Symphonys.get("keyOfSymphony");
    if (!key.equals(request.getParameter("key"))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);

        return;
    }

    context.renderJSON();

    if (journalQueryService.hasChapterWeek()) {
        return;
    }

    try {
        final JSONObject admin = userQueryService.getSA();

        final JSONObject chapter = new JSONObject();

        final Calendar cal = Calendar.getInstance();
        final SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

        final String from = df.format(cal.getTime());
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

        final String title = from + " - " + df.format(cal.getTime());
        chapter.put(Article.ARTICLE_TITLE, title);
        chapter.put(Article.ARTICLE_TAGS, ",");
        chapter.put(Article.ARTICLE_CONTENT, "");
        chapter.put(Article.ARTICLE_EDITOR_TYPE, 0);
        chapter.put(Article.ARTICLE_AUTHOR_EMAIL, admin.optString(User.USER_EMAIL));
        chapter.put(Article.ARTICLE_AUTHOR_ID, admin.optString(Keys.OBJECT_ID));
        chapter.put(Article.ARTICLE_TYPE, Article.ARTICLE_TYPE_C_JOURNAL_CHAPTER);

        articleMgmtService.addArticle(chapter);

        context.renderTrueResult();
    } catch (final ServiceException e) {
        LOGGER.log(Level.ERROR, "Generates section failed", e);
    }
}

From source file:dao.Graficos.java

public static Date dia_inicial_final_semana(boolean isPrimeiro) {
    //Seta a data atual.
    Date dataAtual = new Date();
    GregorianCalendar calendar = new GregorianCalendar();
    //Define que a semana comea no domingo.
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    //Define a data atual.
    calendar.setTime(dataAtual);/*from   w  w w  .ja  v  a 2s .c o  m*/
    if (isPrimeiro) {
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    } else {
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    }
    return calendar.getTime();
}

From source file:services.plugins.system.timesheet1.TimesheetLoadableObject.java

/**
 * Return the timesheet report start date matching with the current logDate
 * @return a timesheet report start date
 *///from  w w w  . j  a  va2 s  .co  m
private Date getTimesheetReportStartDate() {
    Calendar c = Calendar.getInstance();
    c.setTime(getLogDateAsDate());
    if (c.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
        if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            c.add(Calendar.DAY_OF_WEEK, -1);
            c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        } else {
            c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        }
    }
    return c.getTime();
}

From source file:at.diamonddogs.util.CacheManager.java

/**
 * Turn on scheduled cache cleaning (cache will be cleaned even if app is
 * not running)/*from   w w  w. j  a  v a 2  s  .  co m*/
 *
 * @param context a {@link Context}
 */
public void enableScheduledCacheCleaner(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    // @formatter:off
    am.setInexactRepeating(AlarmManager.RTC, Utils.getScheduledDate(Calendar.SUNDAY, 3, 0, 0).getTimeInMillis(),
            7 * AlarmManager.INTERVAL_DAY, getAlarmIntent(context));
    // @formatter:on
    Log.i(TAG, "Cache cleaning alarm has been set.");
}