random_date 0.0.7 copy "random_date: ^0.0.7" to clipboard
random_date: ^0.0.7 copied to clipboard

Generate a random date given range. Options let you skip leap years and ignore endYear in that case end value is deduced based on current year plus 5 years.

example/random_date_example.dart

import 'package:random_date/random_date.dart';

void main() {
  var randomDateOptions = RandomDateOptions.withDefaultYearsToCurrent(10);
  // generates a random date for given range
  var randomDate = RandomDate.withStartYear(2000);
  print('randomDateWithStartYear[2000]: ${randomDate.random()}');
  randomDate = RandomDate.withRange(2000, 2010);
  print('randomDateWithRange[2000-2010]: ${randomDate.random()}');
  randomDateOptions.excludeLeapYear = true;
  randomDate = RandomDate.withRangeAndOptions(2000, 2010, randomDateOptions);
  print(
      'randomDateWithRangeAndSkipLeapYears[2000-2010]: ${randomDate.random()}');
  randomDate = RandomDate.withStartYearAndOptions(2000, randomDateOptions);
  print(
      'randomDateWithStartYearAndEndYearDefaultedTo[2000-2025]: ${randomDate.random()}');
}
5
likes
140
pub points
80%
popularity

Publisher

unverified uploader

Generate a random date given range. Options let you skip leap years and ignore endYear in that case end value is deduced based on current year plus 5 years.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on random_date