Java Code Examples for java.util.Calendar.DAY_OF_WEEK

The following are Jave code examples for showing how to use DAY_OF_WEEK of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: airgram   File: FastDateParser.java   View Source Code Vote up 6 votes
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    switch (field) {
        case Calendar.AM_PM:
            return dfs.getAmPmStrings();
        case Calendar.DAY_OF_WEEK:
            return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
        case Calendar.ERA:
            return dfs.getEras();
        case Calendar.MONTH:
            return isLong ? dfs.getMonths() : dfs.getShortMonths();
    }
    return null;
}
 
Example 2
Project: CosmoCalendar   File: CalendarUtils.java   View Source Code Vote up 6 votes
public static boolean isDayDisabledByCriteria(Day day, DisabledDaysCriteria criteria) {
    int field = -1;
    switch (criteria.getCriteriaType()){
        case DAYS_OF_MONTH:
            field = Calendar.DAY_OF_MONTH;
            break;

        case DAYS_OF_WEEK:
            field = Calendar.DAY_OF_WEEK;
            break;
    }

    for(int dayInt : criteria.getDays()){
        if(dayInt == day.getCalendar().get(field)){
            return true;
        }
    }
    return false;
}
 
Example 3
Project: PlusGram   File: FastDateParser.java   View Source Code Vote up 6 votes
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    switch (field) {
        case Calendar.AM_PM:
            return dfs.getAmPmStrings();
        case Calendar.DAY_OF_WEEK:
            return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
        case Calendar.ERA:
            return dfs.getEras();
        case Calendar.MONTH:
            return isLong ? dfs.getMonths() : dfs.getShortMonths();
    }
    return null;
}
 
Example 4
Project: OpenJSharp   File: DateTimeTextProvider.java   View Source Code Vote up 6 votes
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
Example 5
Project: jdk8u-jdk   File: DateTimeTextProvider.java   View Source Code Vote up 6 votes
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
Example 6
Project: openjdk-jdk10   File: DateTimeTextProvider.java   View Source Code Vote up 6 votes
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
Example 7
Project: daily-menu-android   File: MenuPlanActivity.java   View Source Code Vote up 5 votes
@Override
public int getCount() {
    // Show 5 total pages.
    int mWeekDay = Calendar.DAY_OF_WEEK;
    if ( mWeekDay >= 3) {
        mWeekDay -= 3;
    } else if ( mWeekDay == 2) {
        mWeekDay = 6 - 1;
    } else if ( mWeekDay == 1) {
        mWeekDay = 6 - 2;
    } else if ( mWeekDay == 0) {
        mWeekDay = 6 -3;
    }
    return 5 - mWeekDay;
}
 
Example 8
Project: android_ui   File: MonthView.java   View Source Code Vote up 4 votes
/**
 * Obtains a name of a calendar field with the specified <var>field</var> identifier from the
 * given <var>calendar</var> for the specified <var>locale</var>.
 * <p>
 * <b>Note</b>, that for pre {@link android.os.Build.VERSION_CODES#GINGERBREAD GINGERBREAD} Android
 * version and field names listed below, this method will return only English name regardless
 * the specified <var>locale</var>:
 * <ul>
 * <li>{@link Calendar#MONTH}</li>
 * <li>{@link Calendar#DAY_OF_WEEK}</li>
 * </ul>
 *
 * @param calendar The calendar from which to obtain the requested field's name.
 * @param field    The desired field identifier. See {@link Calendar} for field identifiers.
 * @param style    Style flag for the requested name. One of {@link #CALENDAR_STYLE_SHORT} or
 *                 {@link #CALENDAR_STYLE_LONG}.
 * @param locale   The locale for which to obtain the requested name. If there is no name available
 *                 for the requested locale, {@link UiConfig#DEFAULT_LOCALE} will be used instead.
 * @return Name of the requested calendar field.
 */
@NonNull
@SuppressLint("NewApi")
public static String resolveCalendarFieldName(@NonNull Calendar calendar, int field, int style, @NonNull Locale locale) {
	if (!PRE_GINGERBREAD) {
		final String name = calendar.getDisplayName(field, style, locale);
		return name != null ? name : calendar.getDisplayName(field, style, UiConfig.DEFAULT_LOCALE);
	}
	switch (field) {
		case Calendar.MONTH:
			return PRE_GINGERBREAD_MONTH_NAMES[calendar.get(field)];
		case Calendar.DAY_OF_WEEK:
			return PRE_GINGERBREAD_DAY_NAMES[calendar.get(field) - 1];
	}
	return "";
}
 
