List of usage examples for java.util Calendar SUNDAY
int SUNDAY
To view the source code for java.util Calendar SUNDAY.
Click Source Link
From source file:Time.java
/** * Return the day number of week of this day, where Monday=1, Tuesday=2, ... * Sunday=7./*from w ww . jav a2 s . c om*/ * * @return Day number of week of this day. */ public int getDayNumberOfWeek() { return getDayOfWeek() == Calendar.SUNDAY ? 7 : getDayOfWeek() - Calendar.SUNDAY; }
From source file:org.hawkular.alerts.api.model.action.TimeConstraint.java
private int day(String sDay) { if (isEmpty(sDay)) { return -1; }/*from w w w. j av a2 s. co m*/ if (sDay.length() < 3) { return -1; } String prefix = sDay.substring(0, 3).toLowerCase(); DAY d = DAY.fromString(prefix); if (d == null) { return -1; } switch (d) { case SUNDAY: return Calendar.SUNDAY; case MONDAY: return Calendar.MONDAY; case TUESDAY: return Calendar.TUESDAY; case WEDNESDAY: return Calendar.WEDNESDAY; case THURSDAY: return Calendar.THURSDAY; case FRIDAY: return Calendar.FRIDAY; case SATURDAY: return Calendar.SATURDAY; default: return -1; } }
From source file:org.jfree.data.time.WeekTest.java
/** * A test for a problem in constructing a new Week instance. *///from w w w . ja v a 2 s . c o m @Test public void testConstructor() { Locale savedLocale = Locale.getDefault(); TimeZone savedZone = TimeZone.getDefault(); Locale.setDefault(new Locale("da", "DK")); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); // first day of week is monday assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); Date t = cal.getTime(); Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(34, w.getWeek()); Locale.setDefault(Locale.US); TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); // first day of week is Sunday assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); t = cal.getTime(); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(35, w.getWeek()); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), new Locale("da", "DK")); assertEquals(34, w.getWeek()); Locale.setDefault(savedLocale); TimeZone.setDefault(savedZone); }
From source file:org.activequant.util.charting.IntradayMarketTimeline.java
private boolean isActiveDate(Calendar cal) { int day = cal.get(Calendar.DAY_OF_WEEK); long timeSinceStart = cal.get(Calendar.HOUR_OF_DAY) * 3600000 + cal.get(Calendar.MINUTE) * 60000 + cal.get(Calendar.SECOND) * 1000; if (day == Calendar.SUNDAY) { return (timeSinceStart > this.sundayStart && timeSinceStart < this.sundayEnd); } else if (day == Calendar.MONDAY) { return (timeSinceStart > this.mondayStart && timeSinceStart < this.mondayEnd); } else if (day == Calendar.TUESDAY) { return (timeSinceStart > this.tuesdayStart && timeSinceStart < this.tuesdayEnd); } else if (day == Calendar.WEDNESDAY) { return (timeSinceStart > this.wednesdayStart && timeSinceStart < this.wednesdayEnd); } else if (day == Calendar.THURSDAY) { return (timeSinceStart > this.thursdayStart && timeSinceStart < this.thursdayEnd); } else if (day == Calendar.FRIDAY) { return (timeSinceStart > this.fridayStart && timeSinceStart < this.fridayEnd); } else if (day == Calendar.SATURDAY) { return (timeSinceStart > this.saturdayStart && timeSinceStart < this.saturdayEnd); } else {/*from www.j av a 2s . c o m*/ return false; } }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @return interger//from w ww. j av a 2s . c o m * @ ??? ****************************************/ public static String getYearWeekEndDay(int yearNum, int weekNum) throws ParseException { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, yearNum); cal.set(Calendar.WEEK_OF_YEAR, weekNum + 1); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); // ???? String tempYear = Integer.toString(yearNum); String tempMonth = Integer.toString(cal.get(Calendar.MONTH) + 1); String tempDay = Integer.toString(cal.get(Calendar.DATE)); String tempDate = tempYear + "-" + tempMonth + "-" + tempDay; return setDateFormat(tempDate, "yyyy-MM-dd"); }
From source file:com.jdo.CloudContactUtils.java
public static String getDay() { int d = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); String day = "sun"; switch (d) {/*from ww w. j a va 2 s . co m*/ case Calendar.SUNDAY: day = "sun"; break; case Calendar.MONDAY: day = "mon"; break; case Calendar.TUESDAY: day = "tue"; break; case Calendar.WEDNESDAY: day = "wed"; break; case Calendar.THURSDAY: day = "thu"; break; case Calendar.FRIDAY: day = "fri"; break; case Calendar.SATURDAY: day = "sat"; break; } return day; }
From source file:org.activequant.util.charting.IntradayMarketTimeline.java
private boolean isActiveDate(Calendar cal, Calendar cal2) { int day = cal.get(Calendar.DAY_OF_WEEK); long timeSinceStart = cal.get(Calendar.HOUR_OF_DAY) * 3600000 + cal.get(Calendar.MINUTE) * 60000 + cal.get(Calendar.SECOND) * 1000; boolean firstDate = false; if (day == Calendar.SUNDAY) { firstDate = (timeSinceStart > this.sundayStart && timeSinceStart < this.sundayEnd); } else if (day == Calendar.MONDAY) { firstDate = (timeSinceStart > this.mondayStart && timeSinceStart < this.mondayEnd); } else if (day == Calendar.TUESDAY) { firstDate = (timeSinceStart > this.tuesdayStart && timeSinceStart < this.tuesdayEnd); } else if (day == Calendar.WEDNESDAY) { firstDate = (timeSinceStart > this.wednesdayStart && timeSinceStart < this.wednesdayEnd); } else if (day == Calendar.THURSDAY) { firstDate = (timeSinceStart > this.thursdayStart && timeSinceStart < this.thursdayEnd); } else if (day == Calendar.FRIDAY) { firstDate = (timeSinceStart > this.fridayStart && timeSinceStart < this.fridayEnd); } else if (day == Calendar.SATURDAY) { firstDate = (timeSinceStart > this.saturdayStart && timeSinceStart < this.saturdayEnd); } else {/*from ww w. j av a 2 s . co m*/ firstDate = false; } int day2 = cal2.get(Calendar.DAY_OF_WEEK); timeSinceStart = cal2.get(Calendar.HOUR_OF_DAY) * 3600000 + cal2.get(Calendar.MINUTE) * 60000 + cal2.get(Calendar.SECOND) * 1000; boolean secondDate = false; if (day2 == Calendar.SUNDAY) { secondDate = (timeSinceStart > this.sundayStart && timeSinceStart < this.sundayEnd); } else if (day2 == Calendar.MONDAY) { secondDate = (timeSinceStart > this.mondayStart && timeSinceStart < this.mondayEnd); } else if (day2 == Calendar.TUESDAY) { secondDate = (timeSinceStart > this.tuesdayStart && timeSinceStart < this.tuesdayEnd); } else if (day2 == Calendar.WEDNESDAY) { secondDate = (timeSinceStart > this.wednesdayStart && timeSinceStart < this.wednesdayEnd); } else if (day2 == Calendar.THURSDAY) { secondDate = (timeSinceStart > this.thursdayStart && timeSinceStart < this.thursdayEnd); } else if (day2 == Calendar.FRIDAY) { secondDate = (timeSinceStart > this.fridayStart && timeSinceStart < this.fridayEnd); } else if (day2 == Calendar.SATURDAY) { secondDate = (timeSinceStart > this.saturdayStart && timeSinceStart < this.saturdayEnd); } else { secondDate = false; } return (firstDate && secondDate); }
From source file:com.seajas.search.attender.service.attender.dao.ProfileDAO.java
/** * Find all notifiable subscribers from the given profile. * /*from ww w . j a v a 2 s.c om*/ * @param calendar * @param profile * @return List<ProfileSubscriber> */ public List<ProfileSubscriber> findNotifiableSubscribers(final Calendar calendar, final List<ProfileSubscriber> subscribers) { if (!calendar.getTimeZone().getID().equals("UTC")) throw new IllegalArgumentException( "The given calendar must have a UTC timezone (has " + calendar.getTimeZone().getID() + ")"); // Calculate the current time in UTC Integer currentHour = calendar.get(Calendar.HOUR_OF_DAY), currentMinute = calendar.get(Calendar.MINUTE), currentDay = calendar.get(Calendar.DAY_OF_WEEK); Date currentTime = new Date(calendar.getTimeInMillis()); // Return a list of all applicable subscribers for this profile List<ProfileSubscriber> result = new ArrayList<ProfileSubscriber>(); // Find all active profiles' confirmed subscribers whose notification preference fall within the current day and whose time // values are greater than or equal to the current hour / minute; then take 7 days for weekly updates, 1 for daily updates, // and 1 for weekdays where Saturday / Sunday are excluded for (ProfileSubscriber subscriber : subscribers) { Integer subscriberDay = subscriber.getNotificationDay(), subscriberHour = subscriber.getNotificationHour(), subscriberMinute = subscriber.getNotificationMinute(); Date lastNotification = subscriber.getLastNotification(); NotificationType subscriberType = subscriber.getNotificationType(); // Correct for the user-specific timezone TimeZone timeZone = TimeZone.getTimeZone(subscriber.getTimeZone()); // Take leap seconds into account, although we're not so precise to really care if (subscriberMinute != null) { subscriberMinute -= (int) ((timeZone.getOffset(calendar.getTimeInMillis()) % MILLISECONDS_PER_HOUR) / MILLISECONDS_PER_MINUTE); if (subscriberMinute < 0) { subscriberMinute += 60; subscriberHour--; } else if (subscriberMinute > 59) { subscriberMinute -= 60; subscriberHour++; } } if (subscriberHour != null) { subscriberHour -= (int) (timeZone.getOffset(calendar.getTimeInMillis()) / MILLISECONDS_PER_HOUR); if (subscriberHour < 0) { subscriberHour += 24; if (subscriberDay != null) subscriberDay--; } else if (subscriberHour > 23) { subscriberHour -= 24; if (subscriberDay != null) subscriberDay++; } } if (subscriberDay == -1) subscriberDay = 6; else if (subscriberDay == 7) subscriberDay = 0; // Now determine the actual applicability (last_notification is stored as a UTC date, so does not need to be converted) if (subscriber.getIsConfirmed() && ((subscriberType.equals(NotificationType.Weekly) && subscriberDay.equals(currentDay) && subscriberHour <= currentHour && subscriberMinute <= currentMinute && dateDifference(lastNotification, currentTime) >= 6) || (subscriberType.equals(NotificationType.Weekdays) && currentDay != Calendar.SATURDAY && currentDay != Calendar.SUNDAY && subscriberHour <= currentHour && subscriberMinute <= currentMinute && !DateUtils.isSameDay(lastNotification, currentTime)) || (subscriberType.equals(NotificationType.Daily) && subscriberHour <= currentHour && subscriberMinute <= currentMinute && !DateUtils.isSameDay(lastNotification, currentTime)))) { if (logger.isInfoEnabled()) logger.info("Adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' to be notified"); result.add(subscriber); } else if (logger.isDebugEnabled()) { if (!subscriber.getIsConfirmed()) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - not confirmed"); else if (subscriberType.equals(NotificationType.Direct)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - direct notifications are handled by search-enricher instances"); else if (subscriberType.equals(NotificationType.Weekly)) { if (!subscriberDay.equals(currentDay)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - weekly notification does not fall on current day"); if (!(subscriberHour <= currentHour && subscriberMinute <= currentMinute)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - weekly notification falls outside of current time"); if (!(dateDifference(lastNotification, currentTime) >= 6)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - weekly notification difference (in days) smaller than 7"); } else if (subscriberType.equals(NotificationType.Weekdays)) { if (!(currentDay != Calendar.SATURDAY && currentDay != Calendar.SUNDAY)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - weekday notification does not fall on weekday"); if (!(subscriberHour <= currentHour && subscriberMinute <= currentMinute)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - weekday notification falls outside of current time"); if (DateUtils.isSameDay(lastNotification, currentTime)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - weekday notification difference indicates a notification has already gone out today"); } else if (subscriberType.equals(NotificationType.Daily)) { if (!(subscriberHour <= currentHour && subscriberMinute <= currentMinute)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - daily notification falls outside of current time"); if (DateUtils.isSameDay(lastNotification, currentTime)) logger.debug("Not adding subscriber '" + subscriber.getUniqueId() + "' with e-mail '" + subscriber.getEmail() + "' - daily notification difference indicates a notification has already gone out today"); } } } return result; }
From source file:com.pukulab.puku0x.gscalendar.CalendarActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calendar); // ?/*from w w w .j ava 2 s . c o m*/ mBackKeyTimer = new CountDownTimer(2000, 2000) { @Override public void onTick(long millisUntilFinished) { } @Override public void onFinish() { mBackKeyPressed = false; } }; // ? Bundle extras = getIntent().getExtras(); // ? if (mLoginUser == null) { mLoginUser = (UserData) extras.getSerializable(ARGS_LOGIN_USER); } // if (mDisplayedUser == null) { mDisplayedUser = (UserData) extras.getSerializable(ARGS_DISPLAYED_USER); } // ? if (mDisplayedDate == null) { mDisplayedDate = (Date) extras.getSerializable(ARGS_DISPLAYED_DATE); mLastDisplayedDate = mDisplayedDate; } // ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { // ????????? if (mDisplayedUser.usid != null && !mDisplayedUser.usid.equals(mLoginUser.usid)) { actionBar.setDisplayHomeAsUpEnabled(true); } // actionBar.setTitle(mDisplayedUser.name); actionBar.setSubtitle(DateFormat.format(getString(R.string.date_year_month_day), mDisplayedDate)); } // Retrieve the CalendarView mCalendarView = (MultiCalendarView) findViewById(R.id.calendarView); mProgressBar = (ProgressBar) findViewById(R.id.pb_detail); //mScheduleLayout = (LinearLayout) findViewById(R.id.scheduleList); // ? mScheduleDataList = new ArrayList<>(); mDailyScheduleList = new ArrayList<>(); mDailyScheduleaListAdapter = new ScheduleDataAdapter(CalendarActivity.this, 0, mDailyScheduleList); mDailyScheduleListView = (ListView) findViewById(R.id.lv_schedule); mDailyScheduleListView.setAdapter(mDailyScheduleaListAdapter); mDailyScheduleListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ListView listView = (ListView) parent; Schedule schedule = (Schedule) listView.getItemAtPosition(position); // ??? mLastSchedule = new Schedule(schedule); // ?? Intent intent = DetailActivity.createIntent(CalendarActivity.this, mLoginUser, mDisplayedUser, schedule); int requestCode = DetailActivity.REQUEST_DETAIL; startActivityForResult(intent, requestCode); } }); // Set the first valid day final Calendar firstValidDay = Calendar.getInstance(); firstValidDay.add(Calendar.YEAR, -1); firstValidDay.set(Calendar.DAY_OF_MONTH, 1); firstValidDay.set(Calendar.HOUR_OF_DAY, 0); firstValidDay.set(Calendar.MINUTE, 0); firstValidDay.set(Calendar.SECOND, 0); firstValidDay.set(Calendar.MILLISECOND, 0); mCalendarView.setFirstValidDay(firstValidDay); // Set the last valid day final Calendar lastValidDay = Calendar.getInstance(); lastValidDay.add(Calendar.YEAR, 1); lastValidDay.set(Calendar.HOUR_OF_DAY, 0); lastValidDay.set(Calendar.MINUTE, 0); lastValidDay.set(Calendar.SECOND, 0); lastValidDay.set(Calendar.MILLISECOND, 0); mCalendarView.setLastValidDay(lastValidDay); // ~ mCalendarView.setFirstDayOfWeek(Calendar.SUNDAY); mCalendarView.setLastDayOfWeek(Calendar.SATURDAY); // Create adapter final CustomDayAdapter adapter = new CustomDayAdapter(); // Set listener and adapter mCalendarView.setOnDayClickListener(this); mCalendarView.getIndicator().setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { //System.out.println("position:" + position); final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis((mCalendarView.getFirstValidDay().getTimeInMillis())); cal.add(Calendar.MONTH, position); mStartDate = cal.getTime(); cal.add(Calendar.MONTH, 1); mEndDate = cal.getTime(); mViewPagerPosition = position; new DisplaySchedulesTask(CalendarActivity.this, mDisplayedUser, mDisplayedDate).execute(mStartDate, mEndDate); } @Override public void onPageScrollStateChanged(int state) { } }); mCalendarView.setDayAdapter(adapter); // ???????? mCalendarView.setViewPagerPosition(12); }
From source file:com.codetroopers.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment.java
public CalendarDatePickerDialogFragment setFirstDayOfWeek(int startOfWeek) { if (startOfWeek < Calendar.SUNDAY || startOfWeek > Calendar.SATURDAY) { throw new IllegalArgumentException("Value must be between Calendar.SUNDAY and Calendar.SATURDAY"); }// w ww. ja va 2 s. co m mWeekStart = startOfWeek; if (mDayPickerView != null) { mDayPickerView.onChange(); } return this; }