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

outdated

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 = RandomDateOptions();
  // 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';

Constructors #

//with just start year
Random.withStartYear(2000);
//with range
Random.withRange(2000,2005);
//with StartYear and Options
Random.withStartYearAndOptions(2000,RandomDateOptions());
//with Range and Options
Random.withRangeAndOptions(2000,2005,RandomDateOptions());

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

// generates a random date within range of years 1980 and 2000
var dateTime = RandomDate.withRange(2000, 2010).random();
// deduces endYear from current year plus 5 years when endDate is not provided
var dateTime = RandomDate.withStartYear(1980).random();
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.withRangeAndOptions(1980,2000,options).random();
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.withStartYear(1980).random();
5
likes
0
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

License

unknown (LICENSE)

More

Packages that depend on random_date