Page 1 of 1

Custom library error in server code

Posted: Mon Jun 02, 2014 10:54 pm
by Deki

How can I add this javascript as a library in the Server Code?
When I try and use the library it comes back with an error below. The same happens when I test it. I already have the necessary dependencies (other supporting libraries) selected as well.

pre
Script timezone: TypeError: Cannot call method 'add' of undefined ( @ 1 : 10 ) - moment.tz.add({
/pre

I want to include this as a library in Server Code
pre
moment.tz.add({
"zones": {
"America/Denver": [
"-6:59:56 - LMT 1883_10_18_12_0_4 -6:59:56",
"-7 US M%sT 1920 -7",
"-7 Denver M%sT 1942 -7",
"-7 US M%sT 1946 -7",
"-7 Denver M%sT 1967 -7",
"-7 US M%sT"
]
},
"rules": {
"US": [
"1918 1919 2 0 8 2 0 1 D",
"1918 1919 9 0 8 2 0 0 S",
"1942 1942 1 9 7 2 0 1 W",
"1945 1945 7 14 7 23 1 1 P",
"1945 1945 8 30 7 2 0 0 S",
"1967 2006 9 0 8 2 0 0 S",
"1967 1973 3 0 8 2 0 1 D",
"1974 1974 0 6 7 2 0 1 D",
"1975 1975 1 23 7 2 0 1 D",
"1976 1986 3 0 8 2 0 1 D",
"1987 2006 3 1 0 2 0 1 D",
"2007 9999 2 8 0 2 0 1 D",
"2007 9999 10 1 0 2 0 0 S"
],
"Denver": [
"1920 1921 2 0 8 2 0 1 D",
"1920 1920 9 0 8 2 0 0 S",
"1921 1921 4 22 7 2 0 0 S",
"1965 1966 3 0 8 2 0 1 D",
"1965 1966 9 0 8 2 0 0 S"
]
},
"links": {}
});
/pre


Custom library error in server code

Posted: Tue Jun 03, 2014 12:01 am
by Alena Prykhodko

Hello,

There is no such object as moment.tz.
You need to add it first and then execute you code.

Where does it stem from and what is it supposed to do?


Custom library error in server code

Posted: Tue Jun 03, 2014 1:38 am
by Deki

Alena, below is the moment tz object. I have added this as a separate library and it works just fine. However, my problem is adding the code above. The code above is supposed to work in conjunction with this, but it gives me that error.

pre
// moment-timezone.js
// version : 0.0.6
// author : Tim Wood
// license : MIT
// github.com/timrwood/moment-timezone

(function () {

var VERSION = "0.0.6";

function onload(moment) {
var oldZoneName = moment.fn.zoneName,
oldZoneAbbr = moment.fn.zoneAbbr,

Code: Select all

defaultRule, 
rules = {}, 
ruleSets = {}, 
zones = {}, 
zoneSets = {}, 
links = {}, 

TIME_RULE_WALL_CLOCK = 0, 
TIME_RULE_UTC        = 1, 
TIME_RULE_STANDARD   = 2, 

DAY_RULE_DAY_OF_MONTH   = 7, 
DAY_RULE_LAST_WEEKDAY   = 8; 

if (moment.tz !== undefined) {
// Do not load moment-timezone a second time.
return moment;
}

// converts time in the HH:mm:ss format to absolute number of minutes
function parseMinutes (input) {
input = input + '';
var output = input.split(':'),
sign = input.indexOf('-') ? -1 : 1,
hour = Math.abs(+output[0]),
minute = parseInt(output[1], 10) 0,
second = parseInt(output[2], 10) 0;

Code: Select all

return sign * ((hour * 60) + (minute) + (second / 60)); 

}

/************************************
Rules
************************************/

function Rule (name, startYear, endYear, month, day, dayRule, time, timeRule, offset, letters) {
this.name = name;
this.startYear = +startYear;
this.endYear = +endYear;
this.month = +month;
this.day = +day;
this.dayRule = +dayRule;
this.time = parseMinutes(time);
this.timeRule = +timeRule;
this.offset = parseMinutes(offset);
this.letters = letters || '';
this.date = memoize(this.date);
this.weekdayAfter = memoize(this.weekdayAfter);
this.lastWeekday = memoize(this.lastWeekday);
}

Rule.prototype = {
contains : function (year) {
return (year = this&#46;startYear && year < day) {
output += 7;
}

Code: Select all

 return output; 
}, 

lastWeekday : function (year) { 
 var day = this&#46;day, 
  dow = day % 7, 
  lastDowOfMonth = moment([year, this&#46;month + 1, 1])&#46;day(), 
  daysInMonth = moment([year, this&#46;month, 1])&#46;daysInMonth(), 
  output = daysInMonth + (dow - (lastDowOfMonth - 1)) - (~~(day / 7) * 7); 

 if (dow = lastDowOfMonth) { 
  output -= 7; 
 } 
 return output; 
} 

};

/************************************
Rule Year
************************************/

function RuleYear (year, rule) {
this&#46;rule = rule;
this&#46;start = rule&#46;start(year);
}

RuleYear&#46;prototype = {
equals : function (other) {
if (!other || other&#46;rule !== this&#46;rule) {
return false;
}
return Math&#46;abs(other&#46;start - this&#46;start) < 86400000; &#47;&#47; 24 * 60 * 60 * 1000
}
};

function sortRuleYears (a, b) {
if (a&#46;isLast) {
return -1;
}
if (b&#46;isLast) {
return 1;
}
return b&#46;start - a&#46;start;
}

/************************************
Rule Sets
************************************/

function RuleSet (name) {
this&#46;name = name;
this&#46;rules = [];
this&#46;lastYearRule = memoize(this&#46;lastYearRule);
}

RuleSet&#46;prototype = {
add : function (rule) {
this&#46;rules&#46;push(rule);
},

Code: Select all

ruleYears : function (mom, lastZone) { 
 var i, j, 
  year = mom&#46;year(), 
  rule, 
  lastZoneRule, 
  rules = []; 

 for (i = 0; i < this&#46;rules&#46;length; i++) { 
  rule = this&#46;rules[i]; 
  if (rule&#46;contains(year)) { 
   rules&#46;push(new RuleYear(year, rule)); 
  } else if (rule&#46;contains(year + 1)) { 
   rules&#46;push(new RuleYear(year + 1, rule)); 
  } 
 } 
 rules&#46;push(new RuleYear(year - 1, this&#46;lastYearRule(year - 1))); 

 if (lastZone) { 
  lastZoneRule = new RuleYear(year - 1, lastZone&#46;lastRule()); 
  lastZoneRule&#46;start = lastZone&#46;until&#46;clone()&#46;utc(); 
  lastZoneRule&#46;isLast = lastZone&#46;ruleSet !== this; 
  rules&#46;push(lastZoneRule); 
 } 

 rules&#46;sort(sortRuleYears); 
 return rules; 
}, 

rule : function (mom, offset, lastZone) { 
 var rules = this&#46;ruleYears(mom, lastZone), 
  lastOffset = 0, 
  rule, 
  lastZoneOffset, 
  lastZoneOffsetAbs, 
  lastRule, 
  i; 

 if (lastZone) { 
  lastZoneOffset = lastZone&#46;offset + lastZone&#46;lastRule()&#46;offset; 
  lastZoneOffsetAbs = Math&#46;abs(lastZoneOffset) * 90000; 
 } 

 &#47;&#47; make sure to include the previous rule's offset 
 for (i = rules&#46;length - 1; i  -1; i--) { 
  lastRule = rule; 
  rule = rules[i]; 

  if (rule&#46;equals(lastRule)) { 
   continue; 
  } 

  if (lastZone && !rule&#46;isLast && Math&#46;abs(rule&#46;start - lastZone&#46;until) < rules&#46;length; i++) { 
  rule = rules[i]; 
  if (mom = rule&#46;start && !rule&#46;isLast) { 
   return rule&#46;rule; 
  } 
 } 

 return defaultRule; 
}, 

lastYearRule : function (year) { 
 var i, 
  rule, 
  start, 
  bestRule = defaultRule, 
  largest = -1e30; 

 for (i = 0; i < this&#46;rules&#46;length; i++) { 
  rule = this&#46;rules[i]; 
  if (year = rule&#46;startYear) { 
   start = rule&#46;start(year); 
   if (start  largest) { 
    largest = start; 
    bestRule = rule; 
   } 
  } 
 } 

 return bestRule; 
} 

};

/************************************
Zone
************************************/

function Zone (name, offset, ruleSet, letters, until, untilOffset) {
var i,
untilArray = typeof until === 'string' ? until&#46;split('_') : [9999];

Code: Select all

this&#46;name = name; 
this&#46;offset = parseMinutes(offset); 
this&#46;ruleSet = ruleSet; 
this&#46;letters = letters; 
this&#46;lastRule = memoize(this&#46;lastRule); 

for (i = 0; i < untilArray&#46;length; i++) { 
 untilArray[i] = +untilArray[i]; 
} 
this&#46;until = moment&#46;utc(untilArray)&#46;subtract('m', parseMinutes(untilOffset)); 

}

Zone&#46;prototype = {
rule : function (mom, lastZone) {
return this&#46;ruleSet&#46;rule(mom, this&#46;offset, lastZone);
},

Code: Select all

lastRule : function () { 
 return this&#46;rule(this&#46;until); 
}, 

format : function (rule) { 
 return this&#46;letters&#46;replace("%s", rule&#46;letters); 
} 

};

/************************************
Zone Set
************************************/

function sortZones (a, b) {
return a&#46;until - b&#46;until;
}

function ZoneSet (name) {
this&#46;name = normalizeName(name);
this&#46;displayName = name;
this&#46;zones = [];
this&#46;zoneAndRule = memoize(this&#46;zoneAndRule, function (mom) {
return +mom;
});
}

ZoneSet&#46;prototype = {
zoneAndRule : function (mom) {
var i,
zone,
lastZone;

Code: Select all

 mom = mom&#46;clone()&#46;utc(); 
 for (i = 0; i < this&#46;zones&#46;length; i++) { 
  zone = this&#46;zones[i]; 
  if (mom < zone&#46;until) { 
   break; 
  } 
  lastZone = zone; 
 } 

 return [zone, zone&#46;rule(mom, lastZone)]; 
}, 

add : function (zone) { 
 this&#46;zones&#46;push(zone); 
 this&#46;zones&#46;sort(sortZones); 
}, 

format : function (mom) { 
 var zoneAndRule = this&#46;zoneAndRule(mom); 
 return zoneAndRule[0]&#46;format(zoneAndRule[1]); 
}, 

offset : function (mom) { 
 var zoneAndRule = this&#46;zoneAndRule(mom); 
 return -(zoneAndRule[0]&#46;offset + zoneAndRule[1]&#46;offset); 
} 

};

/************************************
Global Methods
************************************/

function memoize (fn, keyFn) {
var cache = {};
return function (first) {
var key = keyFn ? keyFn&#46;apply(this, arguments) : first;
return key in cache ?
cache[key] :
(cache[key] = fn&#46;apply(this, arguments));
};
}

function addRules (rules) {
var i, j, rule;
for (i in rules) {
rule = rules;
for (j = 0; j < rule&#46;length; j++) {
addRule(i + '\t' + rule[j]);
}
}
}

function addRule (ruleString) {
&#47;&#47; don't duplicate rules
if (rules[ruleString]) {
return rules[ruleString];
}

Code: Select all

var p = ruleString&#46;split(/\s/), 
 name = normalizeName(p[0]), 
 rule = new Rule(name, p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10]); 

&#47;&#47; cache the rule so we don't add it again 
rules[ruleString] = rule; 

&#47;&#47; add to the ruleset 
getRuleSet(name)&#46;add(rule); 

return rule; 

}

function normalizeName (name) {
return (name || '')&#46;toLowerCase()&#46;replace(/
// moment-timezone.js
// version : 0.0.6
// author : Tim Wood
// license : MIT
// github.com/timrwood/moment-timezone

(function () {

var VERSION = "0.0.6";

function onload(moment) {
var oldZoneName = moment.fn.zoneName,
oldZoneAbbr = moment.fn.zoneAbbr,

Code: Select all

defaultRule, 
rules = {}, 
ruleSets = {}, 
zones = {}, 
zoneSets = {}, 
links = {}, 

TIME_RULE_WALL_CLOCK = 0, 
TIME_RULE_UTC        = 1, 
TIME_RULE_STANDARD   = 2, 

DAY_RULE_DAY_OF_MONTH   = 7, 
DAY_RULE_LAST_WEEKDAY   = 8; 

if (moment.tz !== undefined) {
// Do not load moment-timezone a second time.
return moment;
}

// converts time in the HH:mm:ss format to absolute number of minutes
function parseMinutes (input) {
input = input + '';
var output = input.split(':'),
sign = input.indexOf('-') ? -1 : 1,
hour = Math.abs(+output[0]),
minute = parseInt(output[1], 10) 0,
second = parseInt(output[2], 10) 0;

Code: Select all

return sign * ((hour * 60) + (minute) + (second / 60)); 

}

/************************************
Rules
************************************/

function Rule (name, startYear, endYear, month, day, dayRule, time, timeRule, offset, letters) {
this.name = name;
this.startYear = +startYear;
this.endYear = +endYear;
this.month = +month;
this.day = +day;
this.dayRule = +dayRule;
this.time = parseMinutes(time);
this.timeRule = +timeRule;
this.offset = parseMinutes(offset);
this.letters = letters || '';
this.date = memoize(this.date);
this.weekdayAfter = memoize(this.weekdayAfter);
this.lastWeekday = memoize(this.lastWeekday);
}

Rule.prototype = {
contains : function (year) {
return (year = this.startYear && year < day) {
output += 7;
}

Code: Select all

 return output; 
}, 

lastWeekday : function (year) { 
 var day = this.day, 
  dow = day % 7, 
  lastDowOfMonth = moment([year, this.month + 1, 1]).day(), 
  daysInMonth = moment([year, this.month, 1]).daysInMonth(), 
  output = daysInMonth + (dow - (lastDowOfMonth - 1)) - (~~(day / 7) * 7); 

 if (dow = lastDowOfMonth) { 
  output -= 7; 
 } 
 return output; 
} 

};

/************************************
Rule Year
************************************/

function RuleYear (year, rule) {
this.rule = rule;
this.start = rule.start(year);
}

RuleYear.prototype = {
equals : function (other) {
if (!other || other.rule !== this.rule) {
return false;
}
return Math.abs(other.start - this.start) < 86400000; // 24 * 60 * 60 * 1000
}
};

function sortRuleYears (a, b) {
if (a.isLast) {
return -1;
}
if (b.isLast) {
return 1;
}
return b.start - a.start;
}

/************************************
Rule Sets
************************************/

function RuleSet (name) {
this.name = name;
this.rules = [];
this.lastYearRule = memoize(this.lastYearRule);
}

RuleSet.prototype = {
add : function (rule) {
this.rules.push(rule);
},

Code: Select all

ruleYears : function (mom, lastZone) { 
 var i, j, 
  year = mom.year(), 
  rule, 
  lastZoneRule, 
  rules = []; 

 for (i = 0; i < this.rules.length; i++) { 
  rule = this.rules[i]; 
  if (rule.contains(year)) { 
   rules.push(new RuleYear(year, rule)); 
  } else if (rule.contains(year + 1)) { 
   rules.push(new RuleYear(year + 1, rule)); 
  } 
 } 
 rules.push(new RuleYear(year - 1, this.lastYearRule(year - 1))); 

 if (lastZone) { 
  lastZoneRule = new RuleYear(year - 1, lastZone.lastRule()); 
  lastZoneRule.start = lastZone.until.clone().utc(); 
  lastZoneRule.isLast = lastZone.ruleSet !== this; 
  rules.push(lastZoneRule); 
 } 

 rules.sort(sortRuleYears); 
 return rules; 
}, 

rule : function (mom, offset, lastZone) { 
 var rules = this.ruleYears(mom, lastZone), 
  lastOffset = 0, 
  rule, 
  lastZoneOffset, 
  lastZoneOffsetAbs, 
  lastRule, 
  i; 

 if (lastZone) { 
  lastZoneOffset = lastZone.offset + lastZone.lastRule().offset; 
  lastZoneOffsetAbs = Math.abs(lastZoneOffset) * 90000; 
 } 

 // make sure to include the previous rule's offset 
 for (i = rules.length - 1; i  -1; i--) { 
  lastRule = rule; 
  rule = rules[i]; 

  if (rule.equals(lastRule)) { 
   continue; 
  } 

  if (lastZone && !rule.isLast && Math.abs(rule.start - lastZone.until) < rules.length; i++) { 
  rule = rules[i]; 
  if (mom = rule.start && !rule.isLast) { 
   return rule.rule; 
  } 
 } 

 return defaultRule; 
}, 

lastYearRule : function (year) { 
 var i, 
  rule, 
  start, 
  bestRule = defaultRule, 
  largest = -1e30; 

 for (i = 0; i < this.rules.length; i++) { 
  rule = this.rules[i]; 
  if (year = rule.startYear) { 
   start = rule.start(year); 
   if (start  largest) { 
    largest = start; 
    bestRule = rule; 
   } 
  } 
 } 

 return bestRule; 
} 

};

/************************************
Zone
************************************/

function Zone (name, offset, ruleSet, letters, until, untilOffset) {
var i,
untilArray = typeof until === 'string' ? until.split('_') : [9999];

Code: Select all

this.name = name; 
this.offset = parseMinutes(offset); 
this.ruleSet = ruleSet; 
this.letters = letters; 
this.lastRule = memoize(this.lastRule); 

for (i = 0; i < untilArray.length; i++) { 
 untilArray[i] = +untilArray[i]; 
} 
this.until = moment.utc(untilArray).subtract('m', parseMinutes(untilOffset)); 

}

Zone.prototype = {
rule : function (mom, lastZone) {
return this.ruleSet.rule(mom, this.offset, lastZone);
},

Code: Select all

lastRule : function () { 
 return this.rule(this.until); 
}, 

format : function (rule) { 
 return this.letters.replace("%s", rule.letters); 
} 

};

/************************************
Zone Set
************************************/

function sortZones (a, b) {
return a.until - b.until;
}

function ZoneSet (name) {
this.name = normalizeName(name);
this.displayName = name;
this.zones = [];
this.zoneAndRule = memoize(this.zoneAndRule, function (mom) {
return +mom;
});
}

ZoneSet.prototype = {
zoneAndRule : function (mom) {
var i,
zone,
lastZone;

Code: Select all

 mom = mom.clone().utc(); 
 for (i = 0; i < this.zones.length; i++) { 
  zone = this.zones[i]; 
  if (mom < zone.until) { 
   break; 
  } 
  lastZone = zone; 
 } 

 return [zone, zone.rule(mom, lastZone)]; 
}, 

add : function (zone) { 
 this.zones.push(zone); 
 this.zones.sort(sortZones); 
}, 

format : function (mom) { 
 var zoneAndRule = this.zoneAndRule(mom); 
 return zoneAndRule[0].format(zoneAndRule[1]); 
}, 

offset : function (mom) { 
 var zoneAndRule = this.zoneAndRule(mom); 
 return -(zoneAndRule[0].offset + zoneAndRule[1].offset); 
} 

};

/************************************
Global Methods
************************************/

function memoize (fn, keyFn) {
var cache = {};
return function (first) {
var key = keyFn ? keyFn.apply(this, arguments) : first;
return key in cache ?
cache[key] :
(cache[key] = fn.apply(this, arguments));
};
}

function addRules (rules) {
var i, j, rule;
for (i in rules) {
rule = rules;
for (j = 0; j < rule.length; j++) {
addRule(i + '\t' + rule[j]);
}
}
}

function addRule (ruleString) {
// don't duplicate rules
if (rules[ruleString]) {
return rules[ruleString];
}

Code: Select all

var p = ruleString.split(/\s/), 
 name = normalizeName(p[0]), 
 rule = new Rule(name, p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10]); 

// cache the rule so we don't add it again 
rules[ruleString] = rule; 

// add to the ruleset 
getRuleSet(name).add(rule); 

return rule; 

}

function normalizeName (name) {
return (name || '').toLowerCase().replace(/\//g, '_');
}

function addZones (zones) {
var i, j, zone;
for (i in zones) {
zone = zones;
for (j = 0; j < zone.length; j++) {
addZone(i + '\t' + zone[j]);
}
}
}

function addLinks (linksToAdd) {
var i;
for (i in linksToAdd) {
links[normalizeName(i)] = normalizeName(linksToAdd);
}
}

function addZone (zoneString) {
// don't duplicate zones
if (zones[zoneString]) {
return zones[zoneString];
}

Code: Select all

var p = zoneString.split(/\s/), 
 name = normalizeName(p[0]), 
 zone = new Zone(name, p[1], getRuleSet(p[2]), p[3], p[4], p[5]); 

// cache the zone so we don't add it again 
zones[zoneString] = zone; 

// add to the zoneset 
getZoneSet(p[0]).add(zone); 

return zone; 

}

function getRuleSet (name) {
name = normalizeName(name);
if (!ruleSets[name]) {
ruleSets[name] = new RuleSet(name);
}
return ruleSets[name];
}

function getZoneSet (name) {
var machineName = normalizeName(name);
if (links[machineName]) {
machineName = links[machineName];
}
if (!zoneSets[machineName]) {
zoneSets[machineName] = new ZoneSet(name);
}
return zoneSets[machineName];
}

function add (data) {
if (!data) {
return;
}
if (data.zones) {
addZones(data.zones);
}
if (data.rules) {
addRules(data.rules);
}
if (data.links) {
addLinks(data.links);
}
}

// overwrite moment.updateOffset
moment.updateOffset = function (mom, keepTime) {
var offset;
if (mom.z) {
offset = mom.z.offset(mom);
if (Math.abs(offset) < 16) {
offset = offset / 60;
}
mom.zone(offset, keepTime);
}
};

function getZoneSets() {
var sets = [],
zoneName;
for (zoneName in zoneSets) {
sets.push(zoneSets[zoneName]);
}
return sets;
}

moment.fn.tz = function (name) {
if (name) {
this.z = getZoneSet(name);
if (this.z) {
moment.updateOffset(this);
}
return this;
}
if (this.z) {
return this.z.displayName;
}
};

moment.fn.zoneName = function () {
if (this.z) {
return this.z.format(this);
}
return oldZoneName.call(this);
};

moment.fn.zoneAbbr = function () {
if (this.z) {
return this.z.format(this);
}
return oldZoneAbbr.call(this);
};

// Make sure moment's clone includes the newly added properties
moment.momentProperties._z = null;

moment.tz = function () {
var args = [], i, len = arguments.length - 1;
for (i = 0; i < len; i++) {
args = arguments;
}
var m = moment.apply(null, args);
var preTzOffset = m.zone();
m.tz(arguments[len]);
return m.add('minutes', m.zone() - preTzOffset);
};

moment.tz.add = add;
moment.tz.addRule = addRule;
moment.tz.addZone = addZone;
moment.tz.zones = getZoneSets;

moment.tz.version = VERSION;

moment.tz.zoneExists = function (name) {
return getZoneSet(name).zones.length 0;
};

// add default rule
defaultRule = addRule("- 0 9999 0 0 0 0 0 0");

return moment;
}

if (typeof define === "function" && define.amd) {
define("moment-timezone", ["moment"], onload);
} else if (typeof module !== 'undefined') {
module.exports = onload(require('moment'));
} else if (typeof window !== "undefined" && window.moment) {
onload(window.moment);
}
}).apply(this);

#47;&#47;g, '_');
}

function addZones (zones) {
var i, j, zone;
for (i in zones) {
zone = zones;
for (j = 0; j < zone&#46;length; j++) {
addZone(i + '\t' + zone[j]);
}
}
}

function addLinks (linksToAdd) {
var i;
for (i in linksToAdd) {
links[normalizeName(i)] = normalizeName(linksToAdd);
}
}

function addZone (zoneString) {
&#47;&#47; don't duplicate zones
if (zones[zoneString]) {
return zones[zoneString];
}

Code: Select all

var p = zoneString&#46;split(/\s/), 
 name = normalizeName(p[0]), 
 zone = new Zone(name, p[1], getRuleSet(p[2]), p[3], p[4], p[5]); 

&#47;&#47; cache the zone so we don't add it again 
zones[zoneString] = zone; 

&#47;&#47; add to the zoneset 
getZoneSet(p[0])&#46;add(zone); 

return zone; 

}

function getRuleSet (name) {
name = normalizeName(name);
if (!ruleSets[name]) {
ruleSets[name] = new RuleSet(name);
}
return ruleSets[name];
}

function getZoneSet (name) {
var machineName = normalizeName(name);
if (links[machineName]) {
machineName = links[machineName];
}
if (!zoneSets[machineName]) {
zoneSets[machineName] = new ZoneSet(name);
}
return zoneSets[machineName];
}

function add (data) {
if (!data) {
return;
}
if (data&#46;zones) {
addZones(data&#46;zones);
}
if (data&#46;rules) {
addRules(data&#46;rules);
}
if (data&#46;links) {
addLinks(data&#46;links);
}
}

&#47;&#47; overwrite moment&#46;updateOffset
moment&#46;updateOffset = function (mom, keepTime) {
var offset;
if (mom&#46;z) {
offset = mom&#46;z&#46;offset(mom);
if (Math&#46;abs(offset) < 16) {
offset = offset / 60;
}
mom&#46;zone(offset, keepTime);
}
};

function getZoneSets() {
var sets = [],
zoneName;
for (zoneName in zoneSets) {
sets&#46;push(zoneSets[zoneName]);
}
return sets;
}

moment&#46;fn&#46;tz = function (name) {
if (name) {
this&#46;z = getZoneSet(name);
if (this&#46;z) {
moment&#46;updateOffset(this);
}
return this;
}
if (this&#46;z) {
return this&#46;z&#46;displayName;
}
};

moment&#46;fn&#46;zoneName = function () {
if (this&#46;z) {
return this&#46;z&#46;format(this);
}
return oldZoneName&#46;call(this);
};

moment&#46;fn&#46;zoneAbbr = function () {
if (this&#46;z) {
return this&#46;z&#46;format(this);
}
return oldZoneAbbr&#46;call(this);
};

&#47;&#47; Make sure moment's clone includes the newly added properties
moment&#46;momentProperties&#46;_z = null;

moment&#46;tz = function () {
var args = [], i, len = arguments&#46;length - 1;
for (i = 0; i < len; i++) {
args = arguments;
}
var m = moment&#46;apply(null, args);
var preTzOffset = m&#46;zone();
m&#46;tz(arguments[len]);
return m&#46;add('minutes', m&#46;zone() - preTzOffset);
};

moment&#46;tz&#46;add = add;
moment&#46;tz&#46;addRule = addRule;
moment&#46;tz&#46;addZone = addZone;
moment&#46;tz&#46;zones = getZoneSets;

moment&#46;tz&#46;version = VERSION;

moment&#46;tz&#46;zoneExists = function (name) {
return getZoneSet(name)&#46;zones&#46;length 0;
};

&#47;&#47; add default rule
defaultRule = addRule("- 0 9999 0 0 0 0 0 0");

return moment;
}

if (typeof define === "function" && define&#46;amd) {
define("moment-timezone", ["moment"], onload);
} else if (typeof module !== 'undefined') {
module&#46;exports = onload(require('moment'));
} else if (typeof window !== "undefined" && window&#46;moment) {
onload(window&#46;moment);
}
})&#46;apply(this);

/pre


Custom library error in server code

Posted: Tue Jun 03, 2014 2:06 pm
by Deki

How do I manage libraries with execution sequence?


Custom library error in server code

Posted: Tue Jun 03, 2014 2:09 pm
by Evgene Karachevtsev

Deki,

The problem is in your moment-timezone library in these rows:

codeif (typeof define === "function" && define&#46;amd) {
define("moment-timezone", ["moment"], onload);
} else if (typeof module !== 'undefined') {
module&#46;exports = onload(require('moment'));
} else if (typeof window !== "undefined" && window&#46;moment) {
onload(window&#46;moment);
} /code
In server code there is not window object, we don't have module system so this library doesn't expose. You should yourself investigate this problem and fix code in this library or look for another one.


Custom library error in server code

Posted: Tue Jun 03, 2014 2:29 pm
by Deki

Ok, I will look into that code, but i still have the question - How do I manage libraries with execution sequence? Also, do you have any idea on how to re-write this code so that it will work? I really need some help on this...


Custom library error in server code

Posted: Tue Jun 03, 2014 7:05 pm
by Deki

Any ideas on this?


Custom library error in server code

Posted: Tue Jun 03, 2014 7:27 pm
by Kateryna Grynko

Hi Deki,

You can use the following library to change your library code: http://momentjs.com/


Custom library error in server code

Posted: Tue Jun 03, 2014 9:37 pm
by Deki

Katya, please read my initial problem. I am using that library in conjunction with timezonejs (works along with momentjs as a dependency). My problem however is as Evgene pointed out - is exposing the library. Apperyio's server code does not allow for window object and doesn't have modules. So, can you guys please advise on how I can expose this library


Custom library error in server code

Posted: Wed Jun 04, 2014 1:42 pm
by Evgene Karachevtsev

Hello Deki,

I am sorry to have to tell you this would require customizing source code, but custom code and adding 3rd party plugins/libraries are outside the scope of our support.