Example usage for com.google.gwt.i18n.client LocaleInfo getDateTimeConstants

List of usage examples for com.google.gwt.i18n.client LocaleInfo getDateTimeConstants

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client LocaleInfo getDateTimeConstants.

Prototype

public final DateTimeConstants getDateTimeConstants() 

Source Link

Document

Returns a DateTimeConstants instance for this locale.

Usage

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

License:Apache License

/**
 * Replaces month names in the entered date with the name in the current
 * browser locale.//from  w w w . j a  v  a 2  s. co  m
 *
 * @param enteredDate
 *            Date string e.g. "5 May 2010"
 * @param formatString
 *            Format string e.g. "d M yyyy"
 * @return The date string where the month names have been replaced by the
 *         browser locale version
 */
private String parseMonthName(String enteredDate, String formatString) {
    LocaleInfo browserLocale = LocaleInfo.getCurrentLocale();
    if (browserLocale.getLocaleName().equals(getLocale())) {
        // No conversion needs to be done when locales match
        return enteredDate;
    }
    String[] browserMonthNames = browserLocale.getDateTimeConstants().months();
    String[] browserShortMonthNames = browserLocale.getDateTimeConstants().shortMonths();

    if (formatString.contains("MMMM")) {
        // Full month name
        for (int i = 0; i < 12; i++) {
            enteredDate = enteredDate.replaceAll(getMonth(i), browserMonthNames[i]);
        }
    }
    if (formatString.contains("MMM")) {
        // Short month name
        for (int i = 0; i < 12; i++) {
            enteredDate = enteredDate.replaceAll(getShortMonth(i), browserShortMonthNames[i]);
        }
    }

    return enteredDate;
}