Example 9
Project: MainCalendar   File: LunarCalendar.java   View Source Code Vote up 4 votes
/**
     * 获得属性的中文,可以使用的属性字段为DAY_OF_WEEK以及所有农历属性字段。
     * @param field 本类中定义的字段
     * @return 农历日期中文字符串
     */
    public String getLunar(@Field int field) {
        switch (field) {
            case LUNAR_YEAR:
                return getLunar(LUNAR_HEAVENLY_STEM)
                        + getLunar(LUNAR_EARTHLY_BRANCH);

            case LUNAR_MONTH:
                return getLunarMonth(lunarMonth);

            case LUNAR_DATE:
                return lunarDateNames[lunarDate];

            case LUNAR_SECTIONAL_TERM:
                return SolarTerm.getSectionalTermName(get(Calendar.MONTH));

            case LUNAR_PRINCIPLE_TERM:
                return SolarTerm.getPrincipleTermName(get(Calendar.MONTH));

            case LUNAR_HEAVENLY_STEM:
//                if (!areSolarTermsComputed) {
//                    computeSolarTerms();
//                    areSolarTermsComputed = true;
//                }
                return stemNames[get(field)];

            case LUNAR_EARTHLY_BRANCH:
//                if (!areSolarTermsComputed) {
//                    computeSolarTerms();
//                    areSolarTermsComputed = true;
//                }
                return branchNames[get(field)];

            case LUNAR_ANIMAL:
                return animalNames[get(field)];

            case Calendar.DAY_OF_WEEK:
                return lunarWeekNames[get(field)];

            default:
                throw new IllegalArgumentException("Not supported field: " + field);
        }
    }
 
Example 10
Project: daily-menu-android   File: MenuPlanActivity.java   View Source Code Vote up 4 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_menu_plan, container, false);
    Log.i("current weekday: ", String.valueOf(mWeekDay));
    mWeekDay = Calendar.DAY_OF_WEEK;
    if ( mWeekDay >= 3) {
        mWeekDay -= 3;
    } else if ( mWeekDay == 2) {
        mWeekDay = 6 - 1;
    } else if ( mWeekDay == 1) {
        mWeekDay = 6 - 2;
    } else if ( mWeekDay == 0) {
        mWeekDay = 6 -3;
    }
    mMenus = new ArrayList<>();
    mMenuAdapter = new MenuAdapter(R.layout.list_item, mMenus);
    mMenuRecyclerView = (RecyclerView)rootView.findViewById(R.id.menu_recycler_view);
    mMenuRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mMenuRecyclerView.setHasFixedSize(false);
    mMenuRecyclerView.setAdapter(mMenuAdapter);
    //mRestaurantName

    final MenuPlanService menuPlanService = MenuPlanService.retrofit.create(MenuPlanService.class);
    menuPlanService.getMenuPlanByRestaurantAndDay(mRestaurantShortcut,mDay)
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .map(new Func1<Response<MenuPlan>, MenuPlan>() {
                @Override
                public MenuPlan call(Response<MenuPlan> menuPlanResponse) {
                    return menuPlanResponse.getData();
                }
            })
            .subscribe(new Subscriber<MenuPlan>() {
                @Override
                public void onCompleted() {
                    Log.i("Finished call", "Rx Call is finished");
                }

                @Override
                public void onError(Throwable e) {
                    Log.e("Error", "An error occured", e);
                }

                @Override
                public void onNext(MenuPlan menuPlan) {
                    final TextView menuPlanDateTextView = (TextView) rootView.findViewById(R.id.menu_plan_date);
                    SimpleDateFormat simpleDate =  new SimpleDateFormat("dd.MM.yyyy");
                    menuPlanDateTextView.setText(simpleDate.format(menuPlan.getDate()));
                    final TextView restaurantNameTextView = (TextView) rootView.findViewById(R.id.restaurant_name);
                    restaurantNameTextView.setText(mRestaurantShortcut);
                    mMenus.addAll(menuPlan.getMenus());
                    mMenuAdapter.notifyDataSetChanged();
                }
            });
    return rootView;
}