org.hisrc.jsonix.Jsonix.XML.Calendar.js Maven / Gradle / Ivy
Jsonix.XML.Calendar = Jsonix.Class({
year : NaN,
month : NaN,
day : NaN,
hour : NaN,
minute : NaN,
second : NaN,
fractionalSecond : NaN,
timezone : NaN,
initialize : function(data) {
Jsonix.Util.Ensure.ensureObject(data);
// Year
if (Jsonix.Util.Type.exists(data.year)) {
Jsonix.Util.Ensure.ensureInteger(data.year);
if (data.year >= -9999 && data.year <= 9999) {
this.year = data.year;
} else {
throw new Error('Invalid year [' + data.year + '].');
}
} else {
this.year = NaN;
}
// Month
if (Jsonix.Util.Type.exists(data.month)) {
Jsonix.Util.Ensure.ensureInteger(data.month);
if (data.month >= 1 && data.month <= 12) {
this.month = data.month;
} else {
throw new Error('Invalid month [' + data.month + '].');
}
} else {
this.month = NaN;
}
// Day
if (Jsonix.Util.Type.exists(data.day)) {
Jsonix.Util.Ensure.ensureInteger(data.day);
if (data.day >= 1 && data.day <= 31) {
this.day = data.day;
} else {
throw new Error('Invalid day [' + data.day + '].');
}
} else {
this.day = NaN;
}
// Hour
if (Jsonix.Util.Type.exists(data.hour)) {
Jsonix.Util.Ensure.ensureInteger(data.hour);
if (data.hour >= 0 && data.hour <= 23) {
this.hour = data.hour;
} else {
throw new Error('Invalid hour [' + data.hour + '].');
}
} else {
this.hour = NaN;
}
// Minute
if (Jsonix.Util.Type.exists(data.minute)) {
Jsonix.Util.Ensure.ensureInteger(data.minute);
if (data.minute >= 0 && data.minute <= 59) {
this.minute = data.minute;
} else {
throw new Error('Invalid minute [' + data.minute + '].');
}
} else {
this.minute = NaN;
}
// Second
if (Jsonix.Util.Type.exists(data.second)) {
Jsonix.Util.Ensure.ensureInteger(data.second);
if (data.second >= 0 && data.second <= 59) {
this.second = data.second;
} else {
throw new Error('Invalid second [' + data.second + '].');
}
} else {
this.second = NaN;
}
// Fractional second
if (Jsonix.Util.Type.exists(data.fractionalSecond)) {
Jsonix.Util.Ensure.ensureNumber(data.fractionalSecond);
if (data.fractionalSecond >= 0 && data.fractionalSecond < 1) {
this.fractionalSecond = data.fractionalSecond;
} else {
throw new Error('Invalid fractional second [' + data.fractionalSecond + '].');
}
} else {
this.fractionalSecond = NaN;
}
// Timezone
if (Jsonix.Util.Type.exists(data.timezone)) {
if (Jsonix.Util.Type.isNaN(data.timezone)) {
this.timezone = NaN;
} else {
Jsonix.Util.Ensure.ensureInteger(data.timezone);
if (data.timezone >= -1440 && data.timezone < 1440) {
this.timezone = data.timezone;
} else {
throw new Error('Invalid timezone [' + data.timezone + '].');
}
}
} else {
this.timezone = NaN;
}
},
CLASS_NAME : "Jsonix.XML.Calendar"
});
Jsonix.XML.Calendar.fromObject = function(object) {
Jsonix.Util.Ensure.ensureObject(object);
if (Jsonix.Util.Type.isString(object.CLASS_NAME) && object.CLASS_NAME === 'Jsonix.XML.Calendar') {
return object;
}
return new Jsonix.XML.Calendar(object);
};
© 2015 - 2024 Weber Informatics LLC | Privacy Policy