Compare commits

..

2 Commits

Author SHA1 Message Date
efrilm
3d43d7a934 feat: int and string extension 2025-08-13 00:26:59 +07:00
efrilm
e732a27914 feat: date extension 2025-08-13 00:22:49 +07:00
4 changed files with 75 additions and 1 deletions

View File

@ -0,0 +1,33 @@
part of 'extension.dart';
extension DateTimeIndonesia on DateTime {
/// Format: 13 Agustus 2025
String get toDate {
return DateFormat('d MMMM yyyy', 'id_ID').format(this);
}
/// Format: 13 Agustus 2025 20:00
String get toDatetime {
return DateFormat('d MMMM yyyy HH:mm', 'id_ID').format(this);
}
/// Format: Rabu, 13 Agustus 2025
String get toDayDate {
return DateFormat('EEEE, d MMMM yyyy', 'id_ID').format(this);
}
/// Format: 13/08/2025
String get toShortDate {
return DateFormat('dd/MM/yyyy', 'id_ID').format(this);
}
/// Format: 13-08-2025
String get toServerDate {
return DateFormat('dd-MM-yyyy', 'id_ID').format(this);
}
/// Format jam: 14:30
String get toHourMinute {
return DateFormat('HH:mm', 'id_ID').format(this);
}
}

View File

@ -1 +1,5 @@
// TODO: define your code import 'package:intl/intl.dart';
part 'int_extension.dart';
part 'date_extension.dart';
part 'string_extension.dart';

View File

@ -0,0 +1,9 @@
part of 'extension.dart';
extension IntegerExt on int {
String get currencyFormatRp => NumberFormat.currency(
locale: 'id',
symbol: 'Rp. ',
decimalDigits: 0,
).format(this);
}

View File

@ -0,0 +1,28 @@
part of 'extension.dart';
extension StringExt on String {
int get toIntegerFromText {
final cleanedText = replaceAll(RegExp(r'[^0-9]'), '');
final parsedValue = int.tryParse(cleanedText) ?? 0;
return parsedValue;
}
String get currencyFormatRpV2 {
final parsedValue = int.tryParse(this) ?? 0;
return NumberFormat.currency(
locale: 'id',
symbol: 'Rp. ',
decimalDigits: 0,
).format(parsedValue);
}
String get toTitleCase {
if (isEmpty) return '';
return split(' ')
.map((word) {
if (word.isEmpty) return '';
return word[0].toUpperCase() + word.substring(1).toLowerCase();
})
.join(' ');
}
}