Search in sources :

Example 1 with NSTimestampFormatter

use of com.webobjects.foundation.NSTimestampFormatter in project wonder-slim by undur.

the class AjaxDatePicker method awake.

/**
 * Sets up format / formatter values.
 */
@Override
public void awake() {
    super.awake();
    if (!(hasBinding("formatter") || hasBinding("format"))) {
        // Default
        format = "%m %d %Y";
        formatter = new NSTimestampFormatter(format);
    } else if (hasBinding("formatter")) {
        formatter = (Format) valueForBinding("formatter");
        if (formatter instanceof NSTimestampFormatter) {
            format = ((NSTimestampFormatter) formatter).pattern();
        } else if (formatter instanceof SimpleDateFormat) {
            format = ((SimpleDateFormat) formatter).toPattern();
        } else {
            throw new RuntimeException("Can't handle formatter of class " + formatter.getClass().getCanonicalName());
        }
    } else {
        format = (String) valueForBinding("format");
        formatter = new NSTimestampFormatter(format);
    }
    format = translateSimpleDateFormatSymbols(format);
}
Also used : Format(java.text.Format) SimpleDateFormat(java.text.SimpleDateFormat) NSTimestampFormatter(com.webobjects.foundation.NSTimestampFormatter) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with NSTimestampFormatter

use of com.webobjects.foundation.NSTimestampFormatter in project wonder-slim by undur.

the class ERXTimestampFormatter method dateFormatterForPattern.

/**
 * Returns a shared instance for the specified pattern.
 *
 * @return shared instance of formatter
 */
public static NSTimestampFormatter dateFormatterForPattern(String pattern) {
    NSTimestampFormatter formatter;
    if (ERXLocalizer.useLocalizedFormatters()) {
        ERXLocalizer localizer = ERXLocalizer.currentLocalizer();
        formatter = (NSTimestampFormatter) localizer.localizedDateFormatForKey(pattern);
    } else {
        synchronized (_repository) {
            formatter = _repository.get(pattern);
            if (formatter == null) {
                formatter = new NSTimestampFormatter(pattern);
                _repository.put(pattern, formatter);
            }
        }
    }
    return formatter;
}
Also used : ERXLocalizer(er.extensions.localization.ERXLocalizer) NSTimestampFormatter(com.webobjects.foundation.NSTimestampFormatter)

Example 3 with NSTimestampFormatter

use of com.webobjects.foundation.NSTimestampFormatter in project wonder-slim by undur.

the class ERXLocalizer method localizedDateFormatForKey.

/**
 * Returns a localized date formatter for the given key.
 *
 * @return the formatter object
 */
public Format localizedDateFormatForKey(String formatString) {
    formatString = formatString == null ? ERXTimestampFormatter.DEFAULT_PATTERN : formatString;
    formatString = localizedStringForKeyWithDefault(formatString);
    Format result = _dateFormatters.get(formatString);
    if (result == null) {
        Locale current = locale();
        NSTimestampFormatter formatter = new NSTimestampFormatter(formatString, new DateFormatSymbols(current));
        result = formatter;
        _dateFormatters.put(formatString, result);
    }
    return result;
}
Also used : Locale(java.util.Locale) Format(java.text.Format) DateFormatSymbols(java.text.DateFormatSymbols) NSTimestampFormatter(com.webobjects.foundation.NSTimestampFormatter)

Aggregations

NSTimestampFormatter (com.webobjects.foundation.NSTimestampFormatter)3 Format (java.text.Format)2 ERXLocalizer (er.extensions.localization.ERXLocalizer)1 DateFormatSymbols (java.text.DateFormatSymbols)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (java.util.Locale)1