Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

joi-tz

4.0.2 • Public • Published

joi-tz

Build Status Coverage Status Known Vulnerabilities npm version

Provides a Joi rule to validate IANA timezone strings (eg. Europe/London, America/New_York, Etc/GMT-8) using moment-timezone.

Joi-tz only supports Joi 16.x or higher.

This project is forked from joi-timezone (unmaintained). That project remains functional for Joi 9.x-15.x.

Installation:

npm: npm install joi-tz

yarn: yarn add joi-tz

Usage

import BaseJoi from 'joi';
import JoiTimezone from 'joi-tz';
 
const Joi = BaseJoi.extend(JoiTimezone);
 
Joi.timezone().validate('Melbourne/Australia');
// returns {error: null, value: 'Melbourne/Australia'}

Rules

returnMoment - Convert to a moment zone object

When added to the validation chain returns a moment zone object which contains useful metadata about the timezone.

Joi.timezone().returnMoment().validate('America/Los_Angeles');
/*
    returns {
        error: null,
        value: {
            name    : 'America/Los_Angeles',
            abbrs   : ['PDT', 'PST'],
            untils  : [1414918800000, 1425808800000],
            offsets : [420, 480]
        }
    }
*/

Install

npm i joi-tz

DownloadsWeekly Downloads

494

Version

4.0.2

License

Apache-2.0

Unpacked Size

11.6 kB

Total Files

17

Last publish

Collaborators

  • avatar