Skip to content

Commit

Permalink
feat: DateFormatterUtil now supports locales
Browse files Browse the repository at this point in the history
  • Loading branch information
vanlooverenkoen committed Feb 19, 2025
1 parent dd3f810 commit 1b96f5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
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
Expand Down
18 changes: 10 additions & 8 deletions lib/src/util/date_formatter/date_formatter_util.dart
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);
}
}

0 comments on commit 1b96f5d

Please sign in to comment.