28 lines
810 B
Dart
28 lines
810 B
Dart
import 'package:intl/intl.dart';
|
|
|
|
class DateFormatter {
|
|
static String formatDate(DateTime? date,
|
|
{String format = 'dd MMMM yyyy',
|
|
String locale = 'id_ID',
|
|
String defaultValue = '-'}) {
|
|
if (date == null) return defaultValue;
|
|
try {
|
|
return DateFormat(format, locale).format(date);
|
|
} catch (e) {
|
|
print('Error formatting date: $e');
|
|
return date.toString().split(' ')[0]; // Fallback to basic format
|
|
}
|
|
}
|
|
|
|
static String formatNumber(num? number,
|
|
{String locale = 'id_ID', String defaultValue = '0'}) {
|
|
if (number == null) return defaultValue;
|
|
try {
|
|
return NumberFormat("#,##0.##", locale).format(number);
|
|
} catch (e) {
|
|
print('Error formatting number: $e');
|
|
return number.toString(); // Fallback to basic format
|
|
}
|
|
}
|
|
}
|