Skip to content

Commit

Permalink
Add timezone property
Browse files Browse the repository at this point in the history
You can optionally replace utcOffset with a valid timezone (e.g.
'Europe/Berlin'), so we can take care of the actual utcOffset on Nov 18.

You need to specify at least one, utcOffset or timezone.
  • Loading branch information
rradczewski committed May 6, 2017
1 parent 5155a58 commit 883d989
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
13 changes: 11 additions & 2 deletions events/event_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
"type": "object",
"properties": {
"utcOffset": {
"description": "The UTC Timezone the event will take place in (e.g. UTC+1 for Berlin with DST considered)",
"description": "The UTC Timezone the event will take place in (e.g. UTC+2 on Nov 18, 2017 for Berlin with DST considered)",
"type": "number"
},
"timezone": {
"description": "The Timezone as a String, verified by https://momentjs.com/timezone/ to be an actual timezone",
"type": "string",
"format": "timezone"
},
"city": { "type": "string" },
"country": { "type": "string" },
"coordinates": {
Expand All @@ -30,7 +35,11 @@
"required": ["latitude", "longitude"]
}
},
"required": ["utcOffset", "country", "city"]
"required": ["country", "city"],
"anyOf": [
{ "required": ["utcOffset"] },
{ "required": ["timezone"] }
]
},
"moderators": {
"type": "array",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"glob": "^7.1.1",
"jsonschema": "^1.1.1",
"mocha": "^3.2.0",
"moment-timezone": "^0.5.13",
"yamljs": "^0.2.8"
}
}
12 changes: 12 additions & 0 deletions test/validate_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ const YAML = require('yamljs');

const schema = require('../events/event_schema.json');
const JsonValidator = require('jsonschema').Validator;
const moment = require('moment-timezone');

JsonValidator.prototype.customFormats.timezone = (tz) => {
if(typeof tz === 'undefined') {
return true;
}
if(typeof tz === 'string') {
return !!moment.tz.zone(tz);
}
return false;
}

const validate = input => {
const result = (new JsonValidator).validate(input, schema);
if(result.errors.length > 0) {
console.log(result.errors, JSON.stringify(result.errors));
throw new Error(result.errors);
}
}
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ mocha@^3.2.0:
mkdirp "0.5.1"
supports-color "3.1.2"

moment-timezone@^0.5.13:
version "0.5.13"
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.13.tgz#99ce5c7d827262eb0f1f702044177f60745d7b90"
dependencies:
moment ">= 2.9.0"

"moment@>= 2.9.0":
version "2.18.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"

ms@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
Expand Down

0 comments on commit 883d989

Please sign in to comment.