0.0.3 โ€ข Published 7 months ago

@danielgtmn/date-range-helper v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@danielgtmn/date-range-helper

License: MIT TypeScript npm version

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

MIT

๐Ÿค Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ซ Support

0.0.3

7 months ago

0.0.2

7 months ago