Example usage for java.util Calendar DAY_OF_WEEK

List of usage examples for java.util Calendar DAY_OF_WEEK

Introduction

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

Prototype

int DAY_OF_WEEK

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

Click Source Link

Document

Field number for get and set indicating the day of the week.

Usage

From source file:WebCalendar.java

/** */
public String[] getDays() {
    String days[] = new String[m_gc.getMaximum(Calendar.DAY_OF_WEEK) - m_gc.getMinimum(Calendar.DAY_OF_WEEK)
            + 1];//from ww  w.  j  a va 2 s .  co m
    m_gc.set(Calendar.DAY_OF_WEEK, 1);

    for (int i = 0; i < days.length; i++) {
        days[i] = m_sdf.format(m_gc.getTime()).toString();
        m_gc.roll(Calendar.DAY_OF_WEEK, true);
    }

    return days;
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java

public static ArrayList<ITransportationInfo> getNext3Arrivals(String stationFrom, String stationTo, String line,
        Context context) {//from w w w. ja v  a  2s .c  o m
    ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>();
    try {
        String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
        JsonNode actualObj = Util.stringToJsonNode(bufferString);
        JsonNode lines = actualObj.get("timetable");

        // find the data for the current transportation line
        for (int i = 0; i < lines.size(); i++) {
            JsonNode lineJson = lines.get(i);
            String[] sublines = line.split(",");
            for (int ii = 0; ii < sublines.length; ii++) {
                if (lineJson.get("line").asText().equalsIgnoreCase(sublines[ii].trim())) {
                    int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
                    if (day == 1)
                        day = 6;
                    else
                        day -= 2;
                    int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                    int minute = Calendar.getInstance().get(Calendar.MINUTE);
                    JsonNode stationData = null;
                    if ((day == 4 || day == 5)
                            && isFridaySaturdayNight(lineJson.get("night-after-friday-saturday"), hour)) {
                        // night after Friday or Saturday
                        stationData = lineJson.get("night-after-friday-saturday");
                    } else if (day < 5) {
                        // weekdays
                        stationData = lineJson.get("weekdays");
                    } else {
                        // weekend
                        stationData = lineJson.get("weekend");
                    }
                    JsonNode stations = stationData.get("data");
                    int[] AStationMinutes = null, BStationMinutes = null;
                    // find the data for the start and end station and choose the direction
                    direction = NOT_SET;
                    for (int j = 0; j < stations.size(); j++) {
                        JsonNode st = stations.get(j);
                        if (st.get("station").asText().equalsIgnoreCase(stationFrom) && direction == NOT_SET
                                && AStationMinutes == null) {
                            direction = DEPARTURE;
                            AStationMinutes = getMinutesArray(st.get("departure").asText());
                        } else if (st.get("station").asText().equalsIgnoreCase(stationFrom)
                                && AStationMinutes == null) {
                            AStationMinutes = getMinutesArray(st.get("arrival").asText());
                            break;
                        } else if (st.get("station").asText().equalsIgnoreCase(stationTo)
                                && direction == NOT_SET && BStationMinutes == null) {
                            direction = ARRIVAL;
                            BStationMinutes = getMinutesArray(st.get("departure").asText());
                        } else if (st.get("station").asText().equalsIgnoreCase(stationTo)
                                && BStationMinutes == null) {
                            BStationMinutes = getMinutesArray(st.get("arrival").asText());
                            break;
                        }
                    }
                    if (AStationMinutes == null || BStationMinutes == null)
                        continue;
                    JsonNode subLines = direction == DEPARTURE ? stationData.get("departure")
                            : stationData.get("arrival");
                    JsonNode subLine = subLines.get(0);
                    if (hasTrain(hour, subLine.get("night").asText(), subLine.get("day").asText())) {
                        int count = 0;
                        for (int k = 0; k < AStationMinutes.length; k++) {
                            if (minute <= AStationMinutes[k]) {
                                int arrivalHour = hour;
                                int time = BStationMinutes[k] - AStationMinutes[k];
                                if (AStationMinutes[k] > BStationMinutes[k]) {
                                    arrivalHour++;
                                    time = 60 - AStationMinutes[k] + BStationMinutes[k];
                                }
                                ret.add(new STrainData(
                                        (hour < 10 ? "0" + hour : "" + hour) + ":"
                                                + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k]
                                                        : "" + AStationMinutes[k]),
                                        (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":"
                                                + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k]
                                                        : "" + BStationMinutes[k]),
                                        time));
                                if (++count == 3)
                                    break;
                            }
                        }
                        // second pass to get the times for the next hour
                        hour++;
                        for (int k = 0; k < AStationMinutes.length && count < 3; k++) {
                            int arrivalHour = hour;
                            int time = BStationMinutes[k] - AStationMinutes[k];
                            if (AStationMinutes[k] > BStationMinutes[k]) {
                                arrivalHour++;
                                time = 60 - AStationMinutes[k] + BStationMinutes[k];
                            }
                            ret.add(new STrainData(
                                    (hour < 10 ? "0" + hour : "" + hour) + ":"
                                            + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k]
                                                    : "" + AStationMinutes[k]),
                                    (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":"
                                            + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k]
                                                    : "" + BStationMinutes[k]),
                                    time));
                        }
                    }
                    return ret;
                }
            }
        }
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }

    return ret;
}

