From 8e649656a4c4907dc561598298c680d8edc3f3d8 Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 12:26:13 +0300 Subject: [PATCH 1/8] [Started] Added the into doc --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++--------- pubspec.yaml | 2 +- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 87fd849..34793d7 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,81 @@ -A library for Dart developers. +# Jiffy [![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) -[![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=master)](https://coveralls.io/github/jama5262/jiffy?branch=master) +[![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) -Created from templates made available by Stagehand under a BSD-style -[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE). +Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating and formatting dates -## Usage +Full [documentation]() -A simple usage example: +[Installation]() +# Usage + +# Format Dates ```dart -import 'package:jiffy/jiffy.dart'; +Jiffy().format("MMMM dd yyyy, h:mm:ss a"); // October 19 2019, 7:00:53 PM +Jiffy().format("EEEE"); // Saturday +Jiffy().format("yyyy 'escaped' yyyy"); // 2019 escaped 2019 +Jiffy().format(); // 2019-10-19T19:00:53.090646 -main() { - var awesome = new Awesome(); -} +// 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 ``` -## Features and bugs +# Relative Time +```dart +Jiffy("2011-10-31", "yyyy-MM-dd").fromNow(); // 8 years ago +Jiffy("2012-06-20", "yyyy-MM-dd").fromNow(); // 7 years ago + +var jiffy1 = Jiffy() + ..startOf("day"); +jiffy1.fromNow(); // 19 hours ago -Please file feature requests and bugs at the [issue tracker][tracker]. +var jiffy2 = Jiffy() + ..endOf("day"); +jiffy2.fromNow(); // in 5 hours -[tracker]: http://example.com/issues/replaceme +var jiffy3 = Jiffy() + ..startOf("hour"); +jiffy3.fromNow(); // 9 minutes ago +``` + +# Manipulation + +```dart +var jiffy1 = Jiffy() + ..add(1, "day"); +jiffy1.yMMMMd; // October 20, 2019 + +var jiffy2 = Jiffy() + ..subtract(1, "day"); +jiffy2.yMMMMd; // October 18, 2019 + +// You can chain methods by using Dart method cascading +var jiffy3 = Jiffy() + ..add(1, "day") + ..add(3, "hours") + ..subtract(30, "minutes"); +jiffy3.yMMMMEEEEdjm; // Sunday, October 20, 2019 9:50 PM + +var jiffy4 = Jiffy() + ..add(1, "day") + ..add(3, "hours") + ..subtract(30, "minutes"); +jiffy4.format("dd/MM/yyy"); // 21/10/2019 +``` + +# Locale Support +```dart +// 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 +``` \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 424ea8b..f7f153f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: jiffy -description: A starting point for Dart libraries or applications. +description: Jiffy is a date dart package inspired by momentjs for parsing, manipulating and formatting dates version: 1.0.0 homepage: https://github.com/jama5262/jiffy author: Jama Mohamed From 11ce858cb273f9afeb2976402bcff8811f0f485e Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 14:24:08 +0300 Subject: [PATCH 2/8] Set up the parse docs --- README.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++---- docs/README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 docs/README.md diff --git a/README.md b/README.md index 34793d7..1b5e896 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,9 @@ [![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) [![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) -Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating and formatting dates +Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates -Full [documentation]() - -[Installation]() +#### [Full Documentation]() | [Installation]() # Usage @@ -71,11 +69,67 @@ jiffy4.format("dd/MM/yyy"); // 21/10/2019 // 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 -``` \ No newline at end of file +``` + +## Contributing + +To contribute, follow the following easy steps + +### Step 1 + +- **Option 1** + - Fork this repo! + +- **Option 2** + - 👯 Clone this repo to your local machine using `https://github.com/jama5262/jiffy.git` + +### Step 2 + +- **HACK AWAY!** 🔨🔨🔨 + +### Step 3 + +- 🔃 Create a new pull request + +### Support + +Reach out to me at one of the following places! + +- Email at jama3137@gmail.com +- Twitter [timedjama5262](https://twitter.com/timedjama5262) + +### 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. +``` diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..ee1b826 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,57 @@ +# Jiffy + +[![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) +[![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) + +Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates + +# Parsing +#### Now +To get the date now, just call `Jiffy()` without passing any parameters. This will return a Jiffy instance. See below +```dart +Jiff(); // Returns a Jiffy instance +Jiffy().dateTime; // Returns a dart DateTime.now() +Jiffy().format(); // Return a ISO 8601 date time format +``` + +#### String Formatting +To get a Jiffy date from a string, pass the string and its pattern to Jiffy as is parameters. See below +```dart +Jiffy("1995-12-25", "yyyy-MM-dd"); +``` +Jiffy run on top of the [Intl DateFormat](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) package, you can find all the date time patterns used by Jiffy [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) + +This is also same for Jiffy default formats. See below +```dart +Jiffy().yMMMMd; +Jiffy("1995-12-25", "yyyy-MM-dd").yMMMMd; +``` + +#### Unix Timestamp +Jiffy can also parse timestamp milliseconds and seconds. Just call `Jiffy.unix()` which return a dart Datetime. See below +```dart +// Parsing a milliseconds timestamp +Jiffy.unix(1318781876406); + +// Parsing a timestamp in seconds +Jiffy.unix(1318781876); +``` + +_**Note**: `Jiffy.unix()` returns a timestamp base on local time. You can also get it in UTC which return a UTC in dart Datetime. See below_ +```dart +Jiffy.unix(1318781876406).utc(); +``` + +#### UTC +Jiffy can also return date time in UTC. See below +```dart +// No UTC +Jiffy().format(); // 2019-10-20T14:18:45.069304 + +//Change to UTC +var jiffy = Jiffy() + ..utc(); +jiffy.format(); // 2019-10-20T11:18:45.069304Z +``` + +# Get \ No newline at end of file From 33c29124c752b6574f6c6a333fa7b2440d94e5a8 Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 14:34:28 +0300 Subject: [PATCH 3/8] Setup the get docs --- README.md | 2 +- docs/README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1b5e896..bad4752 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates -#### [Full Documentation]() | [Installation]() +#### [Full Documentation](https://github.com/jama5262/jiffy/tree/setup-readme/docs) | [Installation]() # Usage diff --git a/docs/README.md b/docs/README.md index ee1b826..c7800eb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -54,4 +54,60 @@ var jiffy = Jiffy() jiffy.format(); // 2019-10-20T11:18:45.069304Z ``` -# Get \ No newline at end of file +# Get +#### Milliseconds +Get milliseconds (Returns from 0 - 999) +```dart +Jiffy().milliseconds; +``` + +#### Seconds +Get seconds (Returns from 0 - 59) +```dart +Jiffy().seconds; +``` +#### Minute +Get minute (Returns from 0 - 59) +```dart +Jiffy().minute; +``` +#### Hour +Get hour (Returns from 0 - 23) +```dart +Jiffy().hour; +``` +#### Date of Month +Get date of month (Returns from 1 - 31) +```dart +Jiffy().date; +``` +#### Day of week +Get day of week (Returns from 0 - 6 [Sunday - Saturday]) +```dart +Jiffy().day; +``` +#### Day of year +Get day o year (Returns from 1 - 366) +```dart +Jiffy().dayOfYear; +``` +#### Week of year +Get week of year +```dart +Jiffy().week; +``` +#### Month +Get month (Returns from 1 - 12 [Jan - Dec]) +```dart +Jiffy().month; +``` +#### Quarter +Get quarter (Returns from 1 - 4) +```dart +Jiffy().quarter; +``` +#### Year +Get year +```dart +Jiffy().year; +``` From ac0814d55cb35ba272be86113f50a5904bcac73e Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 15:28:49 +0300 Subject: [PATCH 4/8] Setup the manipulation docs --- README.md | 5 +++ docs/README.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/README.md b/README.md index bad4752..b99ff57 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,11 @@ var jiffy4 = Jiffy() ..add(3, "hours") ..subtract(30, "minutes"); jiffy4.format("dd/MM/yyy"); // 21/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", "yyyy-MM-dd").add(1, "month"); // This is February 28 ``` # Locale Support diff --git a/docs/README.md b/docs/README.md index c7800eb..0638aff 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,6 +5,32 @@ Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates +# Table of content +- [Parsing](#parsing) + - [Now](#now) + - [String Formating](#string-formatting) + - [Unix Timestamp](#unix-timestamp) + - [UTC](#utc) +- [Get](#get) + - [Milliseconds](#milliseconds) + - [Seconds](#seconds) + - [Minute](#minute) + - [Hour](#hour) + - [Date of Month](#date-of-month) + - [Day of Week](#day-of-week) + - [Day of Year](#day-of-year) + - [Week of Year](#week-of-year) + - [Month](#month) + - [Quarter](#quarter) + - [Year](#year) +- [Manipulation](#manipulation) + - [Addition](#add) + - [Subtraction](#subtract) + - [Start of Time](#start-of-time) + - [End of Time](#end-of-time) + - [Local](#local) + - [UTC](#utc) + # Parsing #### Now To get the date now, just call `Jiffy()` without passing any parameters. This will return a Jiffy instance. See below @@ -111,3 +137,79 @@ Get year ```dart Jiffy().year; ``` + +# Manipulation + +#### Add +This adds time to Jiffy by the following units years, months, weeks, days, hours, minutes, seconds and milliseconds. See below +```dart +Jiffy().add(1, "year"); +Jiffy().add(3, "d"); +``` +Below are the units that can be used + +| Key | Units | +| ------------- | ------------- | +| years | y / year / years | +| months | M / month / months | +| weeks | w / week / weeks | +| days | d / day / days | +| hours | h / hour / hours | +| minutes | m / minute /minutes | +| seconds | s / second / seconds | +| milliseconds | ms / millisecond / milliseconds | + +You can also add date time with chaining + +```dart +var jiffy = Jiffy() + ..add(7, "days") + ..add(1, "month"); +jiffy.yMMMMd; // November 27, 2019 +``` + +**_Note: 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. See below_** + +```dart +Jiffy("2010-1-31", "yyyy-MM-dd"); // This is January 31 +Jiffy("2010-1-31", "yyyy-MM-dd").add(1, "month"); // This is February 28 +``` +#### Subtract +This subtracts time from Jiffy by the following units years, months, weeks, days, hours, minutes, seconds and milliseconds. See below +```dart +Jiffy().subtract(1, "year"); +Jiffy().subtract(3, "d"); +``` +#### Start of Time +This set the Jiffy date time to a specific unit in time in terms of years, months, weeks, days, hours, minutes, seconds and milliseconds. See below + +```dart +Jiffy().startOf('year'); // Set to January 1st, 12:00 am this year +Jiffy().startOf('month'); // Set to the first of this month, 12:00 am +Jiffy().startOf('week'); // Set to the first day of this week, 12:00 am +Jiffy().startOf('day'); // Set to 12:00 am today +Jiffy().startOf('hour'); // Set to now, but with 0 mins, 0 secs, and 0 ms +Jiffy().startOf('minute'); // Set to now, but with 0 seconds and 0 milliseconds +Jiffy().startOf('second'); // Set to now, but with 0 milliseconds; +``` +#### End of Time +This set the Jiffy date time to a specific unit in time in terms of years, months, weeks, days, hours, minutes, seconds and milliseconds. See below + +```dart +Jiffy().startOf('year'); // Set to December 31st, 23:59:59:999 this year +Jiffy().startOf('month'); // Set to the end of this month, 23:59:59:999 +Jiffy().startOf('week'); // Set to the end day of this week, 23:59:59:999 +Jiffy().startOf('day'); // Set to 23:59:59:999 today +``` +#### Local +Sets Jiffy to local time. See below +```dart +var jiffy = Jiffy()..utc(); // Time in utc +jiffy.local(); // Set to local +``` +#### UTC +Sets Jiffy to UTC time. See below +```dart +var jiffy = Jiffy(); // Time in local +jiffy.utc(); // Set to utc +``` \ No newline at end of file From 7d1e5aee83e72a4c80b12b5684b44d00267ef81d Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 16:40:54 +0300 Subject: [PATCH 5/8] Setup the display docs --- docs/README.md | 111 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 106 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 0638aff..f1e1eeb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,6 +6,7 @@ Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates # Table of content +- [Before Use](#before-use) - [Parsing](#parsing) - [Now](#now) - [String Formating](#string-formatting) @@ -24,12 +25,42 @@ Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for p - [Quarter](#quarter) - [Year](#year) - [Manipulation](#manipulation) - - [Addition](#add) - - [Subtraction](#subtract) + - [Add](#add) + - [Subtract](#subtract) - [Start of Time](#start-of-time) - [End of Time](#end-of-time) - [Local](#local) - [UTC](#utc) +- [Display](#manipulation) + - [Format](#format) + - [Time from Now](#time-from-now) + - [Time from X](#time-from-x) + - [Difference](#difference) + - [Unix Timestamp (Milliseconds)](#unix-timestamp-milliseconds) + - [Unix Timestamp (Seconds)](#unix-timestamp-seconds) + +# Before Use +Almost all of Jiffy methods return a dart DateTime instance, like the `add` and `subtract` methods. Example +```dart +Jiffy().add(1, "year"); // Returns a DateTime instance +Jiffy().utc(); // Returns a DateTime instance +``` +_**But when doing a method chaining, it is recommended to use a variable.**_ The variable will then hold a Jiffy instance. Example +```dart +var jiffy = Jiffy() + ..utc() + ..add(1, "day") + ..add(3, "hours") + ..subtract(30, "minutes"); // Returns a Jiffy instance +``` +`jiffy` variable returns a Jiffy instance. Now to get the date time, you can call it with the following methods +```dart +jiffy.format(); // 2019-10-20T19:00:53.090646 +// or +jiffy.yMMMMd; // October 20, 2019 +// or +jiffy.fromNow(); // in a day +``` # Parsing #### Now @@ -45,7 +76,7 @@ To get a Jiffy date from a string, pass the string and its pattern to Jiffy as i ```dart Jiffy("1995-12-25", "yyyy-MM-dd"); ``` -Jiffy run on top of the [Intl DateFormat](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) package, you can find all the date time patterns used by Jiffy [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) +Jiffy runs on top of the [Intl DateFormat](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) package, you can find all the date time patterns used by Jiffy [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html) This is also same for Jiffy default formats. See below ```dart @@ -71,10 +102,10 @@ Jiffy.unix(1318781876406).utc(); #### UTC Jiffy can also return date time in UTC. See below ```dart -// No UTC +// In local time Jiffy().format(); // 2019-10-20T14:18:45.069304 -//Change to UTC +// Change to UTC var jiffy = Jiffy() ..utc(); jiffy.format(); // 2019-10-20T11:18:45.069304Z @@ -212,4 +243,74 @@ Sets Jiffy to UTC time. See below ```dart var jiffy = Jiffy(); // Time in local jiffy.utc(); // Set to utc +``` +# Display +#### Format +The format function takes in a string pattern, which can be found [here](https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html), and format them. See below +```dart +Jiffy().format("MMMM dd yyyy, h:mm:ss a"); // October 19 2019, 7:00:53 PM +Jiffy().format("EEEE"); // Saturday +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 Intl Dateformat default methods to format. See below +```dart +Jiffy().yMMMMd; // October 19, 2019 +Jiffy().yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM +``` +#### Time from Now +This method is used to get the relative time from now. See below +```dart +Jiffy("2007-1-29", "yyyy-MM-dd").fromNow(); // 13 years ago +Jiffy("2020-10-29", "yyyy-MM-dd").fromNow(); // in a year +Jiffy("2030-10-29", "yyyy-MM-dd").fromNow(); // in 11 years + +var jiffy = Jiffy() +..startOf("hour"); +jiffy.fromNow(); // 9 minutes ago +``` + +#### Time from X +This method is used to get the relative time from a specific date time. See below +```dart +var jiffy1 = Jiffy("2007-1-28", "yyyy-MM-dd"); +var jiffy2 = Jiffy("2017-1-29", "yyyy-MM-dd"); +jiffy1.from(jiffy2); // a day ago +``` +#### Difference +Used to get the difference between two Jiffy date times. See below +```dart +// By default, diff method, get the difference in milliseconds +var jiffy1 = Jiffy("2007-1-28", "yyyy-MM-dd"); +var jiffy2 = Jiffy("2017-1-29", "yyyy-MM-dd"); +jiff1.diff(jiffy2); // 86400000 + +// Getting difference in another unit of measurement +var jiffy1 = Jiffy("2007-1-28", "yyyy-MM-dd"); +var jiffy2 = Jiffy("2017-1-29", "yyyy-MM-dd"); +jiff1.diff(jiffy2, "day"); // 1 +``` + +Also by default `diff` with truncate the result to return a whole number. To get decimal numbers, just pass a third param as `true`. See below +```dart +var jiffy1 = Jiffy("2008-10", "yyyy-MM"); +var jiffy2 = Jiffy("2007-1", "yyyy-MM-dd"); + +jiff1.diff(jiffy2, "year"); // 1 +jiff1.diff(jiffy2, "year", true); // 1.75 +``` +**_Note: Months and years are added in respect to how many days there are in a months and if is a year is a leap year. See below**_ + +#### Unix Timestamp (Milliseconds) +To get timestamp in milliseconds see below +```dart +Jiffy().valueOf(); +``` + +#### Unix Timestamp (Seconds) +To get timestamp in seconds see below +```dart +Jiffy().unix(); ``` \ No newline at end of file From a487d812929c155b46f111becf8cf3a58b0fa7dd Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 17:12:51 +0300 Subject: [PATCH 6/8] Setup the query docs --- README.md | 13 ++--- docs/README.md | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 142 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b99ff57..ce3de22 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) [![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates @@ -9,7 +10,7 @@ Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for p # Usage -# Format Dates +## Format Dates ```dart Jiffy().format("MMMM dd yyyy, h:mm:ss a"); // October 19 2019, 7:00:53 PM Jiffy().format("EEEE"); // Saturday @@ -21,7 +22,7 @@ Jiffy("19, Oct 2019", "dd, MMM yyyy").yMMMMd; // October 19, 2019 Jiffy().yMMMMEEEEdjm; // Saturday, October 19, 2019 7:00 PM ``` -# Relative Time +## Relative Time ```dart Jiffy("2011-10-31", "yyyy-MM-dd").fromNow(); // 8 years ago Jiffy("2012-06-20", "yyyy-MM-dd").fromNow(); // 7 years ago @@ -39,7 +40,7 @@ var jiffy3 = Jiffy() jiffy3.fromNow(); // 9 minutes ago ``` -# Manipulation +## Manipulation ```dart var jiffy1 = Jiffy() @@ -69,7 +70,7 @@ Jiffy("2010-1-31", "yyyy-MM-dd"); // This is January 31 Jiffy("2010-1-31", "yyyy-MM-dd").add(1, "month"); // This is February 28 ``` -# Locale Support +## Locale Support ```dart // The locale method always return a future // To get locale (The default locale is English) @@ -106,14 +107,14 @@ To contribute, follow the following easy steps - 🔃 Create a new pull request -### Support +## Support Reach out to me at one of the following places! - Email at jama3137@gmail.com - Twitter [timedjama5262](https://twitter.com/timedjama5262) -### License +## License ``` MIT License diff --git a/docs/README.md b/docs/README.md index f1e1eeb..6f5a4c7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,6 +2,7 @@ [![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) [![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates @@ -31,13 +32,23 @@ Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for p - [End of Time](#end-of-time) - [Local](#local) - [UTC](#utc) -- [Display](#manipulation) +- [Display](#display) - [Format](#format) - [Time from Now](#time-from-now) - [Time from X](#time-from-x) - [Difference](#difference) - [Unix Timestamp (Milliseconds)](#unix-timestamp-milliseconds) - [Unix Timestamp (Seconds)](#unix-timestamp-seconds) +- [Query](#query) + - [Is Before](#is-before) + - [Is Same](#is-same) + - [Is After](#is-after) + - [Is Same or Before](#is-same-or-before) + - [Is Same or After](#is-same-or-after) + - [Is Between](#is-between) + - [Is Leap Year](#is-leapyear) + - [Is Jiffy](#is-jiffy) + - [Is DateTime](#is-datetime) # Before Use Almost all of Jiffy methods return a dart DateTime instance, like the `add` and `subtract` methods. Example @@ -313,4 +324,127 @@ Jiffy().valueOf(); To get timestamp in seconds see below ```dart Jiffy().unix(); +``` + +# Query +#### Is Before +Check if date time is before another date time. See below +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); +var jiffy2 = Jiffy("2010-10-21", "yyyy-MM-dd"); +jiffy1.isBefore(jiffy2); // true +``` + +You can also check in terms of units of measurement. The below example checks if year is before. +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); + +var jiffy2 = Jiffy("2010-12-31", "yyyy-MM-dd"); +var jiffy3 = Jiffy("2011-01-01", "yyyy-MM-dd"); + +jiffy1.isBefore(jiffy2, "year"); // false +jiffy1.isBefore(jiffy3, "year"); // true +``` + +#### Is Same +Check if date time is same with another date time. See below +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); +var jiffy2 = Jiffy("2010-10-20", "yyyy-MM-dd"); +jiffy1.isSame(jiffy2); // true +``` + +You can also check in terms of units of measurement. The below example checks if years are the same. +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); + +var jiffy2 = Jiffy("2009-12-31", "yyyy-MM-dd"); +var jiffy3 = Jiffy("2010-01-01", "yyyy-MM-dd"); + +jiffy1.isSame(jiffy2, "year"); // false +jiffy1.isSame(jiffy3, "year"); // true +``` + +#### Is After +Check if date time is after another date time. See below +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); +var jiffy2 = Jiffy("2010-10-19", "yyyy-MM-dd"); +jiffy1.isAfter(jiffy2); // true +``` + +You can also check in terms of units of measurement. The below example checks if year is before. +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); + +var jiffy2 = Jiffy("2010-01-01", "yyyy-MM-dd"); +var jiffy3 = Jiffy("2009-12-31", "yyyy-MM-dd"); + +jiffy1.isAfter(jiffy2, "year"); // false +jiffy1.isAfter(jiffy3, "year"); // true +``` + +#### Is Same or Before +Check if date time is same or before with another date time. See below +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); + +var jiffy2 = Jiffy("2009-12-31", "yyyy-MM-dd"); +var jiffy3 = Jiffy("2010-12-31", "yyyy-MM-dd"); +var jiffy4 = Jiffy("2011-01-01", "yyyy-MM-dd"); + +jiffy1.isSameOrBefore(jiffy2, "year"); // false +jiffy1.isSameOrBefore(jiffy3, "year"); // true +jiffy1.isSameOrBefore(jiffy4, "year"); // true +``` +#### Is Same or After +Check if date time is same or after with another date time. See below +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); + +var jiffy2 = Jiffy("2011-12-31", "yyyy-MM-dd"); +var jiffy3 = Jiffy("2010-01-01", "yyyy-MM-dd"); +var jiffy4 = Jiffy("2009-12-31", "yyyy-MM-dd"); + +jiffy1.isSameOrAfter(jiffy2, "year"); // false +jiffy1.isSameOrAfter(jiffy3, "year"); // true +jiffy1.isSameOrAfter(jiffy4, "year"); // true +``` + +#### Is Between +Check if a date time is between two date times. See below +```dart +var jiffy1 = Jiffy("2010-10-20", "yyyy-MM-dd"); + +var jiffy2 = Jiffy("2010-01-01", "yyyy-MM-dd"); +var jiffy3 = Jiffy("2012-01-01", "yyyy-MM-dd"); + +var jiffy4 = Jiffy("2009-12-31", "yyyy-MM-dd"); +var jiffy5 = Jiffy("2012-01-01", "yyyy-MM-dd"); + +jiffy1.isBetween(jiffy2, jiffy3, "year"); // false +jiffy1.isBetween(jiffy4, jiffy5, "year"); // true +``` + +#### Is LeapYear +Check if date time is a leap year or not. See below +```dart +Jiffy("2019", "yyyy").isLeapYear; // false +Jiffy("2016", "yyyy").isLeapYear; // true +``` + +#### Is Jiffy +Check if it is a Jiffy instance. See below +```dart +Jiffy.isJiffy("string"); // false +Jiffy.isJiffy(Jiffy()); // true +Jiffy.isJiffy(DateTime.now()); // false +``` + +#### Is DateTime +Check if it is a dart DateTime instance. See below +```dart +Jiffy.isDateTime("string"); // false +Jiffy.isDateTime(DateTime.now()); // true +Jiffy.isDateTime(Jiffy()); // false ``` \ No newline at end of file From f9866fb6238e2a2d2963195294b0cab1debc6183 Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 17:14:18 +0300 Subject: [PATCH 7/8] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b39a99b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +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. From 5dd3ec480df1c109c9f1c6c18cf555f5433d23b2 Mon Sep 17 00:00:00 2001 From: Jama Mohamed Date: Sun, 20 Oct 2019 17:30:22 +0300 Subject: [PATCH 8/8] [Finished] Finished with docs --- README.md | 4 +++- docs/README.md | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce3de22..b385efc 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,10 @@ [![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) [![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Pub Version](https://img.shields.io/badge/pub-v1.0.0-blue)]() +[![Platform](https://img.shields.io/badge/platform-flutter%7Cweb%7Cdart%20vm-orange)](https://github.com/jama5262/jiffy) -Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates +Jiffy is a dart date package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates #### [Full Documentation](https://github.com/jama5262/jiffy/tree/setup-readme/docs) | [Installation]() diff --git a/docs/README.md b/docs/README.md index 6f5a4c7..d6fc68e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,8 +3,10 @@ [![Build Status](https://travis-ci.org/jama5262/jiffy.svg?branch=develop)](https://travis-ci.org/jama5262/jiffy) [![Coverage Status](https://coveralls.io/repos/github/jama5262/jiffy/badge.svg?branch=develop)](https://coveralls.io/github/jama5262/jiffy?branch=develop) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Pub Version](https://img.shields.io/badge/pub-v1.0.0-blue)]() +[![Platform](https://img.shields.io/badge/platform-flutter%7Cweb%7Cdart%20vm-orange)](https://github.com/jama5262/jiffy) -Jiffy is a date dart package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates +Jiffy is a dart date package inspired by [momentjs](https://momentjs.com/) for parsing, manipulating, querying and formatting dates # Table of content - [Before Use](#before-use) @@ -102,10 +104,10 @@ Jiffy can also parse timestamp milliseconds and seconds. Just call `Jiffy.unix() Jiffy.unix(1318781876406); // Parsing a timestamp in seconds -Jiffy.unix(1318781876); +Jiffy.unix(1318781876).format(); ``` -_**Note**: `Jiffy.unix()` returns a timestamp base on local time. You can also get it in UTC which return a UTC in dart Datetime. See below_ +**_Note: `Jiffy.unix()` returns a timestamp base on local time. You can also get it in UTC which return a UTC in dart Datetime. See below_** ```dart Jiffy.unix(1318781876406).utc(); ``` @@ -201,7 +203,7 @@ Below are the units that can be used | seconds | s / second / seconds | | milliseconds | ms / millisecond / milliseconds | -You can also add date time with chaining +You can also add date time with chaining using [dart method cascading](https://news.dartlang.org/2012/02/method-cascades-in-dart-posted-by-gilad.html) ```dart var jiffy = Jiffy()