[JavaScript] Sample Code for Timezone String Validation with moment.tz.zone
I’ll introduce sample code for validating timezone strings with moment.tz.zone from Moment Timezone.
Moment Timezone Zone Object | Moment Timezone
Here’s sample code for validating timezone string format using moment.tz.zone:
It would be good to define a method like validateTimezoneFormat for use.
const moment = require('moment-timezone');
!!moment.tz.zone('America/Los_Angeles') // true
!!moment.tz.zone('Asia/Tokyo') // true
!!moment.tz.zone('Asia/Toky') //false
!!moment.tz.zone('Foo/Bar') // false
const validateTimezoneFormat = (tz) => {
return !!moment.tz.zone(tz);
};
That’s all from the Gemba.