From source file:com.ekom.ekomerp.global.DateTimeUtils.java

public static Date getSpecificDayOfWeek(Date date, int javaCalendarDayNumber, Locale locale) {
    Calendar calendar = getCalendarWithoutTime(date, locale);
    calendar.set(Calendar.DAY_OF_WEEK, javaCalendarDayNumber);
    return calendar.getTime();
}

From source file:net.chrisrichardson.polyglotpersistence.restaurantmanagement.domain.TimeRange.java

public boolean isOpenAtThisTime(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);/*  w  ww  .j  a v  a 2 s .  c  o m*/
    int day = c.get(Calendar.DAY_OF_WEEK);
    int timeOfDay = c.get(Calendar.HOUR_OF_DAY) * 100 + c.get(Calendar.MINUTE);
    return day == getDayOfWeek() && openingTime <= timeOfDay && timeOfDay <= closingTime;
}

From source file:MonthPanel.java

protected JPanel createDaysGUI() {
    JPanel dayPanel = new JPanel(true);
    dayPanel.setLayout(new GridLayout(0, dayNames.length));

    Calendar today = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    Calendar iterator = (Calendar) calendar.clone();
    iterator.add(Calendar.DAY_OF_MONTH, -(iterator.get(Calendar.DAY_OF_WEEK) - 1));

    Calendar maximum = (Calendar) calendar.clone();
    maximum.add(Calendar.MONTH, +1);

    for (int i = 0; i < dayNames.length; i++) {
        JPanel dPanel = new JPanel(true);
        dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        JLabel dLabel = new JLabel(dayNames[i]);
        dPanel.add(dLabel);/*from   w ww . j  a v a  2s .c  o  m*/
        dayPanel.add(dPanel);
    }

    int count = 0;
    int limit = dayNames.length * 6;

    while (iterator.getTimeInMillis() < maximum.getTimeInMillis()) {
        int lMonth = iterator.get(Calendar.MONTH);
        int lYear = iterator.get(Calendar.YEAR);

        JPanel dPanel = new JPanel(true);
        dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        JLabel dayLabel = new JLabel();

        if ((lMonth == month) && (lYear == year)) {
            int lDay = iterator.get(Calendar.DAY_OF_MONTH);
            dayLabel.setText(Integer.toString(lDay));
        }
        dPanel.add(dayLabel);
        dayPanel.add(dPanel);
        iterator.add(Calendar.DAY_OF_YEAR, +1);
        count++;
    }

    for (int i = count; i < limit; i++) {
        JPanel dPanel = new JPanel(true);
        dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        dPanel.add(new JLabel());
        dayPanel.add(dPanel);
    }
    return dayPanel;
}

From source file:com.example.kyle.weatherforecast.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    viewPager = (ViewPager) findViewById(R.id.pager);
    FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
    viewPager.setAdapter(adapter);/*  ww w.  j  a  v  a 2 s  . co m*/

    Calendar calendar = Calendar.getInstance();
    String weekDay;
    SimpleDateFormat dayFormat;

    dayFormat = new SimpleDateFormat("cccc", Locale.getDefault());
    // dayFormat = new SimpleDateFormat("c LLL d", Locale.getDefault());
    // dayFormat = (SimpleDateFormat) new SimpleDateFormat().getDateInstance();
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.addTab(actionBar.newTab().setText("Today").setTabListener(this));
    for (int i = 1; i < 5; i++) {
        calendar.add(Calendar.DAY_OF_WEEK, 1);
        weekDay = dayFormat.format(calendar.getTime());
        actionBar.addTab(actionBar.newTab().setText(weekDay).setTabListener(this));
    }

    if (notificationId == 0) {
        postAlert(0);
    }

    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });
}

