date-string-ist Utility
Introduction
This JavaScript library is designed to simplify date-related operations, specifically tailored for the Indian financial system. The library is crafted to assist in various date manipulations crucial for financial calculations, ensuring that all time values are in Indian Standard Time (IST) and date formats follow the "YYYY-MM-DD" pattern.
Installation
npm i @zero65tech/date-string-ist
Functions
1. from(date)
This function takes a Date
object or a timestamp and returns the date in the format "YYYY-MM-DD". It adjusts the input date by adding 5.5 hours to it.
Example:
const formattedDate = from(new Date());
2. tomorrow()
Returns the date string for the next day in the format "YYYY-MM-DD".
Example:
const nextDay = tomorrow();
3. today()
Returns the date string for the current day in the format "YYYY-MM-DD".
Example:
const currentDate = today();
4. yesterday()
Returns the date string for the previous day in the format "YYYY-MM-DD".
Example:
const previousDay = yesterday();
5. lastWeek()
Returns the date string for seven days ago in the format "YYYY-MM-DD".
Example:
const lastWeekDate = lastWeek();
6. shift(dateStr, days)
Shifts a given date string by a specified number of days. If no days are provided, the original date string is returned.
Example:
const shiftedDate = shift('2024-01-30', 2);
7. getDuration(startDate, endDate)
Calculates the duration in days between two dates. If no start date is provided, it defaults to the current date.
Example:
const duration = getDuration('2024-01-30', '2024-02-01');
8. getWeekStart(dateStr)
Returns the date string for the start of the week (Monday) for a given date.
Example:
const weekStartDate = getWeekStart('2023-01-06');
9. getWeekEnd(dateStr)
Returns the date string for the end of the week (Sunday) for a given date.
Example:
const weekEndDate = getWeekEnd('2023-01-06');
10. getFyStart(dateStr)
Returns the start date string of the fiscal year for a given date. If no date is provided, it defaults to the current date.
Example:
const fyStartDate = getFyStart('2023-06-01');
11. getFyEnd(dateStr)
Returns the end date string of the fiscal year for a given date. If no date is provided, it defaults to the current date.
Example:
const fyEndDate = getFyEnd('2023-06-01');
12. getQtr(dateStr)
Returns the fiscal quarter for a given date in the format "q1", "q2", "q3", or "q4".
Example:
const quarter = getQtr('2023-06-01');
13. getTaxQtr(dateStr)
Returns the tax quarter for a given date in the format "q1", "q2", "q3", "q4", or "q5".
Example:
const taxQuarter = getTaxQtr('2023-06-01');
14. getFy(dateStr)
Returns the fiscal year for a given date in the format "fyYYYY".
Example:
const fiscalYear = getFy('2023-06-01');
15. getFyDuration(dateStr)
Calculates the duration in days of the fiscal year for a given date. If no date is provided, it defaults to the current date.
Example:
const fyDuration = getFyDuration('2023-06-01');