Example usage for java.util Calendar SATURDAY

List of usage examples for java.util Calendar SATURDAY

Introduction

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

Prototype

int SATURDAY

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

Click Source Link

Document

Value of the #DAY_OF_WEEK field indicating Saturday.

Usage

From source file:com.hurence.logisland.utils.DateUtils.java

/**
 * Check if the date parameter occurs during a weekend.
 *
 * @return Current time in ISO-8601 format, e.g. : "2012-07-03T07:59:09.206 UTC"
 *///  ww  w .j av a  2s .c  om
public static boolean isWeekend(Date date) {
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime(date);
        int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
        return dayOfTheWeek == Calendar.SATURDAY || dayOfTheWeek == Calendar.SUNDAY;
    } else {
        return false;
    }

}

From source file:org.davidmendoza.esu.service.impl.InicioServiceImpl.java

@Cacheable(value = "diaCache")
@Transactional(readOnly = true)// w w w  .ja va2s. c o m
@Override
public Inicio inicio(Calendar hoy) {
    log.debug("Hoy: {}", hoy.getTime());

    if (hoy.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY && hoy.get(Calendar.HOUR_OF_DAY) < 12) {
        hoy.add(Calendar.DAY_OF_WEEK, -1);
    }

    Trimestre trimestre = trimestreService.obtiene(hoy.getTime());

    if (trimestre != null) {
        DateTime a = new DateTime(trimestre.getInicia());
        DateTime b = new DateTime(hoy);
        Weeks c = Weeks.weeksBetween(a, b);
        int weeks = c.getWeeks() + 1;
        log.debug("Weeks: {}", weeks);
        StringBuilder leccion = new StringBuilder();
        leccion.append("l").append(dosDigitos.format(weeks));

        Inicio inicio = new Inicio();
        inicio.setAnio(trimestre.getNombre().substring(0, 4));
        inicio.setTrimestre(trimestre.getNombre().substring(4));
        inicio.setLeccion(leccion.toString());
        inicio.setDia(obtieneDia(hoy.get(Calendar.DAY_OF_WEEK)));
        return inicio;
    } else {
        return null;
    }

}

From source file:ai.ilikeplaces.logic.sits9.SubscriberNotifications.java

@Override
public void startTimer() {
    final int timeout = TGIF_TIMING == 0 ? 7 //Days of Week
            * 24 //Hour of Day
            * 60 //Minutes of Hour
            * 60 //Seconds of Minute
            * 1000 //Milliseconds of Second
            : TGIF_TIMING;// w ww.  j  ava  2s.c om

    final SmartLogger sl = SmartLogger.start(Loggers.LEVEL.INFO, Loggers.CODE_MEMC + "HELLO, STARTING "
            + this.getClass().getSimpleName() + " TIMER  WITH TIMER INTERVAL:" + timeout, 60000, null, true);

    final Calendar _calendar = Calendar.getInstance();
    final int todayDay = _calendar.get(Calendar.DAY_OF_WEEK);
    if (todayDay != Calendar.FRIDAY) {
        _calendar.add(Calendar.DAY_OF_YEAR, (Calendar.SATURDAY - todayDay + 6) % 7);
    }

    if (TGIF_TIMING == 0) {
        final Date _time = _calendar.getTime();
        timerService.createTimer(_time, timeout, null);
        String format = new SimpleDateFormat("yyyy/MM/dd").format(_time);
        sl.appendToLogMSG("Starting timer on " + format);
    } else {
        timerService.createTimer(0, timeout, null);
    }

    if (TGIF_ON_STARTUP == 1) {
        final Calendar now = Calendar.getInstance();
        now.add(Calendar.SECOND, 30);
        timerService.createTimer(now.getTime(), timeout, null);
    }

    sl.complete(Loggers.LEVEL.INFO, Loggers.DONE);
}

From source file:odin.util.ReadGoogleSpreadsheet.java

