nextDate static method
Generates a random Date in the range 'min', 'max'
.
This method generate dates without time (or time set to 00:00:00)
min
(optional) minimum range valuemax
max range value Returns a random Date value.
Implementation
/// - [min] (optional) minimum range value
/// - [max] max range value
/// Returns a random Date value.
static DateTime nextDate(DateTime min, [DateTime? max]) {
if (max == null) {
max = min;
min = DateTime(max.year - 10, 1, 1);
}
var diff = max.millisecondsSinceEpoch - min.millisecondsSinceEpoch;
if (diff <= 0) return min;
var time = min.millisecondsSinceEpoch + RandomInteger.nextInteger(0, diff);
var date = DateTime.fromMillisecondsSinceEpoch(time).toUtc();
return date;
}