abstarct_date 0.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 62

abstract_date #

// registering the date systems that we want to use.
// if you don't register any adapters then 
// the default adapters are going to get registered automatically.
    Date.addType<ShamsiDate>(ShamsiDate());
    Date.addType<GregorianDate>(GregorianDate());

// Creating a new date
    var date = Date<ShamsiDate>(1379,6,26);

// Converting dates
    var converted = date.to<GregorianDate>();
    date = converted.to<Shamsi>();

// Type checking
    if(date.isTypeOf<ShamsiDate>()){
      print('its shamsi!');
    }
    
// Other utility methods
    var tomorrow = date.add(Duration(days: 1));
    
    Duration d = date.difference(tomorrow);
  
    var realTomorrow = date.copy(
      day: date.day + 1,
    );

Date adapters #

###Adding Adapters: Before using Date you should register the types you want to use.

    Date.addType<ShamsiDate>(ShamsiDate());
    Date.addType<GregorianDate>(GregorianDate());

Setting a default adapter #

For setting an adapter as default, just register it with no generic type.

    Date.addType(ShamsiDate());
    ...
    // no generic type is used
    var defaultDate = Date.now(); 

Implementing a new Date adapter #

class NewDateSystem extends DateAdapter with DateFormatter {
  ...
}

If you don't add the DateFormatter mixin, some methods on date will throw an exception:

  1. formatter
  2. monthName
  3. weekDayName
  4. formatted*
  5. formatBuilder*

*: these might not throw exception if you don't use named parts.

Renaming Adapters #

If you don't like the name of a certain adapter, just extend it and register with the new class:

class Hijri extends IslamicDate {}
...
Date.addType<Hijri>(Hijri());

DateAdapter provided implementations #

  1. GregorianDate
  2. HijriDate
  3. ShamsiDate

To use them, import abstract_date and then register them using Date.addType<T extends DateAdapter>() before using them.

[0.0.6] #

  • added Year class
  • added EfficientLeapYear mixin for DateAdapters

[0.0.5] #

  • default adapters will be registered automatically if their is no registered adapters
  • added Week class
  • added Month class

[0.0.4] #

  • added FormattedDate
  • added DateFormatter mixin on DateAdapter
  • added formatBuilder for Date

[0.0.3] #

  • added default adapters HijriDate, GregorianDate or MiladiDate , ShamsiDate or JalaliDate or PersianDate

[0.0.2] #

  • added isTypeOf<T>() to Date

[0.0.1] #

  • added Date
  • added DateAdapter

example/example.dart

import 'package:abstarct_date/abstarct_date.dart';

void main() {
  ///
  ///default adapters are added automatically if you don't use [Date.addType]
  ///
  // Date.addType<ShamsiDate>(ShamsiDate());
  // Date.addType<GregorianDate>(GregorianDate());

  var date = Date<ShamsiDate>(1379, 6, 26);
  print(date.toString());

  var miladi = date.to<GregorianDate>();
  print(miladi);

  var hijri = date.to<HijriDate>();
  print(hijri);

  date = miladi.to<ShamsiDate>();
  print(date);

  var nth = Week.normalizeWeekDay(
      Date.getAdapterOfType<ShamsiDate>().firstDayOfTheWeek, DateTime.monday);

  print('Monday is the ${nth}rd day in shamsi calednar');

  if (date.isTypeOf<ShamsiDate>()) {
    print('its shamsi!');
  }

  var formatted = date.formatBuilder((f) {
    return '${f.yyyy} ${f.MMMM} ${f.dd}, ${f.DDDD}';
  });

  print(formatted);
}

Use this package as a library

1. Depend on it

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


dependencies:
  abstarct_date: ^0.0.6

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:abstarct_date/abstarct_date.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
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]
62
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/src/week.dart. (-0.50 points)

Analysis of lib/src/week.dart reported 1 hint:

line 9 col 14: This function has a return type of 'int', but doesn't end with a return statement.

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.2.0 <3.0.0
hijri ^0.2.5 0.2.5
libcalendar ^0.2.0 0.2.0
Transitive dependencies
logging 0.11.4
meta 1.1.8
Dev dependencies
test ^1.6.0