edtf 1.0.0

edtf #

A library for parsing dates using the EDTF standard.

Usage #

A simple usage example:

import 'package:edtf/edtf.dart';

main() {
  /// Parse a date in the EDTF format
  final date = EdtfDate.parse('1985-05%-13?');

  /// Check that the year is an approximation.
  if (date.year.approx) {
    /// If it is an approximation, then print it
    print(date.toString());
  }

  /// Parse an EDTF formatted interval
  final interval = EdtfInterval.parse('../2012');

  /// If the interval is open started and the end is a known date...
  if (interval.openStart || interval.end != null) {
    /// ... print the end date.
    print(interval.end.toString());
  }

  /// Parse a set of EDTF dates/intervals, where the real date is one of them.
  final oneOf = EdtfOneOf.parse('[1981, 1982-~04, 1983-1987]');

  /// Iterate through the dates/intervals
  for (final elem in oneOf.values) {
    /// If the elem is a date print it in this format
    if (elem is EdtfDate) {
      print('Date: ' + elem.toString());
    }

    /// If the elem is an interval just print the start date
    if (elem is EdtfInterval) {
      print('Interval start date: ' +
          (elem.openStart ? 'open' : elem.start.toString()));
      // An interval either has an known start date or open started
    }
  }
}

1.0.0 #

  • EDTF parsing and toString working

example/edtf_example.dart

import 'package:edtf/edtf.dart';

main() {
  /// Parse a date in the EDTF format
  final date = EdtfDate.parse('1985-05%-13?');

  /// Check that the year is an approximation.
  if (date.year.approx) {
    /// If it is an approximation, then print it
    print(date.toString());
  }

  /// Parse an EDTF formatted interval
  final interval = EdtfInterval.parse('../2012');

  /// If the interval is open started and the end is a known date...
  if (interval.openStart || interval.end != null) {
    /// ... print the end date.
    print(interval.end.toString());
  }

  /// Parse a set of EDTF dates/intervals, where the real date is one of them.
  final oneOf = EdtfOneOf.parse('[1981, 1982-~04, 1983-1987]');

  /// Iterate through the dates/intervals
  for (final elem in oneOf.values) {
    /// If the elem is a date print it in this format
    if (elem is EdtfDate) {
      print('Date: ' + elem.toString());
    }

    /// If the elem is an interval just print the start date
    if (elem is EdtfInterval) {
      print('Interval start date: ' +
          (elem.openStart ? 'open' : elem.start.toString()));
      // An interval either has an known start date or open started
    }
  }
}

Use this package as a library

1. Depend on it

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


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

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

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Maintenance suggestions

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
meta ^1.0.0 1.1.7
Dev dependencies
pedantic ^1.0.0
test ^1.0.0