jiffy 2.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 95

Jiffy #

Build Status Coverage Status License: MIT Pub Version Platform

Jiffy is a Flutter (Android, IOS and Web) date time package inspired by momentjs for parsing, manipulating, querying and formatting dates

Full Documentation | Installation | ChangeLog | Examples #

Usage #

Format Dates #

Jiffy([2019, 10, 19]).format("MMMM do yyyy, h:mm:ss a"); // October 19th 2019, 7:00:53 PM
Jiffy().format("EEEE"); // Saturday
Jiffy().format("MMM do yy"); // Oct 19th 19
Jiffy().format("yyyy 'escaped' yyyy"); // 2019 escaped 2019
Jiffy().format(); // 2019-10-19T19:00:53.090646

Jiffy([2019, 10, 19]).yMMMMd; // October 19, 2019
Jiffy({
  "year": 2019,
  "month": 10,
  "day": 19,
  "hour": 19
}).yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM

//  You can also use default formats
Jiffy("19, Oct 2019", "dd, MMM yyyy").yMMMMd; // October 19, 2019
Jiffy().yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM

Relative Time #

Jiffy("2011-10-31", "yyyy-MM-dd").fromNow(); // 8 years ago
Jiffy("2012-06-20").fromNow(); // 7 years ago

var jiffy1 = Jiffy()
    ..startOf("day");
jiffy1.fromNow(); // 19 hours ago

var jiffy2 = Jiffy()
    ..endOf("day");
jiffy2.fromNow(); // in 5 hours

var jiffy3 = Jiffy()
    ..startOf("hour");
jiffy3.fromNow(); // 9 minutes ago

Manipulation #

var jiffy1 = Jiffy()
    ..add(duration: Duration(days: 1));
jiffy1.yMMMMd; // October 20, 2019

var jiffy2 = Jiffy()
    ..subtract(days: 1);
jiffy2.yMMMMd; // October 18, 2019

//  You can chain methods by using Dart method cascading
var jiffy3 = Jiffy()
     ..add(hours: 3, days: 1)
     ..subtract(minutes: 30, months: 1);
jiffy3.yMMMMEEEEdjm; // Friday, September 20, 2019 9:50 PM

var jiffy4 = Jiffy()
    ..add(duration: Duration(days: 1, hours: 3))
    ..subtract(duration: Duration(minutes: 30));
jiffy4.format("dd/MM/yyy"); // 20/10/2019


// Months and year are added in respect to how many 
// days there are in a months and if is a year is a leap year
Jiffy("2010/1/31", "yyyy-MM-dd"); // This is January 31
Jiffy([2010, 1, 31]).add(months: 1); // This is February 28

Locale Support #

//  The locale method always return a future
//  To get locale (The default locale is English)
await Jiffy.locale(); // en

//  To set locale
await Jiffy.locale("fr");
Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25

await Jiffy.locale("ar");
Jiffy().yMMMMEEEEdjm; // السبت، ١٩ أكتوبر ٢٠١٩ ٧:٢٧ م

await Jiffy.locale("zh-cn");
Jiffy().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28

Contributing #

To contribute, follow the following easy steps

Step 1
  • Fork this repo!
Step 2
  • Make your own updates
Step 3
  • Create a new pull request

Support #

Reach out to me at one of the following places!

Buy Me A Coffee

License #

MIT License

Copyright (c) 2019 Jama Mohamed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2.2.0 #

  • Added more string parsing functionality. See below
Jiffy("1995/12/25"); // A calendar date part separated by slash "/"
Jiffy("19951225"); // Basic (short) full date
Jiffy("1995-12-25 12:00:00.000"); // An hour, minute, second, and millisecond time part
Jiffy("1995-12-25T12:00:00.000"); ISO dart format
Jiffy("1995-12-25T12:00:00.000Z"); ISO dart format (UTC)
  • Added support to Polish locale pl

2.1.2 #

  • Minor bug fixes on the following

Bug fix to support startOf and endOf for locales

Bug fix on week getter

2.1.1 #

  • Minor bug fixes on ordinal date formating

Previously

Jiffy([2014, 4, 23]).format("EEEE MMMM do, yyyy"); // Wednesday April 23o, 2014

Updated

Jiffy([2014, 4, 23]).format("EEEE MMMM do, yyyy"); // Wednesday April 23rd, 2014

2.1.0 #

  • Ordinal date parsing and formating In Jiffy you can now parse and format with ordinal date. e.g
