random_date 0.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • new55

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
var randomDate = RandomDate.withStartYear(2000);
//with range
var randomDate = RandomDate.withRange(2000,2005);
//with StartYear and Options
var randomDate = RandomDate.withStartYearAndOptions(2000,RandomDateOptions());
//with Range and Options
var randomDate = RandomDate.withRangeAndOptions(2000,2005,RandomDateOptions());

// Constructors for RandomDateOptions
  // modifying default value
var randomDateOptions = RandomDateOptions.withDefaultYearsToCurrent(10);
// setting exclude leap years
var randomDateOptions = RandomDateOptions.excludeLeapYears();
// modifying default values
var randomDateOptions = RandomDateOptions.withValues(true,10);

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();

0.0.5 - July 9, 2020

  • New constructors for RandomDateOptions class

0.0.4 - July 2, 2020

  • Added parameter constructor
  • added new method

0.0.3 - June 27, 2020

  • Fixed bug

0.0.2 - June 19, 2020

  • Updated documentation

0.0.1 - June 19, 2020

  • Initial Draft

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()}');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  random_date: ^0.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:random_date/random_date.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
14
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
55
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.1 <3.0.0
Dev dependencies
pedantic ^1.9.0
test ^1.14.4