blob: 3da1abf8846502f8e8ffed82e71596b75dccbb44 [file] [log] [blame]
Dart Team795c4902019-08-29 10:58:28 -07001// 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
alanknight8754d382017-10-13 13:59:14 -07003// 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 Team795c4902019-08-29 10:58:28 -07008import 'date_symbols.dart';
9import 'src/date_format_internal.dart';
alanknight8754d382017-10-13 13:59:14 -070010
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.
20void initializeDateFormattingCustom(
davidmorganbda4da82020-08-26 08:51:02 +000021 {String? locale, DateSymbols? symbols, Map<String, String>? patterns}) {
alanknight8754d382017-10-13 13:59:14 -070022 initializeDateSymbols(_emptySymbols);
23 initializeDatePatterns(_emptyPatterns);
Dart Team795c4902019-08-29 10:58:28 -070024 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 }
alanknight8754d382017-10-13 13:59:14 -070034 dateTimeSymbols[symbols.NAME] = symbols;
35 dateTimePatterns[symbols.NAME] = patterns;
36}
37
38Map<String, DateSymbols> _emptySymbols() => {};
39Map<String, Map<String, String>> _emptyPatterns() => {};