Socket
Socket
Sign inDemoInstall

diff-ymd-package

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff-ymd-package - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

.github/workflows/npm-publish-npm-registry.yml

21

CHANGELOG.md

@@ -56,2 +56,19 @@ ## Changelog

### [v1.1.0]
#### Added
- Improved handling of customized formatting.
- Includes method for creating customized differrence formats.
- Included Unit test using Jest for customizing method.
- Included through comments in tests script
#### Changed
- Included through comments in tests script
#### Fixed
fixed some issues and configured files for publishing diff-ymd-package v1.1.0 on npm registry
### [Next Release] - Planning release time

@@ -61,4 +78,4 @@

- [Unreleased](https://github.com/farhan7reza7/diff-ymd-package/compare/v1.0.5...HEAD)
- [v1.0.5](https://github.com/farhan7reza7/diff-ymd-package/releases/tag/v1.0.5)
- [Unreleased](https://github.com/farhan7reza7/diff-ymd-package/compare/v1.1.0...HEAD)
- [v1.1.0](https://github.com/farhan7reza7/diff-ymd-package/releases/tag/v1.1.0)
- [Next Release](https://github.com/farhan7reza7/diff-ymd-package/milestone/2)

4

jsdoc.json

@@ -15,4 +15,4 @@ {

"templates": {
"cleverLinks": false,
"monospaceLinks": false
"cleverLinks": true,
"monospaceLinks": true
},

@@ -19,0 +19,0 @@ "plugins": [],

{
"name": "diff-ymd-package",
"version": "1.0.5",
"version": "1.1.0",
"description": "Utility class for calculating the difference between two dates in formatted ways like (aY bM cD)(aYears bMonths cDays) or customized formats like aY-bM-cD or aYears-bMonths-cDays etc.",

@@ -10,3 +10,2 @@ "main": "src/diff-ymd.js",

"keywords": [
"diff-ymd-package",

@@ -13,0 +12,0 @@ "ymd",

@@ -6,2 +6,4 @@ # diff-ymd-package

[![NPM Version][npm-image]][npm-url]
[![npm-build-published][npm-ci-image]][npm-ci-url]
[![github-build-published][github-image]][github-url]
[![CI][ci-image]][ci-url]

@@ -58,2 +60,6 @@ [![License][license-image]][licence-url]

// you can use this method for creating format of your choice
const customizedFormat = Formatter.customizeFormat('Ys', 'Ms', 'Ds', '-');
console.log(customizedFormat); // Output: "1Ys-2Ms-2Ds"
```

@@ -71,3 +77,2 @@

const Formatter = new DatesYMD(firstDate, secondDate);
```

@@ -85,3 +90,2 @@

const result = Formatter.diffArray();
```

@@ -97,3 +101,2 @@

const result = Formatter.formattedYMD();
```

@@ -103,2 +106,16 @@

**`customizeFormat(yearUnit, monthUnit, dayUnit, partSeparator)`**
Customizes the difference using specified units and separators
```javascript
const result = Formatter.customizeFormat(
yearUnit,
monthUnit,
dayUnit,
partSeparator,
);
```
- **`Returns:`** A customized formatted difference string of form (a + yearUnit + partSeparator + b + monthUnit + partSeparator + c + dayUnit), eg. aYs-bMs-cDs etc.
For more informations, [See `diff-ymd-package documentation`](https://farhan7reza7.github.io/diff-ymd-package/DatesYMD.html)

@@ -133,2 +150,6 @@

[npm-url]: https://www.npmjs.com/package/diff-ymd-package
[npm-ci-image]: https://github.com/farhan7reza7/diff-ymd-package/actions/workflows/npm-publish-npm-registry.yml/badge.svg
[npm-ci-url]: https://github.com/farhan7reza7/diff-ymd-package/actions/workflows/npm-publish-npm-registry.yml
[github-image]: https://github.com/farhan7reza7/diff-ymd-package/actions/workflows/npm-publish-github-packages.yml/badge.svg
[github-url]: https://github.com/farhan7reza7/diff-ymd-package/actions/workflows/npm-publish-github-packages.yml
[ci-image]: https://github.com/farhan7reza7/diff-ymd-package/actions/workflows/pages/pages-build-deployment/badge.svg

@@ -135,0 +156,0 @@ [ci-url]: https://github.com/farhan7reza7/diff-ymd-package/actions/workflows/pages/pages-build-deployment

@@ -147,2 +147,29 @@ /**

}
/**
* Customizes the difference using specified units and separators like (a + yearUnit + partSeparator + b + monthUnit + partSeparator + c + dayUnit), eg. aYs-bMs-cDs etc.
*
* @method
* @param {string} yearUnit - The unit for years.
* @param {string} monthUnit - The unit for months.
* @param {string} dayUnit - The unit for days.
* @param {string} partSeparator - The separator between year, month, and day parts.
* @returns {string} The customized formatted difference.
*/
customizeFormat(yearUnit, monthUnit, dayUnit, partSeparator) {
let Y, M, D;
Y = this.diffArray()[0];
M = this.diffArray()[1];
D = this.diffArray()[2];
const customized =
Y +
yearUnit +
partSeparator +
M +
monthUnit +
partSeparator +
D +
dayUnit;
return customized;
}
}

@@ -149,0 +176,0 @@

// dates-ymd.test.js
// Import the DatesYMD class from your source code
const DatesYMD = require('../src/diff-ymd');
// Describe block for the DatesYMD class
describe('DatesYMD', () => {
// Test case to check if the difference between two dates is calculated correctly
test('should calculate the difference between two dates', () => {
// Input dates for the test case
const date1 = '2022-01-01';
const date2 = '2023-02-15';
// Create an instance of the DatesYMD class with the input dates
const datesYMD = new DatesYMD(date1, date2);
// Calculate the difference and get the result array
const diffArray = datesYMD.diffArray();
// Assert that the calculated difference matches the expected result
expect(diffArray).toEqual([1, 1, 14, '1Y 1M 14D']);
});
// Test case to check if the class handles empty date inputs
test('should handle empty date inputs', () => {
// Create an instance of the DatesYMD class with empty date inputs
const datesYMD = new DatesYMD('', '');
// Calculate the difference and get the result array
const diffArray = datesYMD.diffArray();

@@ -26,14 +36,40 @@

// Assert that the calculated difference matches the expected result for empty inputs
expect(diffArray).toEqual([0, 0, 0, `0Y 0M 0D`]);
});
// Test case to check if the formatted difference is generated correctly
test('should format the difference between two dates like aY bM cD', () => {
// Input dates for the test case
const date1 = '2021-03-20';
const date2 = '2022-05-22';
// Create an instance of the DatesYMD class with the input dates
const datesYMD = new DatesYMD(date1, date2);
// Get the formatted difference
const formattedDifference = datesYMD.formattedYMD();
// Assert that the formatted difference matches the expected result
expect(formattedDifference).toBe('1Y 2M 2D');
});
// Test case to check if the customized difference is generated correctly
test('should customized the difference between two dates like (a + yearUnit + partSeparator + b + monthUnit + partSeparator + c + dayUnit), eg. aYs-bMs-cDs etc.', () => {
// Input dates for the test case
const date1 = '2021-03-20';
const date2 = '2022-05-22';
// Create an instance of the DatesYMD class with the input dates
const datesYMD = new DatesYMD(date1, date2);
// Get the customized difference
const customizedDifference = datesYMD.customizeFormat(
'Ys',
'Ms',
'Ds',
'-',
);
// Assert that the customized difference matches the expected result
expect(customizedDifference).toBe('1Ys-2Ms-2Ds');
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc