From 53760c1e26d9b26cbfc252071a3806cd8a9a1e5d Mon Sep 17 00:00:00 2001 From: Orlando Date: Sun, 15 Dec 2024 18:45:51 +0000 Subject: [PATCH] patch date series --- CHANGELOG.md | 6 +++ package.json | 2 +- src/dates/getDateSeries.test.ts | 68 ++++++++++++++++----------------- src/dates/getDateSeries.ts | 6 +-- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2658a18..965f7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # deverything +## 1.12.1 + +### Patch Changes + +- array + ## 1.12.0 ### Minor Changes diff --git a/package.json b/package.json index 7305dfd..68fdb11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deverything", - "version": "1.12.0", + "version": "1.12.1", "description": "Everything you need for Dev", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/dates/getDateSeries.test.ts b/src/dates/getDateSeries.test.ts index 8c57126..46f9c23 100644 --- a/src/dates/getDateSeries.test.ts +++ b/src/dates/getDateSeries.test.ts @@ -2,20 +2,20 @@ import { describe, it, expect } from "@jest/globals"; import { getDateSeries } from "./getDateSeries"; describe("getDateSeries", () => { - it("should return a series of dates as ISO strings mapped to indices for days", () => { + it("should return a series of dates as ISO strings for days", () => { const startDate = new Date("2024-01-01"); const endDate = new Date("2024-01-05"); const unit = "days"; const result = getDateSeries(startDate, endDate, unit); - expect(result).toEqual({ - "2024-01-01T00:00:00.000Z": 0, - "2024-01-02T00:00:00.000Z": 0, - "2024-01-03T00:00:00.000Z": 0, - "2024-01-04T00:00:00.000Z": 0, - "2024-01-05T00:00:00.000Z": 0, - }); + expect(result).toEqual([ + "2024-01-01T00:00:00.000Z", + "2024-01-02T00:00:00.000Z", + "2024-01-03T00:00:00.000Z", + "2024-01-04T00:00:00.000Z", + "2024-01-05T00:00:00.000Z", + ]); }); it("should handle a series for hours", () => { @@ -25,12 +25,12 @@ describe("getDateSeries", () => { const result = getDateSeries(startDate, endDate, unit); - expect(result).toEqual({ - "2024-01-01T00:00:00.000Z": 0, - "2024-01-01T01:00:00.000Z": 0, - "2024-01-01T02:00:00.000Z": 0, - "2024-01-01T03:00:00.000Z": 0, - }); + expect(result).toEqual([ + "2024-01-01T00:00:00.000Z", + "2024-01-01T01:00:00.000Z", + "2024-01-01T02:00:00.000Z", + "2024-01-01T03:00:00.000Z", + ]); }); it("should handle a series for minutes", () => { @@ -40,14 +40,14 @@ describe("getDateSeries", () => { const result = getDateSeries(startDate, endDate, unit); - expect(result).toEqual({ - "2024-01-01T00:00:00.000Z": 0, - "2024-01-01T00:01:00.000Z": 0, - "2024-01-01T00:02:00.000Z": 0, - "2024-01-01T00:03:00.000Z": 0, - "2024-01-01T00:04:00.000Z": 0, - "2024-01-01T00:05:00.000Z": 0, - }); + expect(result).toEqual([ + "2024-01-01T00:00:00.000Z", + "2024-01-01T00:01:00.000Z", + "2024-01-01T00:02:00.000Z", + "2024-01-01T00:03:00.000Z", + "2024-01-01T00:04:00.000Z", + "2024-01-01T00:05:00.000Z", + ]); }); it("should handle a series for seconds", () => { @@ -57,24 +57,24 @@ describe("getDateSeries", () => { const result = getDateSeries(startDate, endDate, unit); - expect(result).toEqual({ - "2024-01-01T00:00:00.000Z": 0, - "2024-01-01T00:00:01.000Z": 0, - "2024-01-01T00:00:02.000Z": 0, - "2024-01-01T00:00:03.000Z": 0, - "2024-01-01T00:00:04.000Z": 0, - "2024-01-01T00:00:05.000Z": 0, - }); + expect(result).toEqual([ + "2024-01-01T00:00:00.000Z", + "2024-01-01T00:00:01.000Z", + "2024-01-01T00:00:02.000Z", + "2024-01-01T00:00:03.000Z", + "2024-01-01T00:00:04.000Z", + "2024-01-01T00:00:05.000Z", + ]); }); - it("should return an empty object if startDate is after endDate", () => { + it("should return an empty array if startDate is after endDate", () => { const startDate = new Date("2024-01-05"); const endDate = new Date("2024-01-01"); const unit = "days"; const result = getDateSeries(startDate, endDate, unit); - expect(result).toEqual({}); + expect(result).toEqual([]); }); it("should handle a single date range", () => { @@ -84,8 +84,6 @@ describe("getDateSeries", () => { const result = getDateSeries(startDate, endDate, unit); - expect(result).toEqual({ - "2024-01-01T00:00:00.000Z": 0, - }); + expect(result).toEqual(["2024-01-01T00:00:00.000Z"]); }); }); diff --git a/src/dates/getDateSeries.ts b/src/dates/getDateSeries.ts index 7c21ae6..96ae5ac 100644 --- a/src/dates/getDateSeries.ts +++ b/src/dates/getDateSeries.ts @@ -4,8 +4,8 @@ export const getDateSeries = ( startDate: Date, endDate: Date, unit: "days" | "hours" | "minutes" | "seconds" -): Record => { - const series: Record = {}; +): ISODate[] => { + const series: ISODate[] = []; const unitMap: Record = { days: 24 * 60 * 60 * 1000, // milliseconds in a day hours: 60 * 60 * 1000, // milliseconds in an hour @@ -20,7 +20,7 @@ export const getDateSeries = ( const end = endDate.getTime(); while (current <= end) { - series[new Date(current).toISOString()] = 0; + series.push(new Date(current).toISOString()); current += increment; // Move forward by the specified unit }