Jiffy().format("MMM do yyyy"); // Oct 19th 2019
  • It also supports locales for the following

"en", "es", "fr", "frch", "frca", "it", "itch", "ja", "ko", "pt", "ptbr", "zh", "zhcn", "zhhk", "zhtw", "de", "deat", "dech"

  • Added daysInMonth method to get number of days for specific months .e.g
Jiffy([2016, 1]).daysInMonth; // 31
Jiffy([2016, 2]).daysInMonth; // 28
Jiffy([2017, 2]).daysInMonth; // 29

2.0.0 #

Added params to add and subtract methods Example

Jiffy().add(days: 1);
Jiffy().add(years: 2, months: 1, duration: Duration(days: 1, hours: 30));

1.1.0 #

Add more functionality to parsing. These are

  • Array parsing Jiffy([2019, 10, 21]);
  • Map parsing Jiffy({"year": 2019, "month": 10});
  • Dart DateTime parsing Jiffy(DateTime.now());
  • String parsing Jiffy("2019-10-21");

1.0.0 #

  • Initial version, created by Stagehand

example/jiffy_example.dart

import 'package:jiffy/jiffy.dart';

main() async {
//  FORMATTING DATES
  Jiffy([2019, 10, 19]).format("MMMM do yyyy, h:mm:ss a"); // October 19th 2019, 7:00:53 PM
  Jiffy().format("EEEE"); // Saturday
  Jiffy().format("MMM do yy"); // Oct 19th 19
  Jiffy().format("yyyy 'escaped' yyyy"); // 2019 escaped 2019

//  Not passing a string pattern for format method will return an ISO Date format
  Jiffy().format(); // 2019-10-19T19:00:53.090646

//  You can also use default formats
  Jiffy([2019, 10, 19]).yMMMMd; // October 19, 2019
  Jiffy({
    "year": 2019,
    "month": 10,
    "day": 19,
    "hour": 19
  }).yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM

//  RELATIVE TIME
  Jiffy("2011-10-31").fromNow(); // 8 years ago
  Jiffy(DateTime(2012, 6, 20)).fromNow(); // 7 years ago

  var jiffy1 = Jiffy()
    ..startOf("day");
  jiffy1.fromNow(); // 19 hours ago

  var jiffy2 = Jiffy()
    ..endOf("day");
  jiffy2.fromNow(); // in 5 hours

  var jiffy3 = Jiffy()
    ..startOf("hour");
  jiffy3.fromNow(); // 9 minutes ago

//  MANIPULATING DATES
  var jiffy4 = Jiffy()
    ..add(duration: Duration(days: 1));
  jiffy4.yMMMMd; // October 20, 2019

  var jiffy5 = Jiffy()
    ..subtract(days: 1);
  jiffy5.yMMMMd; // October 18, 2019

//  You can chain methods by using Dart method cascading
  var jiffy6 = Jiffy()
    ..add(hours: 3, days: 1)
    ..subtract(minutes: 30, months: 1);
  jiffy6.yMMMMEEEEdjm; // Friday, September 20, 2019 9:50 PM

//  LOCALES
//  The locale method always return a future
//  To get locale (The default locale is English)
  await Jiffy.locale(); // en
//  To set locale
  await Jiffy.locale("fr");
  Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25
  await Jiffy.locale("ar");
  Jiffy().yMMMMEEEEdjm; // السبت، ١٩ أكتوبر ٢٠١٩ ٧:٢٧ م
  await Jiffy.locale("zh-cn");
  Jiffy().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28
}

Use this package as a library

1. Depend on it

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


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

We analyzed this package on Feb 27, 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 issues and suggestions

Document public APIs. (-0.59 points)

71 out of 72 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/jiffy.dart. (-7.24 points)

Analysis of lib/src/jiffy.dart reported 15 hints, including:

line 370 col 14: Name non-constant identifiers using lowerCamelCase.

line 371 col 14: Name non-constant identifiers using lowerCamelCase.

line 372 col 14: Name non-constant identifiers using lowerCamelCase.

line 373 col 14: Name non-constant identifiers using lowerCamelCase.

line 374 col 14: Name non-constant identifiers using lowerCamelCase.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
intl ^0.16.0 0.16.1
Transitive dependencies
path 1.6.4
Dev dependencies
flutter_test
pedantic ^1.7.0
test ^1.6.0