parseDateTime static method

CalendarDateTime? parseDateTime(
  1. String dateTime
)

Implementation

static CalendarDateTime? parseDateTime(String dateTime) {
  final splitter = dateTime.split(" ");
  final datePart = splitter[0].split("-");
  final timePart = splitter[1].split(":");

  try {
    return CalendarDateTime(
      year: int.parse(datePart[0]),
      month: int.parse(datePart[1]),
      day: int.parse(datePart[2]),
      hour: int.parse(timePart[0]),
      minute: int.parse(timePart[1]),
      second: timePart.length == 3 ? double.parse(timePart[2]).toInt() : 0,
    );
  } on Exception catch (e) {
    print("${e.toString()}");
    return null;
  }
}