Compare commits
2 Commits
43153f9b0d
...
3d43d7a934
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d43d7a934 | ||
|
|
e732a27914 |
33
lib/common/extension/date_extension.dart
Normal file
33
lib/common/extension/date_extension.dart
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1 +1,5 @@
|
|||||||
// TODO: define your code
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
part 'int_extension.dart';
|
||||||
|
part 'date_extension.dart';
|
||||||
|
part 'string_extension.dart';
|
||||||
|
|||||||
9
lib/common/extension/int_extension.dart
Normal file
9
lib/common/extension/int_extension.dart
Normal 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);
|
||||||
|
}
|
||||||
28
lib/common/extension/string_extension.dart
Normal file
28
lib/common/extension/string_extension.dart
Normal 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(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user