Package: LocalizedDateTimeFormatters
LocalizedDateTimeFormatters
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getDateTimeFormatterFor(FormatStyle, Locale) |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * These Foolish Things - Miscellaneous utilities
6: * http://thesefoolishthings.tidalwave.it - git clone git@bitbucket.org:tidalwave/thesefoolishthings-src.git
7: * %%
8: * Copyright (C) 2009 - 2018 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: * $Id$
24: *
25: * *********************************************************************************************************************
26: * #L%
27: */
28: package it.tidalwave.util;
29:
30: import javax.annotation.Nonnull;
31: import java.time.format.DateTimeFormatter;
32: import java.time.format.FormatStyle;
33: import java.util.Locale;
34: import lombok.AccessLevel;
35: import lombok.NoArgsConstructor;
36:
37: /***********************************************************************************************************************
38: *
39: * A factory class for localized {@link DateTimeFormatter}s in various flavours, specified by the {@link FormatStyle}.
40: * This class is especially useful for migration to JDK 9+, where the default behaviour of
41: * {@code DateTimeFormatter.ofLocalizedDate/DateTime(...)} has changed.
42: *
43: * At the moment only locales for English and Italian are supported.
44: *
45: * @since 3.1-ALPHA-4
46: * @author Fabrizio Giudici
47: * @version $Id$
48: *
49: **********************************************************************************************************************/
50: @NoArgsConstructor(access = AccessLevel.PRIVATE)
51: public final class LocalizedDateTimeFormatters
52: {
53: /*******************************************************************************************************************
54: *
55: * Returns a formatter.
56: *
57: * @param style the style
58: * @param locale the locale
59: * @return the formatter
60: *
61: ******************************************************************************************************************/
62: @Nonnull
63: public static DateTimeFormatter getDateTimeFormatterFor (final @Nonnull FormatStyle style,
64: final @Nonnull Locale locale)
65: {
66: final String resourceName = "dateTimeFormatterPattern." + style.name();
67: final String pattern = BundleUtilities.getMessage(LocalizedDateTimeFormatters.class, locale, resourceName);
68: return DateTimeFormatter.ofPattern(pattern).withLocale(locale);
69: }
70: }