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.fromMicrosecondsSinceEpoch.

If there is no element of key in Map or the type does not match int or DateTime, orElse is returned.

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

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

Mapにkeyの要素がない場合やintもしくはDateTimeと型が合わない場合、orElseが返されます。

Implementation

DateTime getAsDateTime(K key, [DateTime? orElse]) {
  if (!containsKey(key)) {
    return orElse ?? Clock.now();
  }
  if (this[key] is int?) {
    final microsecondsSinceEpoch = this[key] as int?;
    if (microsecondsSinceEpoch == null) {
      return orElse ?? Clock.now();
    }
    return Clock.fromMicrosecondsSinceEpoch(microsecondsSinceEpoch);
  } else if (this[key] is DateTime?) {
    return (this[key] as DateTime?) ?? orElse ?? Clock.now();
  } else {
    return orElse ?? Clock.now();
  }
}