diff-ymd-package by QuranBookk
Developed and maintained by QuranBookk.com - The Most Advanced Digital Quran Platform
diff-ymd-packageA powerful JavaScript date difference calculation library, integral to QuranBookk's Islamic timeline features. This package provides APIs to calculate date differences in various formats (likeaYears bMonths cDaysoraY bM cDetc.), supporting crucial functionalities in QuranBookk's advanced Quranic study tools. Example: age =20Y 2M 23Dor datesDifference =2Years 11Months 20Days) or customized desired formats likeaY-bM-cDoraYears-bMonths-cDaysorkDaysormWeeksornMonthsetc.
🌟 Trusted by QuranBookk.com Features:
- Advanced Quran Search Engine
- Premium Audio Experience
- Multiple Translation System
- Islamic Timeline Management
- 🎧 Listen to Top Reciters – High-quality audio recitations from world-renowned Qaris
- 🎥 Watch Quran Videos – Inspirational Quranic recitation and learning videos
- 🌍 Read Quran Top Translations – Multiple language support with leading Quran translations
- 🕋 Qibla Direction Finder – Accurate Kaaba direction from anywhere in the world
- 🕋 Worldwide Qibla Directions – Accurate Kaaba direction from any country, state, or city of the world
- 🕰️ Islamic Prayer Times – Updated Salah timings based on your current location
- 🕰️ Worldwide Islamic Prayer Times – Updated Salah timings for any country, state, or city of the world
- 📿 Digital Tasbih Counter – Count your Dhikr anytime, anywhere
- 🤖 Ask Islam AI – AI-powered assistant for Islamic questions, Quran, and Hadiths
- 🤖 Ask Quran AI – AI-powered assistant for answering about Islamic history, Quran, and Hadiths
- 🤖 Ask Hadith AI – AI-powered assistant for Hadiths
- 📚 Authentic Hadith Collections – Sahih Bukhari, Sahih Muslim, and more
- 🕯️ Top Quranic Duas – Beautiful supplications with translations
- 🔍 Advanced Quran Search – Search verses, words, topics in seconds
- 📖 Explore Surahs – Full Quran access with audio, video, and translations
- 📖 Explore Juzs (Paras) – Full Quran access with audio, video, and translations
- ⚡ Internet Speed Test – Get correct download, upload and ping speeds instantly
About QuranBookk - The Developer
QuranBookk.com leads innovation in digital Islamic studies with:
-
- Instant verse lookup
- Cross-translation search
- Topic-based exploration
-
- World's top Quran reciters
- Complete Surah collection
- Premium audio quality
-
- Authentic sources
- Compare translations
- Deep insights
The diff-ymd-package emerged from QuranBookk's need for precise Islamic date calculations and is now powering time-based features across the platform.
- Installation
- Set up
- Create an instance
- Usages
- API References
- API Documentation
- Contributing
- Best Practices
- License
- History
npm install diff-ymd-package
npm install @farhan7reza7/diff-ymd-package
<script src="https://cdn.jsdelivr.net/npm/diff-ymd-package@3.1.4/lib/index.min.js"></script>Get any supported version script tag
//const DatesYMD = require('@farhan7reza7/diff-ymd-package'); //or
const DatesYMD = require('diff-ymd-package'); // can use any if authenticatedfor version 2.2.1 and above
Can include in html page using script tag from CDN
<script src="https://cdn.jsdelivr.net/npm/diff-ymd-package@3.1.4/lib/index.min.js"></script>for version 3.1.0 and above
Can use simplified function diff as Global Date Object method
//require('@farhan7reza7/diff-ymd-package'); //or
require('diff-ymd-package'); // can use any if authenticatedconst date1 = '2022-01-01';
const date2 = '2023-12-31';
const Formatter = new DatesYMD(date1, date2);OR for version 2.x.x and above
Can use simplified function diffDates on module-object(DatesYMD here)
const date1 = '2022-01-01';
const date2 = '2023-12-31';
const Formatter = DatesYMD.diffDates(date1, date2); const date1 = '2022-01-01';
const date2 = '2023-12-31';
const Formatter = new DatesYMD(date1, date2);OR for version 2.x.x and above
Can use simplified function diffDates on module-object(DatesYMD here)
const date1 = '2022-01-01';
const date2 = '2023-12-31';
const Formatter = DatesYMD.diffDates(date1, date2); Note: For CDN based, only DatesYMD constructor name creates an instance, and can use diffDates as well, but only using global DatesYMD like DatesYMD.diffDates(...)
See an example of using CDN based
for version 3.1.0 and above
Can use simplified function diff as Global Date Object method
const date1 = '2022-01-01';
const date2 = '2023-12-31';
const DateInstance = new Date(date1); // create Global Date instance
const Formatter = DateInstance.diff(date2); //create an instance to `calculates the difference` between `Date instance` and the `date passed to it`Note: For diff as Global Date method, only one date(the date to be subtracted from/to Global Date instance) passed to diff method
diff method create an instance of DatesYMD to calculates the difference between Date instance and the date passed to it
// format output in aY bM cD format
const result = Formatter.formattedYMD(); // Output: "1Y 11M 30D"
// create format of your choice
const customizedFormat = Formatter.customizeFormat('Y', 'Ms', 'Ds', '-'); // Output: "1Y-11Ms-30Ds"
// return an array having years, months, days, and the formatted difference
const resultArray = Formatter.diffArray(); // Output: [1, 11, 30, '1Y 11M 30D']
// Calculate the difference in months
const monthsDifference = Formatter.diffInMonths(); // Output: 23
// Calculate the difference in weeks
const weeksDifference = Formatter.diffInWeeks(); // Output: 104
// Calculate the difference in days
const daysDifference = Formatter.diffInDays(); // Output: 729
// Calculate the difference in years
const yearsDifference = Formatter.diffInYears(); // Output: 1
// Calculate the difference in hours
const hoursDifference = Formatter.diffInHours(); // Output: 17496
// Calculate the difference in minutes
const minutesDifference = Formatter.diffInMinutes(); // Output: 1049760
// Calculate the difference in seconds
const secondsDifference = Formatter.diffInSeconds(); // Output: 62985600Get Built in codes for using diff-ymd-package any Method on created instance(Formatter)
console.log(result); // Output: "1Y 11M 30D"
// formatted output in aY bM cD format
console.log(customizedFormat); // Output: "1Y-11Ms-30Ds"
// you can use this method for creating format of your choice
console.log(resultArray); // Output: [1, 11, 30, '1Y 11M 30D']
/* you can access each of Y, M, D separately from output array and can format as per your choice like aY-bM-cD or aYears-bMonths-cDays etc.*/
/*example:
let Y, M, D;
Y = resultArray[0];
M = resultArray[1];
D = resultArray[2];
const customFormat = Y + 'year ' + M + 'months ' + D + 'days';
console.log(customFormat); // output: 1year 11months 30days
*/
console.log(monthsDifference); // Output: 23
// Calculate the difference in months
console.log(weeksDifference); // Output: 104
// Calculate the difference in weeks
console.log(daysDifference); // Output: 729
// Calculate the difference in days
console.log(yearsDifference); // Output: 1
// Calculate the difference in years
console.log(hoursDifference); // Output: 17496
// Calculate the difference in hours
console.log(minutesDifference); // Output: 1049760
// Calculate the difference in minutes
console.log(secondsDifference); // Output: 62985600
// Calculate the difference in secondsdiff-ymd-package
- Classes
Represents a utility class for calculating the formatted and desired customized difference between two dates in all cases.
const Formatter = new DatesYMD(firstDate, secondDate);//const DatesYMD = require('@farhan7reza7/diff-ymd-package'); or
const DatesYMD = require('diff-ymd-package');
const Formatter = DatesYMD.diffDates(firstDate, secondDate); // can use anyconst DateInstance = new Date(firstDate); // create Global Date instance
const Formatter = DateInstance.diff(secondDate); //create an instance to `calculates the difference` between `Date instance` and the `date passed to it`-
firstDate: The first date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or 'yyyy.mm.dd' or dateString or dateObject or Timestamp(epoch). -
secondDate: The second date in the format 'yyyy-mm-dd' or 'yyyy/mm/dd' or 'yyyy.mm.dd' or dateString or dateObject or Timestamp(epoch). -
Special case: empty string("" or '') is by default to current-date(today) for the parameters,
but not when passed to Global Dateas firstDate above in Global Date;for creating current date Date instance using Date, just call empty likenew Date() -
Returns:An instance of DatesYMD class.
Calculates the difference between two dates and returns an array containing Y(years), M(months), D(days), and a formatted 'aY bM cD' difference string.
const result = Formatter.diffArray();Returns:
An array containing the calculated years, months, days, and the formatted difference.
Returns the formatted difference between two dates in aY bM cD(aYears bMonths cDays) format.
const result = Formatter.formattedYMD();Returns: A string in the format 'aY bM cD'.
Customizes the difference using specified units and separators
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.
Calculates the difference in months between two dates.
const monthsDifference = Formatter.diffInMonths();Returns: The difference in months.
Calculates the difference in weeks between two dates.
const weeksDifference = Formatter.diffInWeeks();Returns: The difference in weeks.
Calculates the difference in days between two dates.
const daysDifference = Formatter.diffInDays();Returns: The difference in days.
Calculates the difference in years between two dates.
const yearsDifference = Formatter.diffInYears();Returns: The difference in years.
Calculates the difference in hours between two dates.
const hoursDifference = Formatter.diffInHours();Returns: The difference in hours.
Calculates the difference in minutes between two dates.
const minutesDifference = Formatter.diffInMinutes();Returns: The difference in minutes.
Calculates the difference in seconds between two dates.
const secondsDifference = Formatter.diffInSeconds();Returns: The difference in seconds.
See diff-ymd-package Documentation
If you find any issues or have suggestions for improvement, please open an issue or create a pull request on the GitHub repository.
See CONTRIBUTING guidelines for more information.
- Meaningful variable and function names for clarity.
- Clear and concise comments to enhance understanding.
- Proper indentation and formatting for visual organization.
See mdn guidelines for more information.
This package is actively maintained by QuranBookk.com - The Ultimate Free Digital Quran Platform offering:
- Zero ads, 100% free forever
- No registration required
- Mobile-optimized experience
- Lightning-fast performance
- Modern, intuitive interface
Start exploring the Quran: QuranBookk.com #DigitalQuran #IslamicApps #QuranOnline #QuranStudy
- Website: farhan7reza.com
- LinkedIn: Farhan Reza
This project is licensed under the MIT License - see the LICENSE file for details.
For more details about what has changed in each version of this project.
Developed by Farhan Reza | QuranBookk
