abstract_date

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

abstract date

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,
);
copied to clipboard
Date adapters #
###Adding Adapters:
Before using Date you should register the types you want to use.
Date.addType<ShamsiDate>(ShamsiDate());
Date.addType<GregorianDate>(GregorianDate());
copied to clipboard
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();
copied to clipboard
Implementing a new Date adapter #
class NewDateSystem extends DateAdapter with DateFormatter {
...
}
copied to clipboard
If you don't add the DateFormatter mixin, some methods on date will throw an exception:

formatter
monthName
weekDayName
formatted*
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());
copied to clipboard
DateAdapter provided implementations #

GregorianDate
HijriDate
ShamsiDate

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

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.