Created
July 6, 2019 20:30
-
-
Save xenon92/4448fa7bad1f5ecc545dfa3557571179 to your computer and use it in GitHub Desktop.
Simple Moment Validations (Nodejs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict" | |
const moment = require('moment') | |
class MomentValidations { | |
constructor(dateTimeString) { | |
this.dateTimeString = dateTimeString | |
} | |
isUtc() { | |
let formatString = 'YYYY-MM-DDTHH:mm:ssZ' | |
let dateObject = moment(this.dateTimeString, formatString, true) | |
return dateObject.isValid() | |
} | |
} | |
//Simple usage of a class in JS | |
console.log(new MomentValidations("2019-05-11T12:05:37Z").isUtc()) //--> true | |
//Directly using the library with the format specified | |
console.log(moment("2019-05-11T12:05:37Z", 'YYYY-MM-DDTHH:mm:ssZ', true).isValid()) //--> true | |
//Directly using the library using the internal ISO format in moment library | |
console.log(moment("2019-05-11T12:05:37Z").isValid()) //--> true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment