Skip to content

patarapolw/valid-moment

Repository files navigation

valid-moment

Convert standard date string to Date, based on moment.js; and invalidate bad formatting.

https://stackoverflow.com/questions/7445328/check-if-a-string-is-a-date-value

Examples

Valid date strings include (see /src/format.ts),

  • ISO 8601 date strings (from JavaScript, Python or Java)
  • RFC 2822 date strings
  • Locale string

Invalid date string include,

  • Numbers and number strings

Plans

  • Be non-library specific, so that can use no library (Date object only), or with inmoment or luxon.

Usage

import { toDate, toMoment } from "valid-moment";
console.log(toDate(DATE_STRING))  // Returns 'null' if invalid
console.log(toMoment(DATE_STRING))  // Returns 'null' if invalid

Installation

npm i valid-moment

Tests

  • For current testing results, see /tests/tests.json. The tests are done at GMT+0700.

About

Convert standard date string to Date, based on moment.js; and invalidate bad formatting.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published