'I want to process JIRA type work log string in flutter

I want to process the below-mentioned string and identify the number of hours and minutes in the string in flutter using RegEx.

6h 30m



Solution 1:[1]

You can process the string using the below-mentioned solution.

/// Modal Class
class TimeLog {
  int? days;
  int? hours;
  int? minutes;
  int? seconds;

  TimeLog({
    this.days,
    this.hours,
    this.minutes,
    this.seconds,
  });
}

// Processing the string.
final List<String> _timeLogStrings = str.split(" ");
TimeLog _timeLog = TimeLog();
for (var element in _timeLogStrings) {
    if (element.contains("h")) {
        _timeLog.hours = int.parse(element.replaceAll("h", ""));
    } else if (element.contains("m")) {
        _timeLog.minutes = int.parse(element.replaceAll("m", ""));
    } else if (element.contains("s")) {
        _timeLog.seconds = int.parse(element.replaceAll("s", ""));
    } else if (element.contains("d")) {
        _timeLog.days = int.parse(element.replaceAll("d", ""));
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sagar Ghag