dateTimeFromJson function

DateTime? dateTimeFromJson(
  1. String? json
)

Implementation

DateTime? dateTimeFromJson(String? json) {
  try {
    final parts = (json ?? '').split('.');

    if (parts.length != 6) {
      return null;
    }

    final years = int.parse(parts[0]);
    final months = int.parse(parts[1]);
    final days = int.parse(parts[2]);
    final hours = int.parse(parts[3]);
    final minutes = int.parse(parts[4]);
    final seconds = int.parse(parts[5]);

    return DateTime(
      years,
      months,
      days,
      hours,
      minutes,
      seconds,
    );
  } catch (e) {
    print(e);

    return null;
  }
}