random_date 0.0.3
random_date: ^0.0.3 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.

A Random generator for Dates given range of years.

This package ability to take in startYear and optional endYear(exclusive) and Options to generate a valid date within the range. Uses Dart Math Random to generate random value.

Defaults #

Includes leap year Leap Years

EndYear when not provided, considers current year plus 5 years.

eg: 2025 ( for current year 2020)

Optional Arguments #

EndYear When not provided, we consider current year plus 5 years You can choose to skip leap years within the range.

  var options = RandonDateOptions();
    // years to add in case endYear is not provided
    options.addYearsToCurrent = 10;
    // in case of excluding leap years
    options.excludeLeapYear = true;

Usage #

 import 'package:random_date/random_date.dart'

The most common way of using this function is calling with a range.

 var randomDate = RandomDate();
// generates a random date within range of years 1980 and 2000
 var dateTime = randomDate.generateRandomDate(1980,2000);
 var randomDate = RandomDate();
// deduces endYear from current year plus 5 years
 var dateTime = randomDate.generateRandomDate(1980);
 var randomDate = RandomDate();
 var options = RandomDateOptions();
 // in case of endYear not provided, this option adds 10 years to the current year
 options.addYearsToCurrent = 10
// deduces endYear from current year plus 10 years
 var dateTime = randomDate.generateRandomDate(1980);
 var randomDate = RandomDate();
 var options = RandomDateOptions();
 // while generating dates, excludes leap year, until a non leap year is found, we keep generating
// dates.
 options.excludeLeapYear = true
 var dateTime = randomDate.generateRandomDate(1980);
2
likes
110
pub points
66%
popularity

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