Example usage for com.vaadin.client LocaleService getFirstDayOfWeek

List of usage examples for com.vaadin.client LocaleService getFirstDayOfWeek

Introduction

In this page you can find the example usage for com.vaadin.client LocaleService getFirstDayOfWeek.

Prototype

public static int getFirstDayOfWeek(String locale) throws LocaleNotLoadedException 

Source Link

Usage

From source file:com.vaadin.client.DateTimeService.java

License:Apache License

/**
 * Returns the first day of the week, according to the used Locale.
 *
 * @return the localized first day of the week, {@code 0} is {@code SUNDAY}
 *//*w w  w  .  jav  a2s.  c om*/
public int getFirstDayOfWeek() {
    try {
        return LocaleService.getFirstDayOfWeek(locale);
    } catch (final LocaleNotLoadedException e) {
        getLogger().log(Level.SEVERE, "Error in getFirstDayOfWeek", e);
        return 0;
    }
}

From source file:com.vaadin.client.DateTimeService.java

License:Apache License

/**
 * Returns the first day of week of the specified {@code month}.
 *
 * @param month/* w  w w.ja v  a2  s  . c  o  m*/
 *            the month, not {@code null}
 * @return the first day of week,
 */
public int getStartWeekDay(Date month) {
    final Date dateForFirstOfThisMonth = new Date(month.getYear(), month.getMonth(), 1);
    int firstDay;
    try {
        firstDay = LocaleService.getFirstDayOfWeek(locale);
    } catch (final LocaleNotLoadedException e) {
        getLogger().log(Level.SEVERE, "Locale not loaded, using fallback 0", e);
        firstDay = 0;
    }
    int start = dateForFirstOfThisMonth.getDay() - firstDay;
    if (start < 0) {
        start += 7;
    }
    return start;
}