Skip to content

Commit

Permalink
fix(date-time): Resolve issue with null date-time validations
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Oct 24, 2024
1 parent 2e3874c commit 3eaf348
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/date-time/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package is part of the ⚡<b>Storm Stack</b> monorepo. Storm Stack packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.33.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
[![Version](https://img.shields.io/badge/version-1.34.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)


> [!IMPORTANT]
Expand Down
3 changes: 3 additions & 0 deletions packages/date-time/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ export const DEFAULT_DATE_FORMAT = "M/D/YYYY";
export const DEFAULT_TIME_FORMAT = "h:mm A";

export const DEFAULT_DATE_TIME_FORMAT = `${DEFAULT_DATE_FORMAT} ${DEFAULT_TIME_FORMAT}`;

export const DATE_TIME_MISSING_DATE = "Missing Date";
export const DATE_TIME_INVALID_DATE = "Invalid Date";
20 changes: 17 additions & 3 deletions packages/date-time/src/storm-date-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import {
MessageType,
ValidationDetails
} from "@storm-stack/types";
import { RFC_3339_DATE_TIME_REGEX } from "./constants";
import {
DATE_TIME_INVALID_DATE,
DATE_TIME_MISSING_DATE,
RFC_3339_DATE_TIME_REGEX
} from "./constants";
import { DateTimeErrorCode } from "./errors";
import { isInstant } from "./utilities/is-instant";
import { validateDayOfMonth } from "./utilities/validate-day-of-month";
Expand Down Expand Up @@ -89,8 +93,6 @@ export function deserializeStormDateTime(utcString: JsonValue): StormDateTime {
: StormDateTime.create();
}

export const DATE_TIME_MISSING_DATE = "MISSING_DATE";

/**
* A wrapper of the and Date class used by Storm Software to provide Date-Time values
*
Expand Down Expand Up @@ -196,9 +198,21 @@ export class StormDateTime extends Date {
* @returns A boolean representing whether the value is a valid *date-time*
*/
public static validate(value?: DateTimeInput): ValidationDetails | null {
if (
isDate(value) ||
(StormDateTime.isDateTime(value) &&
value.toString() === DATE_TIME_INVALID_DATE)
) {
return {
code: DateTimeErrorCode.rfc_3339_format,
type: MessageType.ERROR
};
}

if (StormDateTime.isDateTime(value)) {
return value.validate();
}

if (isInstant(value)) {
if (value.epochMilliseconds) {
return null;
Expand Down
18 changes: 17 additions & 1 deletion packages/date-time/src/storm-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
MessageType,
ValidationDetails
} from "@storm-stack/types";
import { RFC_3339_DATE_REGEX, RFC_3339_DATE_TIME_REGEX } from "./constants";
import {
DATE_TIME_INVALID_DATE,
RFC_3339_DATE_REGEX,
RFC_3339_DATE_TIME_REGEX
} from "./constants";
import { DateTimeErrorCode } from "./errors";
import type { DateTimeInput, DateTimeOptions } from "./storm-date-time";
import { StormDateTime } from "./storm-date-time";
Expand Down Expand Up @@ -105,9 +109,21 @@ export class StormDate extends StormDateTime {
public static override validate(
value?: DateTimeInput
): ValidationDetails | null {
if (
isDate(value) ||
(StormDateTime.isDateTime(value) &&
value.toString() === DATE_TIME_INVALID_DATE)
) {
return {
code: DateTimeErrorCode.rfc_3339_format,
type: MessageType.ERROR
};
}

if (StormDateTime.isDateTime(value)) {
return value.validate();
}

if (isInstant(value)) {
if (value.epochMilliseconds) {
return null;
Expand Down
18 changes: 17 additions & 1 deletion packages/date-time/src/storm-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
MessageType,
ValidationDetails
} from "@storm-stack/types";
import { RFC_3339_DATE_TIME_REGEX, RFC_3339_TIME_REGEX } from "./constants";
import {
DATE_TIME_INVALID_DATE,
RFC_3339_DATE_TIME_REGEX,
RFC_3339_TIME_REGEX
} from "./constants";
import { DateTimeErrorCode } from "./errors";
import type { DateTimeInput, DateTimeOptions } from "./storm-date-time";
import { StormDateTime } from "./storm-date-time";
Expand Down Expand Up @@ -103,9 +107,21 @@ export class StormTime extends StormDateTime {
public static override validate(
value?: DateTimeInput
): ValidationDetails | null {
if (
isDate(value) ||
(StormDateTime.isDateTime(value) &&
value.toString() === DATE_TIME_INVALID_DATE)
) {
return {
code: DateTimeErrorCode.rfc_3339_format,
type: MessageType.ERROR
};
}

if (StormDateTime.isDateTime(value)) {
return value.validate();
}

if (isInstant(value)) {
if (value.epochMilliseconds) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package is part of the ⚡<b>Storm Stack</b> monorepo. Storm Stack packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-0.10.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
[![Version](https://img.shields.io/badge/version-0.11.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)


> [!IMPORTANT]
Expand Down
2 changes: 1 addition & 1 deletion packages/serialization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package is part of the ⚡<b>Storm Stack</b> monorepo. Storm Stack packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-1.31.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
[![Version](https://img.shields.io/badge/version-1.32.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)


> [!IMPORTANT]
Expand Down
2 changes: 1 addition & 1 deletion packages/types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This package is part of the ⚡<b>Storm Stack</b> monorepo. Storm Stack packages

<h3 align="center">💻 Visit <a href="https://stormsoftware.com" target="_blank">stormsoftware.com</a> to stay up to date with this developer</h3><br />

[![Version](https://img.shields.io/badge/version-0.19.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)
[![Version](https://img.shields.io/badge/version-0.20.0-1fb2a6.svg?style=for-the-badge&color=1fb2a6)](https://prettier.io/)&nbsp;[![Nx](https://img.shields.io/badge/Nx-17.0.2-lightgrey?style=for-the-badge&logo=nx&logoWidth=20&&color=1fb2a6)](http://nx.dev/)&nbsp;[![NextJs](https://img.shields.io/badge/Next.js-14.0.2-lightgrey?style=for-the-badge&logo=nextdotjs&logoWidth=20&color=1fb2a6)](https://nextjs.org/)&nbsp;[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge&logo=commitlint&color=1fb2a6)](http://commitizen.github.io/cz-cli/)&nbsp;![Semantic-Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge&color=1fb2a6)&nbsp;[![documented with Fumadocs](https://img.shields.io/badge/documented_with-fumadocs-success.svg?style=for-the-badge&logo=readthedocs&color=1fb2a6)](https://fumadocs.vercel.app/)&nbsp;![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/storm-software/storm-stack/cr.yml?style=for-the-badge&logo=github-actions&color=1fb2a6)


> [!IMPORTANT]
Expand Down

0 comments on commit 3eaf348

Please sign in to comment.