Skip to content

Commit 7ebcd82

Browse files
Merge pull request #1020 from dart-lang:updateIntlExample
PiperOrigin-RevId: 827919259
2 parents d2395d4 + 00af44e commit 7ebcd82

File tree

2 files changed

+52
-48
lines changed

2 files changed

+52
-48
lines changed

pkgs/intl/example/bin/example.dart

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,68 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:intl/date_symbol_data_local.dart';
56
import 'package:intl/intl.dart';
67

7-
void main(List<String> arguments) {
8+
Future<void> main(List<String> arguments) async {
89
// These examples were all run with locale en_US.
910

11+
String? locale = 'en_US';
12+
await initializeDateFormatting(locale);
1013
final numberFormatters = [
11-
NumberFormat.compact(), // 2M
12-
NumberFormat.compactCurrency(), // USD2M
13-
NumberFormat.compactLong(), // 2 million
14-
NumberFormat.compactSimpleCurrency(), // $2M
15-
NumberFormat.currency(), // USD2,000,000.33
16-
NumberFormat.decimalPattern(), // 2,000,000.335
14+
NumberFormat.compact(locale: locale), // 2M
15+
NumberFormat.compactCurrency(locale: locale), // USD2M
16+
NumberFormat.compactLong(locale: locale), // 2 million
17+
NumberFormat.compactSimpleCurrency(locale: locale), // $2M
18+
NumberFormat.currency(locale: locale), // USD2,000,000.33
19+
NumberFormat.decimalPattern(locale), // 2,000,000.335
1720
NumberFormat.decimalPatternDigits(decimalDigits: 2), // 2,000,000.33
1821
NumberFormat.decimalPercentPattern(decimalDigits: 1), // 200,000,033.5%
19-
NumberFormat.percentPattern(), // 200,000,033%
20-
NumberFormat.scientificPattern(), // 2E6
21-
NumberFormat.simpleCurrency(), // $2,000,000.33
22+
NumberFormat.percentPattern(locale), // 200,000,033%
23+
NumberFormat.scientificPattern(locale), // 2E6
24+
NumberFormat.simpleCurrency(locale: locale), // $2,000,000.33
2225
];
2326
print('Number formatting:');
2427
for (final formatter in numberFormatters) {
2528
print(formatter.format(2000000.33454));
2629
}
2730

2831
final dateFormatters = [
29-
DateFormat.d(), // 26
30-
DateFormat.E(), // Wed
31-
DateFormat.EEEE(), // Wednesday
32-
DateFormat.EEEEE(), // W
33-
DateFormat.LLL(), // Apr
34-
DateFormat.LLLL(), // April
35-
DateFormat.M(), // 4
36-
DateFormat.Md(), // 4/26
37-
DateFormat.MEd(), // Wed, 4/26
38-
DateFormat.MMM(), // Apr
39-
DateFormat.MMMd(), // Apr 26
40-
DateFormat.MMMEd(), // Wed, Apr 26
41-
DateFormat.MMMM(), // April
42-
DateFormat.MMMMd(), // April 26
43-
DateFormat.MMMMEEEEd(), // Wednesday, April 26
44-
DateFormat.QQQ(), // Q2
45-
DateFormat.QQQQ(), // 2nd quarter
46-
DateFormat.y(), // 2023
47-
DateFormat.yM(), // 4/2023
48-
DateFormat.yMd(), // 4/26/2023
49-
DateFormat.yMEd(), // Wed, 4/26/2023
50-
DateFormat.yMMM(), // Apr 2023
51-
DateFormat.yMMMd(), // Apr 26, 2023
52-
DateFormat.yMMMEd(), // Wed, Apr 26, 2023
53-
DateFormat.yMMMM(), // April 2023
54-
DateFormat.yMMMMd(), // April 26, 2023
55-
DateFormat.yMMMMEEEEd(), // Wednesday, April 26, 2023
56-
DateFormat.yQQQ(), // Q2 2023
57-
DateFormat.yQQQQ(), // 2nd quarter 2023
58-
DateFormat.H(), // 05
59-
DateFormat.Hm(), // 05:24
60-
DateFormat.Hms(), // 05:24:22
61-
DateFormat.j(), // 5 AM
62-
DateFormat.jm(), // 5:24 AM
63-
DateFormat.jms(), // 5:24:22 AM
32+
DateFormat.d(locale), // 26
33+
DateFormat.E(locale), // Wed
34+
DateFormat.EEEE(locale), // Wednesday
35+
DateFormat.EEEEE(locale), // W
36+
DateFormat.LLL(locale), // Apr
37+
DateFormat.LLLL(locale), // April
38+
DateFormat.M(locale), // 4
39+
DateFormat.Md(locale), // 4/26
40+
DateFormat.MEd(locale), // Wed, 4/26
41+
DateFormat.MMM(locale), // Apr
42+
DateFormat.MMMd(locale), // Apr 26
43+
DateFormat.MMMEd(locale), // Wed, Apr 26
44+
DateFormat.MMMM(locale), // April
45+
DateFormat.MMMMd(locale), // April 26
46+
DateFormat.MMMMEEEEd(locale), // Wednesday, April 26
47+
DateFormat.QQQ(locale), // Q2
48+
DateFormat.QQQQ(locale), // 2nd quarter
49+
DateFormat.y(locale), // 2023
50+
DateFormat.yM(locale), // 4/2023
51+
DateFormat.yMd(locale), // 4/26/2023
52+
DateFormat.yMEd(locale), // Wed, 4/26/2023
53+
DateFormat.yMMM(locale), // Apr 2023
54+
DateFormat.yMMMd(locale), // Apr 26, 2023
55+
DateFormat.yMMMEd(locale), // Wed, Apr 26, 2023
56+
DateFormat.yMMMM(locale), // April 2023
57+
DateFormat.yMMMMd(locale), // April 26, 2023
58+
DateFormat.yMMMMEEEEd(locale), // Wednesday, April 26, 2023
59+
DateFormat.yQQQ(locale), // Q2 2023
60+
DateFormat.yQQQQ(locale), // 2nd quarter 2023
61+
DateFormat.H(locale), // 05
62+
DateFormat.Hm(locale), // 05:24
63+
DateFormat.Hms(locale), // 05:24:22
64+
DateFormat.j(locale), // 5 AM
65+
DateFormat.jm(locale), // 5:24 AM
66+
DateFormat.jms(locale), // 5:24:22 AM
6467
];
6568
print('Date formatting:');
6669
for (final formatter in dateFormatters) {

pkgs/intl/example/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
name: example
22

3+
publish_to: none
4+
35
environment:
4-
sdk: ^3.0.0
6+
sdk: ^3.3.0
57

6-
# Add regular dependencies here.
78
dependencies:
89
intl:
910
path: ../
1011

1112
dev_dependencies:
12-
lints: ^4.0.0
13+
lints: ^6.0.0

0 commit comments

Comments
 (0)