Methods

  • BrainJS: u.method()
  • BrainXML: <u>method()</u>
function User( ) {
this.holidayToday = function( ) {
     var d = new Date();
     return holidayUS(d);
  
};
this.holidayUS = function(dt_date) {
     // check simple dates (month/date - no leading zeroes)
     var n_date = dt_date.getDate(),
     n_month = dt_date.getMonth() + 1;
     var s_date1 = n_month + '/' + n_date;
   
     switch (s_date1) {
       case '1/1':
         return "New Year's Day";
       case '6/14':
         return "Flag Day";
       case '7/4':
         return "Independence Day";
       case '11/11':
         return "Veterans Day";
       case '12/25':
         return "Christmas Day";    
     }
   
     // weekday from beginning of the month (month/num/day)
     var n_wday = dt_date.getDay(),
     n_wnum = Math.floor((n_date - 1) / 7) + 1;
     var s_date2 = n_month + '/' + n_wnum + '/' + n_wday;
   
     switch (s_date2){  
       case '1/3/1':
         return "Martin Luther King Day"; // third Monday in January
       case '2/3/1':
         return "Washington's Birthday"; // third Monday in February
       case '5/3/6':
         return "armed Forces Day"; // third Saturday in May
       case '9/1/1':
         return "Labor Day"; // first Monday in September
       case '10/2/1':
         return "Columbus Day"; // second Monday in October
       case '11/4/4':
         return "Thanksgiving Day"; // fourth Thursday in November
     }
   
     // weekday number from end of the month (month/num/day)
     var dt_temp = new Date (dt_date);
     dt_temp.setDate(1);
     dt_temp.setMonth(dt_temp.getMonth() + 1);
     dt_temp.setDate(dt_temp.getDate() - 1);
     n_wnum = Math.floor((dt_temp.getDate() - n_date - 1) / 7) + 1;
     var s_date3 = n_month + '/' + n_wnum + '/' + n_wday;
   
     if ( s_date3 == '5/1/1' // last Monday in May
     ) return "Memorial Day";
   
     // misc complex dates
     if (s_date1 == '1/20' && (((dt_date.getFullYear() - 1937) % 4) === 0)
     // January 20th every four years, starting in 1937.
     ) return "Inauguration Day";
   
     if (n_month == 11 && n_date >= 2 && n_date < 9 && n_wday == 2
     // Tuesday on or after November 2.
     ) return "Election Day";
   
     return '';
  
};
this.img = function(keyword, currentID) {
  
     if (keyword === undefined) {
       return 'acox imgError keywordMissed';
     }
     if (currentID === undefined) {
       currentID = 0;
     }
     var url = 'http://acobot.com/api/img/'+keyword+'/'+currentID;  
     return sraix(url);
  
};
this.imgRand = function(prev) {
  
     if (prev === undefined){
       prev = 0;
     }
     var url = 'http://acobot.com/api/img_rand/' + prev;
     return sraix(url);
  
};
this.imgur = function(keyword, offset) {
  
     var url;
     if (keyword == undefined) {
       url = 'http://acobot.com/api/imgur';  
     }
     else if (offset == undefined) {
       keyword = encodeURIComponent (keyword);  
       url = 'http://acobot.com/api/imgur/'+keyword;
     }
     else {
       url = 'http://acobot.com/api/imgur/'+keyword+'/'+offset;
     }
     return sraix(url);
  
};
this.init = function(app) {
  
     var offset = this.getTimeZoneOffset();
     var url = 'http://acobot.com/api/init/' + this.uid_key + '/' + offset;
     if (app !== undefined) {
       url = url + '/' + app;
     }
     return sraix(url);  
  
};
this.isBirthdayToday = function( ) {
  
     var d = new Date();
     if (d.getMonth()+1 == this.birth.month && d.getDate == this.birth.date){
       return true;
     }
     return false;
  
};
this.isChristmasToday = function( ) {
  
     if (this.getHolidayToday() == "Christmas Day"){
       return true;
     }
     return false;
  
};
this.isDate = function(text) {
  
     var timestamp = Date.parse(text);
     return isNaN(timestamp);
  
};
this.isEmpty = function(val) {
  
     return (typeof val != 'undefined' && val) ? false : true;
  
};

页面