tempus 1.1.1

tempus Pub Build Status

An implementation of some Moment.js features for parsing, manipulates and displaying dates in Dart.

Usage #

A simple usage example:

import 'package:tempus/tempus.dart';

main() {
    Duration secondsToAdd = new Duration(seconds: 10);
    DateTime dateForComparison = new DateTime.now().add(secondsToAdd);
    Tempus tempus = new Tempus();

    // Will print "in a few seconds"
    print(tempus.from(Tempus.fromDate(dateForComparison)));

    // Will generate a list with 35 DateTimes, perfect for creating
    // calendar grids. By default starts on Sunday, can be Monday.
    DateTime randomDate = new DateTime(2018, 10);
    List<DateTime> dateGrid = Tempus.daysInMonth(randomDate, startOnMonday: true);
}

Locales #

Set the locale for all usages of Tempus:

Tempus.globalLocale(new LocaleDE());

Set the locale only for the current instance of Tempus:

Tempus tempus = new Tempus.now().locale(new LocaleDE());

Adding your own locale: #

Just create a class that implements ILocale and assign that to your Tempus instance or set it globally.

Overwriting existing locales: #

class ShortLocaleEn extends LocaleEN {
  String get seconds => '%is';

  String get aMinute => '%im';
  String get minutes => '%im';

  String get anHour => '%ih';
  String get hours => '%ih';

  String get aDay => '%id';
  String get days => '%id';
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Credits #

This package draws inspiration and code from rinukkusu/simple_moment and apptreesoftware/date_utils.

[1.1.1] | 2019-12-30

Fixes #

  • Add missing formatHour function

[1.1.0] | 2019-12-30

  • Added example package!

🎉 [1.0.0] | 2019-12-30

Tempus now uses the library tempus; package format!

Features #

  • Add daysInWeek
  • Rename datesInMonthGrid to daysInMonth
  • Normalize most returned dates

Docs #

  • Fix several typos
  • Add missing public API DartDocs

[0.5.0] | 2019-12-30

Features #

  • Add 24h format
  • Add UTC date normalizer
  • Tempus().date is now a getter

Fixes #

  • Improved month grid generation
  • Improved days in rage generation

Docs #

  • Updated docs

Tests #

  • Added normalize and normalizeDate tests
  • Added daysInRange tests
  • Fixed datesInMonthGrid tests

[0.4.2] | 2019-12-29

Fixes #

  • Add missing getter/setter

Docs #

  • Update docs

[0.4.1] | 2019-12-29

Features #

  • Add function to format as day of week

[0.4.0] | 2019-12-29

Deps #

  • Bump test to ^1.9.4
  • Add pedantic

Style #

  • Fix all analyzer warnings

Docs #

  • Update docs

[0.3.2] | 2019-12-13

  • Bump intl to ^0.16.0
  • Bump test to ^1.9.0

[0.3.1] | 2019-08-11

  • Update docs
  • Update author information

[0.3.0] | 2019-08-11

  • Fix fromNow() calculating the difference in reverse
  • Improved some comments

[0.2.0] - 2018-11-17

  • Added weekday lists to all locales

[0.1.0] - 2018-11-12

Initial release. #

  • Added docs

example/README.md

tempus Pub Build Status

An implementation of some Moment.js features for parsing, manipulates and displaying dates in Dart.

Usage #

A simple usage example:

import 'package:tempus/tempus.dart';

main() {
    Duration secondsToAdd = new Duration(seconds: 10);
    DateTime dateForComparison = new DateTime.now().add(secondsToAdd);
    Tempus tempus = new Tempus();

    // Will print "in a few seconds"
    print(tempus.from(dateForComparison));

    // Will generate a list with 42 DateTimes, perfect for creating
    // calendar grids. By default starts on Sunday, can be Monday.
    DateTime randomDate = new DateTime(2018, 10);
    List<DateTime> dateGrid = Tempus.datesInMonthGrid(randomDate, true);
}

Locales #

Set the locale for all usages of Tempus:

Tempus.globalLocale(new LocaleDE());

Set the locale only for the current instance of Tempus:

Tempus tempus = new Tempus.now().locale(new LocaleDE());

Adding your own locale: #

Just create a class that implements ILocale and assign that to your Tempus instance or set it globally.

Overwriting existing locales: #

class ShortLocaleEn extends LocaleEN {
  String get seconds => '%is';

  String get aMinute => '%im';
  String get minutes => '%im';

  String get anHour => '%ih';
  String get hours => '%ih';

  String get aDay => '%id';
  String get days => '%id';
}

Use this package as a library

1. Depend on it

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


dependencies:
  tempus: ^1.1.1

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

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

  • Dart: 2.7.1
  • pana: 0.13.5

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
intl ^0.16.0 0.16.1
Transitive dependencies
path 1.6.4
Dev dependencies
pedantic ^1.9.0
test ^1.9.4