From source file:calendar.services.transformers.EntryToWeekRowTransformer.java

private BigDecimal setEntryToDayInWeekRow(Entry entry, WeekRow weekRow) {
    Date date = entry.getDate();/*from   w  w w. j a  v  a  2s.  c om*/
    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:com.sammyun.util.DateUtil.java

/**
 * ?_:1,:2....:7//w ww. j av  a2s  .c o  m
 * 
 * @param dateString String
 * @return int
 */
public static int getWeek(String dateString) {
    Date date = string2Date(dateString);
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c.get(Calendar.DAY_OF_WEEK);
}

From source file:edu.jhuapl.graphs.jfreechart.TimeSeriesEffectsTest.java

public static JFreeChartGraphSource getSource() throws GraphException {
    Calendar base = Calendar.getInstance();
    base.set(Calendar.WEEK_OF_YEAR, 6);

    Random r = new Random();

    List<TimePoint> ps1 = new LinkedList<TimePoint>();
    List<TimePoint> ps2 = new LinkedList<TimePoint>();
    List<TimePoint> ps3 = new LinkedList<TimePoint>();

    for (int count = 0; count < 4; count += 1) {
        base.set(Calendar.DAY_OF_WEEK, 2);
        addPoint(base.getTime(), ps2, r);

        // now generate five points for ps1 and p23, the daily sets
        addPoint(base.getTime(), ps1, r);
        addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=0", null);

        for (int i = 1; i < 5; i += 1) {
            base.add(Calendar.DAY_OF_WEEK, 1);
            addPoint(base.getTime(), ps1, r);
            addPoint(base.getTime(), ps3, r, "showPoint?week=" + count + "&day=" + i, null);
        }//from   w w w . j av a  2s  .  c  o m

        base.set(Calendar.DAY_OF_WEEK, 1);
        base.add(Calendar.WEEK_OF_YEAR, 1);
    }

    List<DefaultTimeSeries> series = new LinkedList<DefaultTimeSeries>();
    Map<String, Object> s1Md = new HashMap<String, Object>();
    s1Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY);
    s1Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-5, -5, 10, 10));
    s1Md.put(GraphSource.SERIES_TITLE, "Frederick County Counts");
    series.add(new DefaultTimeSeries(ps1, s1Md));

    Map<String, Object> s2Md = new HashMap<String, Object>();
    s2Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.WEEKLY);
    s2Md.put(GraphSource.SERIES_SHAPE, new Ellipse2D.Float(-7, -7, 14, 14));
    s2Md.put(GraphSource.SERIES_TITLE, "NCR Counts");
    series.add(new DefaultTimeSeries(ps2, s2Md));

    Map<String, Object> s3Md = new HashMap<String, Object>();
    s3Md.put(GraphSource.SERIES_TIME_RESOLUTION, TimeResolution.DAILY);
    s3Md.put(GraphSource.SERIES_SHAPE, new Rectangle2D.Float(-3, -3, 6, 6));
    s3Md.put(GraphSource.SERIES_TITLE, "Carroll County Counts");
    BasicStroke bs = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10,
            new float[] { 3F, 2F, 8F }, 1F);
    s3Md.put(GraphSource.SERIES_STROKE, bs);
    series.add(new DefaultTimeSeries(ps3, s3Md));

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(GraphSource.BACKGROUND_COLOR, Color.BLUE);
    params.put(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Color.WHITE);
    params.put(GraphSource.GRAPH_TITLE, "Counts");
    params.put(GraphSource.GRAPH_X_LABEL, "Time");
    params.put(GraphSource.GRAPH_Y_LABEL, "Total Counts");
    DateAxis customAxis = new RotatedTickDateAxis(60.);
    params.put(JFreeChartTimeSeriesGraphSource.DATE_AXIS, customAxis);

    JFreeChartGraphSource source = new JFreeChartGraphSource();
    source.setData(series);
    source.setParams(params);
    source.initialize();

    return source;
}

From source file:com.greenline.guahao.biz.util.DateUtils.java

/**
 * ???0?7?//from  w  ww.  j ava  2  s  .c  o m
 * 
 * @param date
 * @return int
 */
public static int getIndexInCycle(String date) {
    try {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, 1); // 
        int d = cal.get(Calendar.DAY_OF_WEEK); // 
        cal.setTime(df.parse(date));
        int id = cal.get(Calendar.DAY_OF_WEEK); // 
        int idx = id - d;
        idx = idx < 0 ? idx + 7 : idx; // 7
        return idx;
    } catch (Exception e) {
        logger.error("???", e);
    }
    return -1;
}