h-1 lebaran
This commit is contained in:
@ -1,43 +0,0 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// Kelas pembantu untuk manipulasi tanggal dan waktu
|
||||
class DateHelper {
|
||||
/// Format tanggal ke format Indonesia (dd MMM yyyy)
|
||||
static String formatDate(
|
||||
DateTime? dateTime, {
|
||||
String format = 'dd MMM yyyy',
|
||||
String locale = 'id_ID',
|
||||
String defaultValue = 'Belum ditentukan',
|
||||
}) {
|
||||
if (dateTime == null) return defaultValue;
|
||||
try {
|
||||
return DateFormat(format, locale).format(dateTime.toLocal());
|
||||
} catch (e) {
|
||||
return dateTime.toString().split(' ')[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// Format nilai ke dalam format mata uang Rupiah
|
||||
static String formatRupiah(
|
||||
num? value, {
|
||||
String symbol = 'Rp',
|
||||
int decimalDigits = 0,
|
||||
String defaultValue = 'Rp 0',
|
||||
}) {
|
||||
if (value == null) return defaultValue;
|
||||
try {
|
||||
final formatter = NumberFormat.currency(
|
||||
locale: 'id_ID',
|
||||
symbol: '$symbol ',
|
||||
decimalDigits: decimalDigits,
|
||||
);
|
||||
return formatter.format(value);
|
||||
} catch (e) {
|
||||
// Format manual
|
||||
return '$symbol ${value.toStringAsFixed(decimalDigits).replaceAllMapped(
|
||||
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
|
||||
(Match m) => '${m[1]}.',
|
||||
)}';
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import 'package:intl/intl.dart';
|
||||
///
|
||||
/// Kelas ini berisi fungsi-fungsi untuk memformat dan memanipulasi
|
||||
/// tanggal dan waktu.
|
||||
class DateTimeHelper {
|
||||
class FormatHelper {
|
||||
/// Mengkonversi DateTime dari UTC ke timezone lokal
|
||||
static DateTime toLocalDateTime(DateTime utcDateTime) {
|
||||
return utcDateTime.toLocal();
|
||||
@ -70,7 +70,6 @@ class DateTimeHelper {
|
||||
static String formatDateTime(
|
||||
DateTime? dateTime, {
|
||||
String format = 'dd MMM yyyy HH:mm',
|
||||
String locale = 'id_ID',
|
||||
String defaultValue = 'Belum ditentukan',
|
||||
}) {
|
||||
if (dateTime == null) return defaultValue;
|
||||
@ -78,7 +77,7 @@ class DateTimeHelper {
|
||||
// Pastikan tanggal dan waktu dalam timezone lokal
|
||||
final localDateTime = toLocalDateTime(dateTime);
|
||||
try {
|
||||
return DateFormat(format, locale).format(localDateTime);
|
||||
return DateFormat(format).format(localDateTime);
|
||||
} catch (e) {
|
||||
print('Error formatting date time: $e');
|
||||
return localDateTime.toString(); // Fallback to basic format
|
||||
@ -197,8 +196,10 @@ class DateTimeHelper {
|
||||
final String tanggal = localDateTime.day.toString().padLeft(2, '0');
|
||||
final String bulan = namaBulan[localDateTime.month - 1];
|
||||
final String tahun = localDateTime.year.toString();
|
||||
final String jam = localDateTime.hour.toString().padLeft(2, '0');
|
||||
final String menit = localDateTime.minute.toString().padLeft(2, '0');
|
||||
|
||||
return '$hari, $tanggal $bulan $tahun';
|
||||
return '$hari, $tanggal $bulan $tahun $jam:$menit';
|
||||
}
|
||||
|
||||
/// Format angka dengan pemisah ribuan
|
||||
|
Reference in New Issue
Block a user