diff --git a/lib/common/extension/date_extension.dart b/lib/common/extension/date_extension.dart index 292a27b..0c552fd 100644 --- a/lib/common/extension/date_extension.dart +++ b/lib/common/extension/date_extension.dart @@ -1,33 +1,33 @@ -import 'package:intl/intl.dart'; +part of 'extension.dart'; extension DateTimeIndonesia on DateTime { /// Format: 13 Agustus 2025 - String toDate() { + String get toDate { return DateFormat('d MMMM yyyy', 'id_ID').format(this); } /// Format: 13 Agustus 2025 20:00 - String toDatetime() { + String get toDatetime { return DateFormat('d MMMM yyyy HH:mm', 'id_ID').format(this); } /// Format: Rabu, 13 Agustus 2025 - String toDayDate() { + String get toDayDate { return DateFormat('EEEE, d MMMM yyyy', 'id_ID').format(this); } /// Format: 13/08/2025 - String toShortDate() { + String get toShortDate { return DateFormat('dd/MM/yyyy', 'id_ID').format(this); } /// Format: 13-08-2025 - String toSeverDate() { + String get toServerDate { return DateFormat('dd-MM-yyyy', 'id_ID').format(this); } /// Format jam: 14:30 - String toHourMinute() { + String get toHourMinute { return DateFormat('HH:mm', 'id_ID').format(this); } } diff --git a/lib/common/extension/extension.dart b/lib/common/extension/extension.dart index 7199fdd..12aec9b 100644 --- a/lib/common/extension/extension.dart +++ b/lib/common/extension/extension.dart @@ -1 +1,5 @@ - // TODO: define your code +import 'package:intl/intl.dart'; + +part 'int_extension.dart'; +part 'date_extension.dart'; +part 'string_extension.dart'; diff --git a/lib/common/extension/int_extension.dart b/lib/common/extension/int_extension.dart new file mode 100644 index 0000000..b9f4180 --- /dev/null +++ b/lib/common/extension/int_extension.dart @@ -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); +} diff --git a/lib/common/extension/string_extension.dart b/lib/common/extension/string_extension.dart new file mode 100644 index 0000000..23687e9 --- /dev/null +++ b/lib/common/extension/string_extension.dart @@ -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(' '); + } +}