private static void process(String sprintName) throws MalformedURLException, IOException, ServiceException,
        GeneralSecurityException, ParseException, Exception {
    logger.info("Getting worksheet (same name as sprint): " + sprintName);

    StringBuffer returnBody = new StringBuffer();
    returnBody.append("<p>" + ReadGoogleSpreadsheet.class.getName() + " Completed");

    URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");

    ListFeed listFeedSpreadsheet = GoogleOAuthIntegration.getSpreadsheetService().getFeed(SPREADSHEET_FEED_URL,
            ListFeed.class);

    WorksheetEntry worksheet = getWorkSheet(sprintName);
    logger.info("Worksheet title: " + worksheet.getTitle().getPlainText());
    returnBody.append("<ul><li>Worksheet title: " + worksheet.getTitle().getPlainText() + "</li></ul>");

    // Fetch the list feed of the worksheet.
    URL listFeedUrl = worksheet.getListFeedUrl();
    ListFeed listFeed = GoogleOAuthIntegration.getSpreadsheetService().getFeed(listFeedUrl, ListFeed.class);

    //   StringBuffer sb = new StringBuffer();
    // Iterate through each row, printing its cell values.
    for (ListEntry row : listFeed.getEntries()) {
        String username = null;/* w w w  .j  a va2s.  co m*/
        // Print the first column's cell value
        // Iterate over the remaining columns, and print each cell value
        for (String tag : row.getCustomElements().getTags()) {
            logger.info("CustomElement tag value: " + row.getCustomElements().getValue(tag));
            if (tag.equals("username"))
                username = row.getCustomElements().getValue(tag);
            if (tag.startsWith("week")) {
                // Get week number from Google spreadsheet tag
                String weekNumber = tag.substring(4);

                // Get last date of that week.
                SimpleDateFormat sdf = new SimpleDateFormat("M/d/yy");
                Calendar cal = Calendar.getInstance();
                cal.set(Calendar.WEEK_OF_YEAR, new Integer(weekNumber).intValue());
                cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
                String wkEndDtS = sdf.format(cal.getTime());
                logger.info("wkEndDtS=" + wkEndDtS);

                // get hours
                int hours = 0;
                if (row.getCustomElements().getValue(tag) != null)
                    hours = new Integer(row.getCustomElements().getValue(tag)).intValue();

                // Update availability in local database
                Availability.setAvailability(wkEndDtS, username, hours);
            }
        }
    }
    OdinResponse res = new OdinResponse();
    res.setStatusCode(0);
    res.setReasonPhrase("OK");
    res.setMessageBody(returnBody.toString());
    sendJobMessage(res);
}

From source file:jp.co.nemuzuka.utils.DateTimeUtils.java

/**
 * ??./*from   ww w .  j  a  va2 s . c o m*/
 * ??????Date????
 * ?????????????????
 * ???????????
 * @param targetYyyyMM ?
 * @return index 0:??Date index 1:?Date
 */
public static List<Date> getStartEndDate4SunDay(String targetYyyyMM) {
    List<Date> list = getStartEndDate(targetYyyyMM);
    Date startDate = list.get(0);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeZone(getTimeZone());

    //??
    while (true) {
        calendar.setTime(startDate);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            //?????
            break;
        }
        //1??
        startDate = addDays(startDate, -1);
    }

    Date endDate = list.get(1);
    //?
    while (true) {
        calendar.setTime(endDate);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
            //?????
            break;
        }
        //1?
        endDate = addDays(endDate, 1);
    }

    List<Date> retList = new ArrayList<Date>();
    retList.add(startDate);
    retList.add(endDate);
    return retList;
}

From source file:net.chaosserver.timelord.swingui.ChartingPanel.java

/**
 * Creates the dataset to be charted./* w w  w .  j a v  a 2s.c o  m*/
 *
 * @return the dataset to be charted.
 */
private CategoryDataset createDataset() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Calendar calendar = Calendar.getInstance();
    DateUtil.trunc(calendar);
    calendar.add(Calendar.DATE, -FIRST_DATE);

    String series1 = "Total Hours";
    for (int i = 0; i < FIRST_DATE; i++) {
        if (Calendar.SATURDAY != calendar.get(Calendar.DAY_OF_WEEK)
                && Calendar.SUNDAY != calendar.get(Calendar.DAY_OF_WEEK)) {

            TimelordDayView timelordDayView = new TimelordDayView(timelordData, calendar.getTime());

            double totalTime = timelordDayView.getTotalTimeToday(false);

            if (log.isTraceEnabled()) {
                log.trace("Creating Value of totalTime [" + totalTime + "], series1 = " + series1
                        + " category [" + calendar.getTime() + "]");
            }
            dataset.addValue(totalTime, series1, calendar.getTime());

            timelordDayView.dispose();
        }
        calendar.add(Calendar.DATE, 1);
    }

    return dataset;
}

From source file:de.ribeiro.android.gso.activities.PlanActivity.java

/**
 * @author ribeiro//from   w ww  .  j a  v a  2  s.co m
 * ffnet ein Datumsplugin und prft, ob dieses TimeTable verfgbar ist, wenn ja, springt er dorthin
 */
