scdate 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -78,6 +78,11 @@ const weekday = getWeekdayFromDate(date1) // Get weekday (0-6)
|
|
|
78
78
|
const nextTuesday = getNextDateByWeekday(date1, Weekday.Tue)
|
|
79
79
|
const prevFriday = getPreviousDateByWeekday(date1, Weekday.Fri)
|
|
80
80
|
|
|
81
|
+
// Date calculations
|
|
82
|
+
const daysBetween = getDaysBetweenDates(date1, date2) // Days between dates (positive if date2 is later)
|
|
83
|
+
const utcMs = getUTCMillisecondsFromDate(date1, 'America/Puerto_Rico') // Convert to UTC milliseconds
|
|
84
|
+
const zonedDate = getTimeZonedDateFromDate(date1, 'America/Puerto_Rico') // Get timezone-adjusted Date
|
|
85
|
+
|
|
81
86
|
// Date comparison
|
|
82
87
|
const isEqual = isSameDate(date1, date2)
|
|
83
88
|
const isBefore = isBeforeDate(date1, date2)
|
|
@@ -85,6 +90,10 @@ const isAfter = isAfterDate(date1, date2)
|
|
|
85
90
|
const isSameOrBefore = isSameDateOrBefore(date1, date2)
|
|
86
91
|
const isSameOrAfter = isSameDateOrAfter(date1, date2)
|
|
87
92
|
const isToday = isDateToday(date1, 'America/Puerto_Rico')
|
|
93
|
+
const isSameMonth = areDatesInSameMonth(date1, date2) // Check if dates are in same month & year
|
|
94
|
+
const isSameYear = areDatesInSameYear(date1, date2) // Check if dates are in same year
|
|
95
|
+
const isCurrentMonth = isDateInCurrentMonth(date1, 'America/Puerto_Rico') // Check if in current month
|
|
96
|
+
const isCurrentYear = isDateInCurrentYear(date1, 'America/Puerto_Rico') // Check if in current year
|
|
88
97
|
|
|
89
98
|
// Date formatting
|
|
90
99
|
const fullDateStr = getFullDateString(date1, 'en-US')
|
|
@@ -107,11 +116,20 @@ const shortDateStr = getShortDateString(date1, 'America/Puerto_Rico', 'en-US', {
|
|
|
107
116
|
- **`addMonthsToDate(date, months, options?)`**: Properly handles month boundaries by clamping to the last day of the target month. For example, adding one month to January 31 will result in February 28/29 (depending on leap year), adding 3 months will result in April 30, and adding 5 months will result in June 30. This ensures consistent and predictable date handling when crossing between months with different numbers of days.
|
|
108
117
|
|
|
109
118
|
Accepts an optional `options` object with:
|
|
110
|
-
|
|
111
119
|
- `capToCommonDate`: When set to `true`, dates greater than the 28th will always be capped to the 28th of the target month (the last date common to all months). For example, `addMonthsToDate('2023-01-31', 3, { capToCommonDate: true })` will result in `'2023-04-28'` rather than `'2023-04-30'`. This is useful for scheduling scenarios where you need consistent date behavior across all months.
|
|
112
120
|
|
|
113
121
|
- **`isDateToday(date, timeZone)`**: The comparison is time-zone aware, so a date that is "today" in one time zone might not be "today" in another time zone.
|
|
114
122
|
|
|
123
|
+
- **`getDaysBetweenDates(date1, date2)`**: Returns the number of calendar days between two dates. The result is positive if date2 is after date1, negative if before. This accounts for calendar days rather than full 24-hour periods.
|
|
124
|
+
|
|
125
|
+
- **`getUTCMillisecondsFromDate(date, timeZone)`**: Converts a date to UTC milliseconds since the Unix epoch, accounting for the specified time zone offset.
|
|
126
|
+
|
|
127
|
+
- **`getTimeZonedDateFromDate(date, timeZone)`**: Returns a native Date object adjusted so that its local time matches the local time at the specified time zone.
|
|
128
|
+
|
|
129
|
+
- **`areDatesInSameMonth(date1, date2)` / `areDatesInSameYear(date1, date2)`**: Check if two dates fall within the same month/year. For months, both the month and year must match.
|
|
130
|
+
|
|
131
|
+
- **`isDateInCurrentMonth(date, timeZone)` / `isDateInCurrentYear(date, timeZone)`**: Check if a date falls within the current month or year in the specified time zone.
|
|
132
|
+
|
|
115
133
|
### Time Operations (`STime`)
|
|
116
134
|
|
|
117
135
|
`STime` represents a time in the ISO 8601 format (`HH:MM`).
|
|
@@ -133,6 +151,8 @@ const totalMinutes = getTimeInMinutes(time1) // Get total minutes since midnight
|
|
|
133
151
|
|
|
134
152
|
// Time formatting
|
|
135
153
|
const timeString = get12HourTimeString(time1) // e.g., "2:30 PM"
|
|
154
|
+
const hoursString = get12HoursHoursStringFromTime(time1) // Get hours in 12-hour format (e.g., "2")
|
|
155
|
+
const minutesString = getMinutesStringFromTime(time1) // Get minutes as 2-digit string (e.g., "30")
|
|
136
156
|
|
|
137
157
|
// Time comparison
|
|
138
158
|
const isEqual = isSameTime(time1, time2)
|
|
@@ -151,6 +171,10 @@ const isPM = isTimePM(time1)
|
|
|
151
171
|
|
|
152
172
|
- **`isTimePM(time)`**: Hours from 12:00 to 23:59 are considered PM, while 00:00 to 11:59 are AM. 12:00 is considered PM, not AM.
|
|
153
173
|
|
|
174
|
+
- **`get12HoursHoursStringFromTime(time)`**: Returns the hours component in 12-hour format as a string (1-12).
|
|
175
|
+
|
|
176
|
+
- **`getMinutesStringFromTime(time)`**: Returns the minutes component as a zero-padded 2-digit string (00-59).
|
|
177
|
+
|
|
154
178
|
### Timestamp Operations (`STimestamp`)
|
|
155
179
|
|
|
156
180
|
`STimestamp` combines a date and time in the ISO 8601 format (`YYYY-MM-DDTHH:MM`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scdate",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js"
|
|
@@ -29,23 +29,23 @@
|
|
|
29
29
|
"postpublish": "pinst --enable"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@date-fns/utc": "^2.1.
|
|
32
|
+
"@date-fns/utc": "^2.1.1",
|
|
33
33
|
"date-fns": "^4.1.0",
|
|
34
34
|
"date-fns-tz": "^3.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@eslint/js": "^9.
|
|
37
|
+
"@eslint/js": "^9.33.0",
|
|
38
38
|
"@tsconfig/strictest": "^2.0.5",
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"eslint": "^9.
|
|
39
|
+
"@types/node": "^24.3.0",
|
|
40
|
+
"eslint": "^9.33.0",
|
|
41
41
|
"husky": "^9.1.7",
|
|
42
|
-
"lint-staged": "^
|
|
42
|
+
"lint-staged": "^16.1.5",
|
|
43
43
|
"pinst": "^3.0.0",
|
|
44
|
-
"prettier": "^3.
|
|
44
|
+
"prettier": "^3.6.2",
|
|
45
45
|
"rimraf": "^6.0.1",
|
|
46
|
-
"typescript": "^5.
|
|
47
|
-
"typescript-eslint": "^8.
|
|
48
|
-
"vitest": "^3.
|
|
46
|
+
"typescript": "^5.9.2",
|
|
47
|
+
"typescript-eslint": "^8.40.0",
|
|
48
|
+
"vitest": "^3.2.4"
|
|
49
49
|
},
|
|
50
50
|
"prettier": {
|
|
51
51
|
"tabWidth": 2,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"repository": {
|
|
56
56
|
"type": "git",
|
|
57
|
-
"url": "https://github.com/ericvera/scdate"
|
|
57
|
+
"url": "git+https://github.com/ericvera/scdate.git"
|
|
58
58
|
},
|
|
59
59
|
"keywords": [
|
|
60
60
|
"date",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"*.{ts,tsx,mjs}": "eslint --cache",
|
|
71
71
|
"*": "prettier --ignore-unknown --write"
|
|
72
72
|
},
|
|
73
|
-
"packageManager": "yarn@4.9.
|
|
73
|
+
"packageManager": "yarn@4.9.2"
|
|
74
74
|
}
|