whenwas 1.1.0

Whenwas #

Library to calculate how many years, months, days, ... ago a given DateTime is.

Usage #

import 'package:whenwas/whenwas.dart';

main() {
  int year = 2000;
  var date = DateTime(year);
  
  // x years ago
  print(When(date));

  // in case you want a custom format:
  var time = When(date).toTime();
  if (time.unit == TimeUnit.YEAR) {
    // x years ago in Spanish
    print('Hace ${time.amount} aƱos')
  }
}

1.1.0 #

  • Support custom formats

1.0.0 #

  • Initial version

example/whenwas_example.dart

import 'package:whenwas/whenwas.dart';

main() {
  var dateInThePast = DateTime.now().subtract(
    Duration(
      milliseconds: 2,
      seconds: 15,
      minutes: 27,
      hours: 4,
      days: 29
    )
  );

  // 29 days ago
  print(When(dateInThePast));

  // custom format:
  dateInThePast = dateInThePast.subtract(Duration(days: 365 * 4));
  var time = When(dateInThePast).toTime();
  if (time.unit == TimeUnit.YEAR) {
    // 4 super long years ago
    print('${time.amount} super long ${time.unit}s ago');
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  whenwas: ^1.1.0

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:whenwas/whenwas.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
9
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Aug 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:whenwas/whenwas.dart.

Health suggestions

Format lib/src/time.dart.

Run dartfmt to format lib/src/time.dart.

Format lib/src/time_units.dart.

Run dartfmt to format lib/src/time_units.dart.

Format lib/src/when_base.dart.

Run dartfmt to format lib/src/when_base.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
Dev dependencies
pedantic ^1.7.0
test ^1.6.0