getAsDateTime method

DateTime getAsDateTime(
  1. K key, [
  2. DateTime? orElse
])

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.

MapからDateTimekeyの要素を取得します。

int型の場合はDateTime.fromMillisecondsSinceEpochDateTime型に変換します。

Mapkeyの要素がない場合や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();
  }
}