Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-187] Update main readme and docs #200

Merged
merged 4 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 64 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,115 @@
# Jiffy

[![.github/workflows/release.yml](https://github.com/jama5262/jiffy/actions/workflows/release.yml/badge.svg)](https://github.com/jama5262/jiffy/actions/workflows/release.yml)
[![Release to pub.dev](https://github.com/jama5262/jiffy/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/jama5262/jiffy/actions/workflows/release.yml)
[![codecov](https://codecov.io/gh/jama5262/jiffy/branch/master/graph/badge.svg?token=Z2EGVUGWTE)](https://codecov.io/gh/jama5262/jiffy)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Pub Version](https://img.shields.io/badge/pub-v5.0.0-blue)](https://pub.dev/packages/jiffy)
[![Pub Version](https://img.shields.io/badge/pub.dev-v5.0.1-blue)](https://pub.dev/packages/jiffy/versions/5.0.1)
![Platform](https://img.shields.io/badge/platform-flutter%7Cweb%7Cdart%20vm-orange)

Jiffy is a Flutter (Android, IOS and Web) date time package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates

### [Full Documentation](doc) | [Installation](https://pub.dev/packages/jiffy#-installing-tab-) | [ChangeLog](https://pub.dev/packages/jiffy#-changelog-tab-) | [Examples](https://pub.dev/packages/jiffy#-example-tab-)

#### [Follow the project board](https://github.com/jama5262/jiffy/projects/1)
### [Full Documentation](./doc) | [API Reference](https://pub.dev/documentation/jiffy/latest/jiffy/Jiffy-class.html) | [Installation](https://pub.dev/packages/jiffy#-installing-tab-) | [ChangeLog](https://pub.dev/packages/jiffy#-changelog-tab-) | [Examples](https://pub.dev/packages/jiffy#-example-tab-)

# Usage

## Format Dates
```dart
Jiffy([2021, 1, 19]).format("MMMM do yyyy, h:mm:ss a"); // January 1st 2021, 12:00:00 AM
Jiffy().format("EEEE"); // Tuesday
Jiffy().format("MMM do yy"); // Mar 2nd 21
Jiffy().format("yyyy [escaped] yyyy"); // 2021 escaped 2021
Jiffy().format(); // 2021-03-02T15:18:29.922343

Jiffy([2020, 10, 19]).yMMMMd; // January 19, 2021

Jiffy({
"year": 2020,
"month": 10,
"day": 19,
"hour": 19
Jiffy.parse('2021/01/19').format('MMMM do yyyy, h:mm:ss a'); // January 1st 2021, 12:00:00 AM
Jiffy.now().format('EEEE'); // Tuesday
Jiffy.now().format('MMM do yy'); // Mar 2nd 21
Jiffy.now().format('yyyy [escaped] yyyy'); // 2021 escaped 2021
Jiffy.now().format(); // 2021-03-02T15:18:29.922343

Jiffy.parseFromList([2020, 10, 19]).yMMMMd; // January 19, 2021

Jiffy.parseFromMap({
Unit.year: 2020,
Unit.month: 10,
Unit.day: 19,
Unit.hour: 19
}).yMMMMEEEEdjm; // Monday, October 19, 2020 7:14 PM

// You can also use default formats
Jiffy("19, Jan 2021", "dd, MMM yyyy").yMMMMd; // January 19, 2021

Jiffy().yMMMMEEEEdjm; // Tuesday, March 2, 2021 3:20 PM
// You can also use pre-set formats
Jiffy.parse('19, Jan 2021', pattern: 'dd, MMM yyyy').yMMMMd; // January 19, 2021
Jiffy.now().yMMMMEEEEdjm; // Tuesday, March 2, 2021 3:20 PM
```

## Relative Time
```dart
Jiffy("2011-10-31", "yyyy-MM-dd").fromNow(); // 9 years ago

Jiffy("2020-01-01", "yyyy-MM-dd").from(Jiffy("2021-12-31", "yyyy-MM-dd"), maxRelativeTimeUnit: Units.MONTH); // 24 months ago

Jiffy().startOf(Units.DAY).fromNow(); // 19 hours ago

Jiffy().endOf(Units.DAY).fromNow(); // in 5 hours

Jiffy().startOf(Units.HOUR).add(hours: 2, minutes: 20).fromNow(); // in 2 hours
// From X
Jiffy.parse('1997/09/23').from(Jiffy.parse('2002/10/26')); // 5 years ago
// From Now
Jiffy.parse('1997/09/23').fromNow(); // 25 years ago

// To X
Jiffy.parse('1997/09/23').to(Jiffy.parse('2002/10/26')); // in 5 years
// To Now
Jiffy.parse('1997/09/23').toNow(); // in 25 years
```

## Manipulation

```dart
var jiffy1 = Jiffy().add(duration: Duration(days: 1));
jiffy1.yMMMMd; // March 3, 2021
var jiffy = Jiffy.now().add(duration: Duration(days: 1));
jiffy.yMMMMd; // March 3, 2021

Jiffy().subtract(days: 1).yMMMMd; // March 1, 2021
Jiffy.now().subtract(days: 1).yMMMMd; // March 1, 2021

Jiffy()
Jiffy.now()
.add(hours: 3, days: 1)
.subtract(minutes: 30, months: 1);
.yMMMMEEEEdjm; // Wednesday, February 3, 2021 6:07 PM

// 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
Jiffy.parse('1997/09/23')
.startOf(Unit.year)
.yMMMMEEEEd; // Wednesday, January 1, 1997

Jiffy.parse('1997/09/23')
.endOf(Unit.month)
.yMMMMEEEEd; // Tuesday, September 30, 1997
```

## Locale Support
## Querying

```dart
// The locale method always return a future
// To get locale (The default locale is English)
await (Jiffy.locale()).code; // en
Jiffy.parse('1997/9/23').isBefore(Jiffy.parse('1997/9/24')); // true

// To set locale
await Jiffy.locale("fr");
Jiffy().yMMMMEEEEdjm; // samedi 19 octobre 2019 19:25
Jiffy.parse('1997/9/23').isAfter(Jiffy.parse('1997/9/20')); // true

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

await Jiffy.locale("zh_cn");
Jiffy().yMMMMEEEEdjm; // 2019年10月19日星期六 下午7:28
Jiffy.parse('1997/9/23')
.isBetween(Jiffy.parse('1997/9/20'), Jiffy.parse('1997/9/24')); // true
```

## Contributing

To contribute, follow the following easy steps

##### Step 1
## Locale Support
```dart
// Get current locale code, by default it is en_us
Jiffy.now().localeCode; // en_us

- Fork this repo!
// Setting your preferred locale
await Jiffy.setLocale('fr_ca');
Jiffy.now().yMMMMEEEEdjm; // dimanche 26 février 2023 12 h 03

##### Step 2
await Jiffy.setLocale('ja');
Jiffy.now().yMMMMEEEEdjm; // 2023年2月26日日曜日 12:02

- Make your own updates
await Jiffy.setLocale('zh_cn');
Jiffy.now().yMMMMEEEEdjm; // 2023年2月26日星期日 下午12:03
```

##### Step 3
## Contributing

- Create a new pull request
To contribute, follow the following easy steps
1. Fork this repo!
2. Make your own updates
3. Create a new pull request to the `master` branch

## Support

Reach out to me at one of the following places!

- Email at [email protected]
- Email at [[email protected]](mailto:[email protected])
- Twitter [timedjama5262](https://twitter.com/timedjama5262)

## License
Expand Down
3 changes: 3 additions & 0 deletions bin/dart_analyze.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dart analyze lib test example
2 changes: 1 addition & 1 deletion bin/dart_format.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dart format --set-exit-if-changed lib test example
dart format lib test example
3 changes: 3 additions & 0 deletions bin/dart_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dart format lib test example
3 changes: 3 additions & 0 deletions bin/dart_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dart test
Loading