Skip to content

Commit

Permalink
fix(datetime): Make DateTimeOptions non-nullable
Browse files Browse the repository at this point in the history
undefined is now the default value for precision, which I think makes
sense because it indicates that the precision is "not defined", and
therefore can have any or zero digits of precision.
  • Loading branch information
0livare committed Feb 14, 2024
1 parent 5db955c commit fd4d839
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export type MatchOptions = {
export type DateTimeOptions = {
message: Message<{ allowOffset?: boolean; precision?: number }>;
/** Allow a time zone offset. False requires UTC 'Z' timezone. (default: false) */
allowOffset?: boolean | null;
/** Require a certain sub-second precision on the date. (default: null -- any or no sub-second precision) */
precision?: number | null;
allowOffset?: boolean;
/** Require a certain sub-second precision on the date. (default: undefined -- any or no sub-second precision) */
precision?: number;
};

let objStringTag = {}.toString();
Expand Down Expand Up @@ -226,7 +226,7 @@ export default class StringSchema<
({
message = '',
allowOffset = false,
precision = null,
precision = undefined,
} = options as DateTimeOptions);
} else {
message = options;
Expand Down Expand Up @@ -256,7 +256,7 @@ export default class StringSchema<
params: { precision },
skipAbsent: true,
test: (value: Maybe<string>) => {
if (!value || precision == null) return true;
if (!value || precision == undefined) return true;
const struct = parseDateStruct(value);
if (!struct) return false;
return struct.precision === precision;
Expand Down

0 comments on commit fd4d839

Please sign in to comment.