ical.js-one.com
Version:
[](http://travis-ci.org/mozilla-comm/ical.js)
76 lines (66 loc) • 2.01 kB
JavaScript
// singleton class to contain timezones.
// Right now its all manual registry in the
// future we may use this class to download timezone
// information or handle loading pre-expanded timezones.
ICAL.TimezoneService = (function() {
var zones;
// Using var rather then return so we don't need to name the functions twice.
// TimezoneService#get will appear in profiler, etc...
var TimezoneService = {
reset: function() {
zones = Object.create(null);
var utc = ICAL.Timezone.utcTimezone;
zones.Z = utc;
zones.UTC = utc;
zones.GMT = utc;
},
/**
* Checks if timezone id has been registered.
*
* @param {String} tzid (e.g. America/Los_Angeles).
* @return {Boolean} false when not present.
*/
has: function(tzid) {
return !!zones[tzid];
},
/**
* Returns a timezone by its tzid if present.
*
* @param {String} tzid name of timezone (e.g. America/Los_Angeles).
* @return {ICAL.Timezone|Null} zone or null.
*/
get: function(tzid) {
return zones[tzid];
},
/**
* Registers a timezone object or component.
*
* @param {String} [name] optional uses timezone.tzid by default.
* @param {ICAL.Component|ICAL.Timezone} zone initialized zone or vtimezone.
*/
register: function(name, timezone) {
if (name instanceof ICAL.Component) {
if (name.name === 'vtimezone') {
timezone = new ICAL.Timezone(name);
name = timezone.tzid;
}
}
if (timezone instanceof ICAL.Timezone) {
zones[name] = timezone;
} else {
throw new TypeError('timezone must be ICAL.Timezone or ICAL.Component');
}
},
/**
* Removes a timezone by its tzid from the list.
*
* @param {String} tzid (e.g. America/Los_Angeles).
*/
remove: function(tzid) {
return (delete zones[tzid]);
}
};
// initialize defaults
TimezoneService.reset();
return TimezoneService;
}());