Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
@zero65tech/date-string-ist
Advanced tools
Readme
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.
npm i @zero65tech/date-string-ist
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()); // Returns a string representing today's date
tomorrow()
Returns the date string for the next day in the format "YYYY-MM-DD".
Example:
const nextDay = tomorrow(); // Returns a string representing tomorrow's date
today()
Returns the date string for the current day in the format "YYYY-MM-DD".
Example:
const currentDate = today(); // Returns a string representing today's date
yesterday()
Returns the date string for the previous day in the format "YYYY-MM-DD".
Example:
const previousDay = yesterday(); // Returns a string representing yesterday's date
lastWeek()
Returns the date string for seven days ago in the format "YYYY-MM-DD".
Example:
const lastWeekDate = lastWeek(); // Returns a string representing the date seven days ago
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); // Shifts the date two days ahead
// Output - '2024-02-01'
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'); // Returns the duration between the two dates
// Output - 2
getWeekStart(dateStr)
Returns the date string for the start of the week (Monday) for a given date.
Example:
const weekStartDate = getWeekStart('2023-01-06'); // Returns the date of the Monday of the week
// Output - '2024-01-01'
getWeekEnd(dateStr)
Returns the date string for the end of the week (Sunday) for a given date.
Example:
const weekEndDate = getWeekEnd('2023-01-06'); // Returns the date of the Sunday of the week
// Output - '2024-01-07'
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'); // Returns the start date of the fiscal year
// Output - '2023-04-01'
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'); // Returns the end date of the fiscal year
// Output - '2024-03-31'
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'); // Returns the fiscal quarter for the date
// Output - 'q1'
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'); // Returns the tax quarter for the date
// Output - 'q1'
getFy(dateStr)
Returns the fiscal year for a given date in the format "fyYYYY".
Example:
const fiscalYear = getFy('2023-06-01'); // Returns the fiscal year for the date
// Output - 'fy23'
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'); // Returns the duration of the fiscal year
// Output - 366
FAQs
Date String Manipulation (IST)
The npm package @zero65tech/date-string-ist receives a total of 16 weekly downloads. As such, @zero65tech/date-string-ist popularity was classified as not popular.
We found that @zero65tech/date-string-ist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.