Methods

  • BrainJS: u.method()
  • BrainXML: <u>method()</u>
function User( ) {
this.getTimedTopic = function(expiration) {
  if(!this.timedTopic) {
    return "";
  }
  var now = Math.round(new Date().getTime()/1000);
  if(!expiration) {
    expiration = 300;
  }
  if(this.timedTopic.time < (now - expiration)) {
    this.timedTopic = null;
    return "";
  }
  this.timedTopic.time = now;
  return this.timedTopic.topic;
};
this.getTimestamp = function( ) {
  return Math.round(new Date().getTime()/1000);
};
this.getTimeZoneOffset = function( ) {
  
     var offset = '0';
     if (this.device.timezoneoffset){
       offset = this.device.timezoneoffset;
     }
     return offset;
  
};
this.getTitleForName = function( ) {
    
     switch (this.gender) {
       case 'male':
         return 'Mr.';
       case 'female': 
         if (this.marital == 'married') {          
           return 'Mrs.';
         }
         else if (parseInt(this.age, 10) < 18) {
           return 'Miss.';
         }
         else {
           return 'Ms.';
         }
         break;
       default:
         return '';
     }
  
};
this.getTitleNoName = function( ) {
  
     switch (this.gender) {
       case 'male':
         return 'Sir';
       case 'female':
         return 'Madam';
       default:
         return '';
     }
  
};
this.getUserName = function( ) {
     if (this.name) {
       return this.ucwords(this.name);
     }
     if(this.input && this.input.lang == 'sc') {
        return '朋友';
     }
     return 'my friend';    
  
};
this.getWeekday = function( ) {
  var now = new Date().getTime();
  var dateInTimezone;
  var week;
  
  if(this.input.lang == "sc") {
  	dateInTimezone = new Date(now + 480 * 60000);
  	if(dateInTimezone.getDay()===0)          week="星期日" 
  	if(dateInTimezone.getDay()===1)          week="星期一" 
  	if(dateInTimezone.getDay()===2)          week="星期二" 
  	if(dateInTimezone.getDay()===3)          week="星期三" 
  	if(dateInTimezone.getDay()===4)          week="星期四" 
  	if(dateInTimezone.getDay()===5)          week="星期五" 
  	if(dateInTimezone.getDay()===6)          week="星期六" 
  } else {
  	dateInTimezone = new Date(now);
  	if(dateInTimezone.getDay()===0)          week="Sunday" 
  	if(dateInTimezone.getDay()===1)          week="Monday" 
  	if(dateInTimezone.getDay()===2)          week="Tuesday" 
  	if(dateInTimezone.getDay()===3)          week="Wednesday" 
  	if(dateInTimezone.getDay()===4)          week="Thursday" 
  	if(dateInTimezone.getDay()===5)          week="Friday" 
  	if(dateInTimezone.getDay()===6)          week="Saturday" 
  }
  return week;
};
this.getYearsAfter = function(yearsNum) {
    var d=new Date();
    var y=d.getFullYear()+yearsNum;
    
    return y;
};
this.getYearsBefore = function(yearsNum) {
    var d=new Date();
    var y=d.getFullYear()-yearsNum;
    return y;
  
};
this.getZodiacSign = function( ) {
  
     if (!this.birth.date || !this.birth.month) {
       return false;
     }    
     if (this.birth.month === '' ||
         this.birth.date === '' ) {
       return false;
     }    
     return zodiacSign(parseInt(this.birth.date,10), parseInt(this.birth.month,10));
  
};

页面