@danielgtmn/date-range-helper v0.0.3
@danielgtmn/date-range-helper
A lightweight, zero-dependency library for working with date ranges in JavaScript and TypeScript.
๐ฆ Installation
npm install @danielgtmn/date-range-helper
# or
pnpm install @danielgtmn/date-range-helper
# or
yarn add @danielgtmn/date-range-helper๐ง Funktionen
getCurrentMonthRange()
Returns the start and end time of the current month.
const { start, end } = getCurrentMonthRange();getPreviousMonthRange()
Returns the start and end time of the previous month.
const { start, end } = getPreviousMonthRange();getNextMonthRange()
Returns the start and end time of the next month.
const { start, end } = getNextMonthRange();getCurrentWeekRange()
Returns the start and end time of the current week (Monday to Sunday).
const { start, end } = getCurrentWeekRange();getPreviousWeekRange()
Returns the start and end time of the previous week (Monday to Sunday).
const { start, end } = getPreviousWeekRange();getNextWeekRange()
Returns the start and end time of the next week (Monday to Sunday).
const { start, end } = getNextWeekRange();Utility Functions
isInRange(date, { start, end })
Checks whether a date is within a range.
const isTodayInRange = isInRange(new Date(), { start, end });getDaysBetween(start, end)
Calculates the number of full days between two dates.
const days = getDaysBetween(new Date('2025-03-01'), new Date('2025-03-10'));getDateList(start, end)
Generates a list of all data between two points in time.
const dates = getDateList(new Date('2025-03-01'), new Date('2025-03-03'));
// [2025-03-01, 2025-03-02, 2025-03-03]normalizeDate(date)
Converts a date to a string in the format 'YYYY-MM-DD'.
const normalizedDate = normalizeDate(new Date('2025-03-01'));
// '2025-03-01'Timezone Support
This library is timezone-aware. All date operations are performed in the local timezone of the device.
toTimezone(date, timezone)
Converts a date to a specific timezone.
const dateInNewYork = toTimezone(new Date(), 'America/New_York');getCurrentMonthRangeInTimezone(timezone)
Returns the start and end time of the current month in a specific timezone.
const { start, end } = getCurrentMonthRangeInTimezone('America/New_York');getCurrentWeekRangeInTimezone(timezone)
Returns the start and end time of the current week in a specific timezone.
const { start, end } = getCurrentWeekRangeInTimezone('America/New_York');๐ค Contributing
Contributions are welcome! Please read the contributing guidelines first.
๐งช Beispiel
import {
getCurrentWeekRange,
isInRange,
getDateList
} from '@danielgtmn/date-range-helper';
const { start, end } = getCurrentWeekRange();
console.log(getDateList(start, end)); // Alle Tage dieser Woche๐ License
๐ค Contributing
- Fork it
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ซ Support
- Create a GitHub issue for bug reports and feature requests
- Follow @danielgtmn for announcements