DateTimeParser constructor

DateTimeParser(
  1. String stringValue
)

Implementation

DateTimeParser(String stringValue) {
  final removeAt = stringValue.replaceFirst('@', '');
  final split = removeAt.split('T');

  if (split.length == 2 && split.last != '') {
    final formattedDateTime = FhirDateTime(removeAt).value;
    if (formattedDateTime == null) {
      throw FormatException(
          'The DateTime provided was not properly formatted', stringValue);
    }
    String? timeString;
    final timeLength = removeAt.split('T').last.split(':').length;
    timeString = formattedDateTime
        .toIso8601String()
        .split('T')
        .last
        .replaceFirst('Z', '')
        .split(':')
        .sublist(0, timeLength <= 3 ? timeLength : 3)
        .join(':');

    value = [
      DateParser(formattedDateTime.toIso8601String().split('T').first),
      TimeParser(timeString),
    ];
  } else {
    final formattedDateTime = FhirDateTime(removeAt.split('T').first).value;
    if (formattedDateTime == null) {
      throw FormatException(
          'The DateTime provided was not properly formatted', stringValue);
    }
    value = [FhirDate(removeAt.split('T').first)];
  }
}