isAtSameMomentAs method

bool isAtSameMomentAs(
  1. JDate other
)

Returns true if this occurs at the same moment as other.

The comparison is independent of whether the time is in UTC or in the local time zone.

var now = new JDate.now();
var later = now.add(const Duration(seconds: 5));
assert(!later.isAtSameMomentAs(now));
assert(now.isAtSameMomentAs(now));

// This relation stays the same, even when changing timezones.
assert(!later.isAtSameMomentAs(now.toUtc()));
assert(!later.toUtc().isAtSameMomentAs(now));

assert(now.toUtc().isAtSameMomentAs(now));
assert(now.isAtSameMomentAs(now.toUtc()));

Implementation

bool isAtSameMomentAs(JDate other) =>
    toDateTime().isAtSameMomentAs(other.toDateTime());