UNPKG

@storm-stack/date-time

Version:

This package includes a DateTime class, various utility functions for working with dates and times, and a number of formatting options.

47 lines (46 loc) 1.02 kB
import { MessageType } from "@storm-stack/types/utility-types/messages"; import { DateTimeErrorCode } from "../errors.mjs"; export const validateDayOfMonth = (value) => { switch (value.zonedDateTime.month) { case 0: case 2: case 4: case 6: case 7: case 9: case 11: { if (value.zonedDateTime.day > 31) { return { code: DateTimeErrorCode.invalid_day_of_month, type: MessageType.ERROR }; } break; } case 1: { if (value.zonedDateTime.day > (value.zonedDateTime.inLeapYear ? 29 : 28)) { return { code: DateTimeErrorCode.invalid_day_of_month, type: MessageType.ERROR }; } break; } case 3: case 5: case 8: case 10: { if (value.zonedDateTime.day > 30) { return { code: DateTimeErrorCode.invalid_day_of_month, type: MessageType.ERROR }; } break; } default: { break; } } return null; };