getAsDateTime method
Retrieves the element of key
of type Map from Map.
If it is an int type, convert it to a DateTime type with DateTime.fromMillisecondsSinceEpoch.
If there is no element of key
in Map, or if the type does not match int or DateTime, or if it is Null itself, orElse
is returned.
int型の場合はDateTime.fromMillisecondsSinceEpochでDateTime型に変換します。
Mapにkey
の要素がない場合やintもしくはDateTimeと型が合わない場合、自身がNullの場合はorElse
が返されます。
Implementation
DateTime getAsDateTime(K key, [DateTime? orElse]) {
if (this == null || !containsKey(key)) {
return orElse ?? DateTime.now();
}
if (this![key] is int?) {
final millisecondsSinceEpoch = this![key] as int?;
if (millisecondsSinceEpoch == null) {
return orElse ?? DateTime.now();
}
return DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch);
} else if (this![key] is DateTime?) {
return (this![key] as DateTime?) ?? orElse ?? DateTime.now();
} else {
return orElse ?? DateTime.now();
}
}