fromTextToDurationDataScheme method

DurationDataScheme fromTextToDurationDataScheme(
  1. String text
)

text to duration example:

days - hours - minutes - seconds - milliseconds - microseconds

0 - 0 - 0 - 0 - 0 - 0

Implementation

DurationDataScheme fromTextToDurationDataScheme(String text) {
  DurationDataScheme durationData = DurationDataScheme({
    "@type": "durationDataScheme",
  });
  RegExpMatch? regExpMatch = RegExp(
          r"(([0-9]+)[ \-\~+]+([0-9]+)[ \-\~+]+([0-9]+)[ \-\~+]+([0-9]+)[ \-\~+]+([0-9]+)[ \-\~+]+([0-9]+))",
          caseSensitive: false)
      .firstMatch(text);
  if (regExpMatch != null) {
    List<String?> res = regExpMatch.groups([2, 3, 4, 5, 6, 7]);
    List<String> keys = [
      "days",
      "hours",
      "minutes",
      "seconds",
      "milliseconds",
      "microseconds",
    ];
    for (var i = 0; i < res.length; i++) {
      String? datas = res[i];
      if (datas == null) {
        continue;
      }
      try {
        durationData[keys[i]] = int.parse(datas);
      } catch (e) {}
    }
  }
  return durationData;
}