This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// Label rentang periode ringkas, contoh: "27 Jul - 2 Agu 2026".
|
||||
String formatPeriodLabel(DateTime from, DateTime to) {
|
||||
final dayMonth = DateFormat('d MMM', 'id_ID');
|
||||
final dayMonthYear = DateFormat('d MMM yyyy', 'id_ID');
|
||||
|
||||
if (from.year == to.year && from.month == to.month && from.day == to.day) {
|
||||
return dayMonthYear.format(from);
|
||||
}
|
||||
if (from.year == to.year) {
|
||||
return '${dayMonth.format(from)} - ${dayMonthYear.format(to)}';
|
||||
}
|
||||
return '${dayMonthYear.format(from)} - ${dayMonthYear.format(to)}';
|
||||
}
|
||||
|
||||
/// Label bulan dari format API "2026-08" menjadi "Agustus 2026".
|
||||
String formatMonthLabel(String month, DateTime fallback) {
|
||||
final parts = month.split('-');
|
||||
if (parts.length == 2) {
|
||||
final year = int.tryParse(parts[0]);
|
||||
final monthNumber = int.tryParse(parts[1]);
|
||||
if (year != null && monthNumber != null) {
|
||||
return DateFormat(
|
||||
'MMMM yyyy',
|
||||
'id_ID',
|
||||
).format(DateTime(year, monthNumber));
|
||||
}
|
||||
}
|
||||
return DateFormat('MMMM yyyy', 'id_ID').format(fallback);
|
||||
}
|
||||
Reference in New Issue
Block a user