Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: { toDate: () => Date } #356

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/data_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ class DATE extends DataType {
return this._round(value);
}

uncast(value: null | Raw | string | Date, _strict?: boolean): string | Date | Raw {
uncast(value: null | Raw | string | Date | { toDate: () => Date }, _strict?: boolean): string | Date | Raw {
const originValue = value;

if (value == null || value instanceof Raw) return value;
// type narrowing doesn't handle `return value` correctly
if (value == null) return value as null | undefined;
if (value instanceof Raw) return value;
// Date | Moment
if (typeof (value as any).toDate === 'function') {
value = (value as any).toDate();
}
if (typeof value === 'object' && 'toDate' in value) value = value.toDate();

// @deprecated
// vaguely standard date formats such as 2021-10-15 15:50:02,548
Expand Down