FhirDateTime constructor
FhirDateTime(
- dynamic inValue
Implementation
factory FhirDateTime(dynamic inValue) {
if (inValue is FhirDateTime) {
return inValue;
} else if (inValue is DateTime) {
return FhirDateTime.fromDateTime(inValue);
} else if (inValue is String) {
try {
final DateTime dateTimeValue = _parseDateTime(inValue);
return FhirDateTime._(
inValue, dateTimeValue, true, _getPrecision(inValue), null);
} on FormatException catch (e) {
return FhirDateTime._(
inValue, null, false, DateTimePrecision.INVALID, e);
}
}
if (inValue is FhirDate) {
switch (inValue.precision) {
case DatePrecision.YYYY:
return FhirDateTime.fromDateTime(
inValue.value!, DateTimePrecision.YYYY);
case DatePrecision.YYYYMM:
return FhirDateTime.fromDateTime(
inValue.value!, DateTimePrecision.YYYYMM);
case DatePrecision.YYYYMMDD:
return FhirDateTime.fromDateTime(
inValue.value!, DateTimePrecision.YYYYMMDD);
case DatePrecision.INVALID:
return FhirDateTime._(inValue.toString(), null, false,
DateTimePrecision.INVALID, inValue.parseError);
}
} else {
throw CannotBeConstructed<FhirDateTime>(
"FhirDateTime cannot be constructed from '$inValue' (unsupported type).");
}
}