-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DateFormatterUtil now supports locales
- Loading branch information
1 parent
dd3f810
commit 1b96f5d
Showing
2 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# 0.11.0 | ||
|
||
## Feat | ||
|
||
- DateFormatterUtil now supports locales | ||
|
||
# 0.10.0 | ||
|
||
## Feat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:intl/intl.dart'; | ||
|
||
class DateFormatterUtil { | ||
const DateFormatterUtil._(); | ||
static String formatDate(DateTime date) { | ||
static String formatDate(DateTime date, [Locale? locale]) { | ||
final localDate = date.toLocal(); | ||
final dateFormat = DateFormat('dd/MM/yyyy'); | ||
final dateFormat = DateFormat('dd/MM/yyyy', locale?.languageCode); | ||
return dateFormat.format(localDate); | ||
} | ||
|
||
static String formatTime(DateTime date) { | ||
static String formatTime(DateTime date, [Locale? locale]) { | ||
final localDate = date.toLocal(); | ||
final dateFormat = DateFormat('HH:mm'); | ||
final dateFormat = DateFormat('HH:mm', locale?.languageCode); | ||
return dateFormat.format(localDate); | ||
} | ||
|
||
static String formatDateTime(DateTime date) { | ||
static String formatDateTime(DateTime date, [Locale? locale]) { | ||
final localDate = date.toLocal(); | ||
final dateFormat = DateFormat('dd/MM/yyyy HH:mm'); | ||
final dateFormat = DateFormat('dd/MM/yyyy HH:mm', locale?.languageCode); | ||
return dateFormat.format(localDate); | ||
} | ||
|
||
static String customFormat(DateTime date, String format) { | ||
static String customFormat(DateTime date, String format, [Locale? locale]) { | ||
final localDate = date.toLocal(); | ||
final dateFormat = DateFormat(format); | ||
final dateFormat = DateFormat(format, locale?.languageCode); | ||
return dateFormat.format(localDate); | ||
} | ||
} |