Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 1 | // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file for |
| 2 | // details. All rights reserved. Use of this source code is governed by a |
alanknight | 8754d38 | 2017-10-13 13:59:14 -0700 | [diff] [blame] | 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | /// API to allow setting Date/Time formatting in a custom way. |
| 6 | /// |
| 7 | /// It does not actually provide any data - that's left to the user of the API. |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 8 | import 'date_symbols.dart'; |
| 9 | import 'src/date_format_internal.dart'; |
alanknight | 8754d38 | 2017-10-13 13:59:14 -0700 | [diff] [blame] | 10 | |
| 11 | /// This should be called for at least one [locale] before any date |
| 12 | /// formatting methods are called. |
| 13 | /// |
| 14 | /// It sets up the lookup for date information. The [symbols] argument should |
| 15 | /// contain a populated [DateSymbols], and [patterns] should contain a Map for |
| 16 | /// the same locale from skeletons to the specific format strings. For examples, |
| 17 | /// see date_time_patterns.dart. |
| 18 | /// |
| 19 | /// If data for this locale has already been initialized it will be overwritten. |
| 20 | void initializeDateFormattingCustom( |
davidmorgan | bda4da8 | 2020-08-26 08:51:02 +0000 | [diff] [blame] | 21 | {String? locale, DateSymbols? symbols, Map<String, String>? patterns}) { |
alanknight | 8754d38 | 2017-10-13 13:59:14 -0700 | [diff] [blame] | 22 | initializeDateSymbols(_emptySymbols); |
| 23 | initializeDatePatterns(_emptyPatterns); |
Dart Team | 795c490 | 2019-08-29 10:58:28 -0700 | [diff] [blame] | 24 | if (symbols == null) { |
| 25 | throw ArgumentError('Missing DateTime formatting symbols'); |
| 26 | } |
| 27 | if (patterns == null) { |
| 28 | throw ArgumentError('Missing DateTime formatting patterns'); |
| 29 | } |
| 30 | if (locale != symbols.NAME) { |
| 31 | throw ArgumentError.value( |
| 32 | [locale, symbols.NAME], 'Locale does not match symbols.NAME'); |
| 33 | } |
alanknight | 8754d38 | 2017-10-13 13:59:14 -0700 | [diff] [blame] | 34 | dateTimeSymbols[symbols.NAME] = symbols; |
| 35 | dateTimePatterns[symbols.NAME] = patterns; |
| 36 | } |
| 37 | |
| 38 | Map<String, DateSymbols> _emptySymbols() => {}; |
| 39 | Map<String, Map<String, String>> _emptyPatterns() => {}; |