Skip to content

Commit 3754af1

Browse files
committed
Update version to 4.4.0, enhance date range series with calendarYear option, and improve date helper functions with type annotations and new methods for yesterday in both local and UTC time.
1 parent 7c4be2c commit 3754af1

10 files changed

Lines changed: 51 additions & 9 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# deverything
22

3+
## 4.4.0
4+
5+
### Minor Changes
6+
7+
- Dates improvements
8+
39
## 4.3.2
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deverything",
3-
"version": "4.3.2",
3+
"version": "4.4.0",
44
"description": "Everything you need for Dev",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/dates/getDateRangeSeries.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import { DateRange, ISODate } from "../types";
88
*/
99
export const getDateRangeSeries = (
1010
dateRange: DateRange,
11-
unit: "day" | "week" | "hour" | "minute" | "second" | "calendarMonth",
11+
unit:
12+
| "second"
13+
| "minute"
14+
| "hour"
15+
| "day"
16+
| "week"
17+
| "calendarMonth"
18+
| "calendarYear",
1219
options: {
1320
step?: number;
1421
} = {}
@@ -32,6 +39,19 @@ export const getDateRangeSeries = (
3239
series.push(current.toISOString());
3340

3441
switch (unit) {
42+
case "calendarYear":
43+
if (start.getUTCMonth() === 1 && start.getUTCDate() === 29) {
44+
throw new Error(
45+
"Cannot add years when the start date is Feb 29, it may lead to unexpected results"
46+
);
47+
}
48+
{
49+
const currentYear = current.getUTCFullYear();
50+
current.setUTCFullYear(currentYear + step);
51+
}
52+
53+
break;
54+
3555
case "calendarMonth":
3656
if (start.getUTCDate() > 28) {
3757
throw new Error(

src/dates/startOfNextMonth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const startOfNextMonth = () => {
1+
export const startOfNextMonth = (): Date => {
22
const now = new Date();
33
return new Date(now.getFullYear(), now.getMonth() + 1, 1);
44
};

src/dates/startOfNextWeek.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const startOfNextWeek = () => {
1+
export const startOfNextWeek = (): Date => {
22
const now = new Date();
33
return new Date(
44
now.getFullYear(),

src/dates/startOfThisWeek.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const startOfThisWeek = () => {
1+
export const startOfThisWeek = (): Date => {
22
const now = new Date();
33
return new Date(
44
now.getFullYear(),

src/dates/startOfTomorrow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const startOfTomorrow = () => {
1+
export const startOfTomorrow = (): Date => {
22
const now = new Date();
33
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
44
};

src/dates/startOfUTCTomorrow.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
22
* Returns the start of tomorrow (00:00:00.000) in UTC time.
3-
*
4-
* @param date - The date to calculate tomorrow from. Defaults to current date if not provided.
5-
* @returns A new Date object set to the start of tomorrow in UTC time.
63
*/
74
export const startOfUTCTomorrow = (): Date => {
85
const tomorrow = new Date();

src/dates/startOfUTCYesterday.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Returns the start of yesterday (00:00:00.000) in UTC time.
3+
*/
4+
export const startOfUTCYesterday = (): Date => {
5+
const tomorrow = new Date();
6+
7+
tomorrow.setUTCDate(tomorrow.getUTCDate() - 1);
8+
return new Date(
9+
Date.UTC(
10+
tomorrow.getUTCFullYear(),
11+
tomorrow.getUTCMonth(),
12+
tomorrow.getUTCDate()
13+
)
14+
);
15+
};

src/dates/startOfYesterday.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const startOfYesterday = (): Date => {
2+
const now = new Date();
3+
return new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
4+
};

0 commit comments

Comments
 (0)