Skip to content

Add example to package:intl #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkgs/intl/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
30 changes: 30 additions & 0 deletions pkgs/intl/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
69 changes: 69 additions & 0 deletions pkgs/intl/example/bin/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:intl/intl.dart';

void main(List<String> arguments) {
// These examples were all run with locale en_US.

final numberFormatters = [
NumberFormat.compact(), // 2M
NumberFormat.compactCurrency(), // USD2M
NumberFormat.compactLong(), // 2 million
NumberFormat.compactSimpleCurrency(), // $2M
NumberFormat.currency(), // USD2,000,000.33
NumberFormat.decimalPattern(), // 2,000,000.335
NumberFormat.decimalPatternDigits(decimalDigits: 2), // 2,000,000.33
NumberFormat.decimalPercentPattern(decimalDigits: 1), // 200,000,033.5%
NumberFormat.percentPattern(), // 200,000,033%
NumberFormat.scientificPattern(), // 2E6
NumberFormat.simpleCurrency(), // $2,000,000.33
];
print('Number formatting:');
for (final formatter in numberFormatters) {
print(formatter.format(2000000.33454));
}

final dateFormatters = [
DateFormat.d(), // 26
DateFormat.E(), // Wed
DateFormat.EEEE(), // Wednesday
DateFormat.EEEEE(), // W
DateFormat.LLL(), // Apr
DateFormat.LLLL(), // April
DateFormat.M(), // 4
DateFormat.Md(), // 4/26
DateFormat.MEd(), // Wed, 4/26
DateFormat.MMM(), // Apr
DateFormat.MMMd(), // Apr 26
DateFormat.MMMEd(), // Wed, Apr 26
DateFormat.MMMM(), // April
DateFormat.MMMMd(), // April 26
DateFormat.MMMMEEEEd(), // Wednesday, April 26
DateFormat.QQQ(), // Q2
DateFormat.QQQQ(), // 2nd quarter
DateFormat.y(), // 2023
DateFormat.yM(), // 4/2023
DateFormat.yMd(), // 4/26/2023
DateFormat.yMEd(), // Wed, 4/26/2023
DateFormat.yMMM(), // Apr 2023
DateFormat.yMMMd(), // Apr 26, 2023
DateFormat.yMMMEd(), // Wed, Apr 26, 2023
DateFormat.yMMMM(), // April 2023
DateFormat.yMMMMd(), // April 26, 2023
DateFormat.yMMMMEEEEd(), // Wednesday, April 26, 2023
DateFormat.yQQQ(), // Q2 2023
DateFormat.yQQQQ(), // 2nd quarter 2023
DateFormat.H(), // 05
DateFormat.Hm(), // 05:24
DateFormat.Hms(), // 05:24:22
DateFormat.j(), // 5 AM
DateFormat.jm(), // 5:24 AM
DateFormat.jms(), // 5:24:22 AM
];
print('Date formatting:');
for (final formatter in dateFormatters) {
print(formatter.format(DateTime(2023, 4, 26, 5, 24, 22, 1, 5)));
}
}
14 changes: 14 additions & 0 deletions pkgs/intl/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: example
description: A sample command-line application.

environment:
sdk: ^3.0.0

# Add regular dependencies here.
dependencies:
intl:
path: ../

dev_dependencies:
lints: ^3.0.0
test: ^1.24.0