You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2KB

  1. import 'dart:developer';
  2. import 'package:intl/intl.dart';
  3. extension HHmm on Duration {
  4. String formatHHmm() {
  5. //1:34:00.000000
  6. final str = this.toString();
  7. final texts = str.split(":");
  8. final textHour = texts[0].padLeft(2, '0');
  9. final textMinute = texts[1].padLeft(2, '0');
  10. return "${textHour}h ${textMinute}m";
  11. }
  12. }
  13. extension FormatNumber on int {
  14. String formatDecimalThousand() {
  15. //1403 -> 1,403
  16. var f = new NumberFormat.decimalPattern("en_US");
  17. return f.format(this);
  18. }
  19. }
  20. extension FormatDate on int {
  21. String MMM_dd_yyyy() {
  22. return DateFormat("MMM dd, yyyy")
  23. .format(DateTime.fromMillisecondsSinceEpoch(this * 1000));
  24. }
  25. }
  26. extension DoubleParsing on String {
  27. double parseDoubleThousand() {
  28. var newValue = this.replaceAll(",", "");
  29. //TODO: CHECK again
  30. if (newValue.endsWith(".0")) {
  31. newValue = newValue.substring(0, newValue.length - 2);
  32. }
  33. return double.tryParse(newValue);
  34. }
  35. }
  36. extension IntParsing on String {
  37. int parseIntThousand() {
  38. var newValue = this.replaceAll(",", "");
  39. if (newValue.endsWith(".0")) {
  40. newValue = newValue.substring(0, newValue.length - 2);
  41. }
  42. return int.tryParse(newValue);
  43. }
  44. }