You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use `defaultDate` to provide context for validation of partial date strings. The most practical use case is leap year-aware validation of month-day strings.
78
+
79
+
```typescript
80
+
import { isValid } from'date-and-time';
81
+
82
+
// Leap day validation — result depends on the year
83
+
isValid('02-29', 'MM-DD', { defaultDate: { Y: 2024 } }); // => true (2024 is a leap year)
84
+
isValid('02-29', 'MM-DD', { defaultDate: { Y: 2023 } }); // => false (2023 is not a leap year)
85
+
isValid('02-29', 'MM-DD'); // => false (default year 1970 is not a leap year)
86
+
87
+
// Day range validation — depends on both year and month
**Note**: Values provided in `defaultDate` are also subject to range validation. For example, an out-of-range `H` value in `defaultDate` will cause `isValid()` to return `false`.
Specifies default values for date/time components that are missing from the format string. This is useful when parsing partial strings such as time-only or month-day formats.
305
+
306
+
```typescript
307
+
interfaceParsedComponents {
308
+
Y?:number; // Year
309
+
M?:number; // Month (1-12)
310
+
D?:number; // Day
311
+
H?:number; // Hour (24-hour)
312
+
A?:number; // Meridiem (0: AM, 1: PM)
313
+
h?:number; // Hour (12-hour)
314
+
m?:number; // Minute
315
+
s?:number; // Second
316
+
S?:number; // Millisecond
317
+
Z?:number; // Timezone offset in minutes (e.g., UTC+9 = -540)
318
+
}
319
+
```
320
+
321
+
**Note**: If `defaultDate.Z` is set, it takes precedence over the `timeZone` option. `Z` is in minutes, using the same sign convention as the `Z` / `ZZ` format tokens (e.g., UTC+9 = `-540`).
322
+
323
+
```typescript
324
+
import { parse } from'date-and-time';
325
+
326
+
// Parse time-only string — fill in date from defaultDate
|`dateString`|`string`| Yes | The date string to parse |
18
18
|`formatString`|`string \| CompiledObject`| Yes | Format pattern string or compiled object |
19
-
|`options`|`ParserOptions`| No | Parsing options for customization (see [`parse()`](./parse) for details) |
19
+
|`options`|`ParserOptions`| No | Parsing options for customization (see [`parse()`](./parse#parseroptions) for details) |
20
20
21
21
### Returns
22
22
@@ -94,7 +94,7 @@ console.log(result);
94
94
95
95
## ParserOptions
96
96
97
-
The `options` parameter accepts the same `ParserOptions` as the [`parse()`](./parse#parseroptions) function. This includes locale, timezone, numeral system, calendar, case sensitivity, and hour format settings. Refer to the parse documentation for complete details on all available options.
97
+
The `options` parameter accepts the same `ParserOptions` as the [`parse()`](./parse#parseroptions) function. This includes locale, timezone, numeral system, calendar, case sensitivity, hour format settings, and `defaultDate`. Refer to the parse documentation for complete details on all available options.
0 commit comments