feat: int and string extension
This commit is contained in:
parent
e732a27914
commit
3d43d7a934
@ -1,33 +1,33 @@
|
|||||||
import 'package:intl/intl.dart';
|
part of 'extension.dart';
|
||||||
|
|
||||||
extension DateTimeIndonesia on DateTime {
|
extension DateTimeIndonesia on DateTime {
|
||||||
/// Format: 13 Agustus 2025
|
/// Format: 13 Agustus 2025
|
||||||
String toDate() {
|
String get toDate {
|
||||||
return DateFormat('d MMMM yyyy', 'id_ID').format(this);
|
return DateFormat('d MMMM yyyy', 'id_ID').format(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format: 13 Agustus 2025 20:00
|
/// Format: 13 Agustus 2025 20:00
|
||||||
String toDatetime() {
|
String get toDatetime {
|
||||||
return DateFormat('d MMMM yyyy HH:mm', 'id_ID').format(this);
|
return DateFormat('d MMMM yyyy HH:mm', 'id_ID').format(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format: Rabu, 13 Agustus 2025
|
/// Format: Rabu, 13 Agustus 2025
|
||||||
String toDayDate() {
|
String get toDayDate {
|
||||||
return DateFormat('EEEE, d MMMM yyyy', 'id_ID').format(this);
|
return DateFormat('EEEE, d MMMM yyyy', 'id_ID').format(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format: 13/08/2025
|
/// Format: 13/08/2025
|
||||||
String toShortDate() {
|
String get toShortDate {
|
||||||
return DateFormat('dd/MM/yyyy', 'id_ID').format(this);
|
return DateFormat('dd/MM/yyyy', 'id_ID').format(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format: 13-08-2025
|
/// Format: 13-08-2025
|
||||||
String toSeverDate() {
|
String get toServerDate {
|
||||||
return DateFormat('dd-MM-yyyy', 'id_ID').format(this);
|
return DateFormat('dd-MM-yyyy', 'id_ID').format(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format jam: 14:30
|
/// Format jam: 14:30
|
||||||
String toHourMinute() {
|
String get toHourMinute {
|
||||||
return DateFormat('HH:mm', 'id_ID').format(this);
|
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