From 7ae80ae0628739e988b466ed676fb4df9c65cad8 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Thu, 13 Apr 2023 17:20:49 +0200 Subject: [PATCH] date diff --- js/date-difference/index.js | 10 +++++++++ js/date-difference/package-lock.json | 31 ++++++++++++++++++++++++++++ js/date-difference/package.json | 5 +++++ 3 files changed, 46 insertions(+) create mode 100644 js/date-difference/index.js create mode 100644 js/date-difference/package-lock.json create mode 100644 js/date-difference/package.json diff --git a/js/date-difference/index.js b/js/date-difference/index.js new file mode 100644 index 0000000..d969507 --- /dev/null +++ b/js/date-difference/index.js @@ -0,0 +1,10 @@ +const differenceInCalendarDays = require('date-fns/differenceInCalendarDays'); + +const earlier = new Date(2023, 6, 31); +const later = new Date(2028, 6, 1); + +const dif = differenceInCalendarDays(later, earlier); + +console.log('from:', earlier.toLocaleDateString('en-GB', { dateStyle: 'full' })); +console.log('to:', later.toLocaleDateString('en-GB', { dateStyle: 'full' })); +console.log(dif); diff --git a/js/date-difference/package-lock.json b/js/date-difference/package-lock.json new file mode 100644 index 0000000..abba7c8 --- /dev/null +++ b/js/date-difference/package-lock.json @@ -0,0 +1,31 @@ +{ + "name": "date-difference", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "dependencies": { + "date-fns": "^2.29.3" + } + }, + "node_modules/date-fns": { + "version": "2.29.3", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.29.3.tgz", + "integrity": "sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==", + "engines": { + "node": ">=0.11" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/date-fns" + } + } + }, + "dependencies": { + "date-fns": { + "version": "2.29.3", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.29.3.tgz", + "integrity": "sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==" + } + } +} diff --git a/js/date-difference/package.json b/js/date-difference/package.json new file mode 100644 index 0000000..e297aa8 --- /dev/null +++ b/js/date-difference/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "date-fns": "^2.29.3" + } +}