private void gotoDate() {
    ctxt.handler.post(new Runnable() {

        @Override
        public void run() {
            _logger.Info("Goto Date called");
            if (ctxt.mIsRunning && ctxt.pager != null && ctxt.pager.size() > 1) {
                Calendar cal = ctxt.pager.getDateOfCurrentPage();
                if (cal != null) {
                    DatePickerDialog picker = new DatePickerDialog(PlanActivity.this,
                            new DatePickerDialog.OnDateSetListener() {

                                public void onDateSet(DatePicker view, int year, int monthOfYear,
                                        int dayOfMonth) {
                                    _logger.Info("Set Date " + dayOfMonth + "." + monthOfYear + "." + year);
                                    // das Ausgewhlte Datum einstellen
                                    Calendar newDate = new GregorianCalendar();
                                    newDate.set(year, monthOfYear, dayOfMonth);
                                    // prfen, ob es sich dabei um wochenend tage
                                    // handelt:
                                    switch (newDate.get(Calendar.DAY_OF_WEEK)) {
                                    case Calendar.SATURDAY:
                                        newDate.setTimeInMillis(
                                                newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 2));
                                        break;
                                    case Calendar.SUNDAY:
                                        newDate.setTimeInMillis(
                                                newDate.getTimeInMillis() + (1000 * 60 * 60 * 24 * 1));
                                        break;
                                    }
                                    int page = ctxt.pager.getPage(newDate, -1);
                                    if (page != -1) {
                                        // gefunden
                                        ctxt.pager.setPage(page);
                                    } else {
                                        _logger.Info("Selected date is unavailable");
                                        Toast.makeText(PlanActivity.this, "Dieses Datum ist nicht verfgbar!",
                                                Toast.LENGTH_SHORT).show();
                                    }

                                }
                            }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
                    picker.show();
                } else
                    _logger.Info("Cal Picker canceled, because Pager is empty");
            }

        }

    });

}

From source file:com.lugia.timetable.TimeTableFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView()");

    mColors = Utils.getForegroundColorArrays(getActivity());

    mBackgrounds = Utils.getBackgroundDrawableResourceIds();

    View view = inflater.inflate(R.layout.fragment_time_table, null);

    mTimeTable = (TimeTableLayout) view.findViewById(R.id.time_table);

    SubjectList subjects = SubjectList.getInstance(getActivity());

    for (Subject subject : subjects) {
        int colorIndex = subject.getColor();

        for (Schedule schedule : subject.getSchedules()) {
            View child = inflater.inflate(R.layout.item_time_table_schedule, mTimeTable, false);
            child.setBackgroundResource(mBackgrounds[colorIndex]);
            child.setTag(subject.getSubjectCode());

            TextView subjectCodeTextView = (TextView) child.findViewById(R.id.text_subject_code);
            TextView subjectDescriptionTextView = (TextView) child.findViewById(R.id.text_subject_description);
            TextView sectionTextView = (TextView) child.findViewById(R.id.text_section);
            TextView roomTextView = (TextView) child.findViewById(R.id.text_room);

            subjectCodeTextView.setText(subject.getSubjectCode());
            subjectDescriptionTextView.setText(subject.getSubjectDescription());
            sectionTextView.setText(subject.getSection(schedule.getSection()));
            roomTextView.setText(schedule.getRoom());

            subjectCodeTextView.setTextColor(mColors[colorIndex]);
            subjectDescriptionTextView.setTextColor(mColors[colorIndex]);
            sectionTextView.setTextColor(mColors[colorIndex]);
            roomTextView.setTextColor(mColors[colorIndex]);

            mTimeTable.addView(child, schedule.getDay(), schedule.getTime(), schedule.getLength());
        }//www .j  ava2  s.co m
    }

    mTimeTable.setOnDayChangedListener((MasterActivity) getActivity());
    mTimeTable.setOnItemClickListener(TimeTableFragment.this);

    // set the current day of this view initially according to real world day
    switch (Calendar.getInstance().get(Calendar.DAY_OF_WEEK)) {
    case Calendar.SATURDAY:
    case Calendar.SUNDAY:
        mTimeTable.setCurrentDay(TimeTableLayout.MONDAY);
        break;

    default:
        mTimeTable.setCurrentDay(Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1);

        // scroll to current time position for user convenient
        mTimeTable.scrollToCurrentTime();
        break;
    }

    return view;
}

From source file:ru.codeinside.calendar.BusinessCalendarDueDateCalculator.java

private boolean isWeekEnd(Calendar calendar) {
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    return day == Calendar.SUNDAY || day == Calendar.SATURDAY;
}

From source file:org.osframework.contract.date.fincal.holiday.producer.SingleYearProducer.java

private void addWeekends(FinancialCalendar calendar, List<Holiday> holidays) {
    c.clear();//from   ww  w . j  av a 2 s  . c o  m
    c.set(year, Calendar.JANUARY, 1);
    while (c.get(Calendar.YEAR) == year) {
        if (Calendar.SATURDAY == c.get(Calendar.DAY_OF_WEEK)
                || Calendar.SUNDAY == c.get(Calendar.DAY_OF_WEEK)) {
            holidays.add(new Holiday(calendar, c.getTime(), WEEKEND_HOLIDAY_DEFINITION));
        }
        c.add(Calendar.DAY_OF_MONTH, 1);
    }
}