Advertisement
AceScottie

fix_date.gs

Jan 8th, 2020
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function test_dobf1(){
  2.  
  3.   var dob = "10/7/08";
  4.  
  5.   Logger.log(fix_datex(dob.split("/")));
  6. }
  7.  
  8. function fix_datex(dataarr){
  9.   var new_arr = [0, 0, 0];
  10.   try{
  11.     var day = parseInt(dataarr[0]);
  12.     if(day < 10){
  13.       day = "0"+String(day);
  14.       new_arr[0] = day
  15.     }else{
  16.       new_arr[0] = day;
  17.     }
  18.   }catch(e){
  19.     Logger.log("not a day");
  20.     Logger.log(e);
  21.     return false;
  22.   }
  23.  
  24.   try{
  25.     var month = parseInt(dataarr[1]);
  26.     if(month < 10){
  27.       month = "0"+String(month);
  28.       new_arr[1] = month
  29.     }else{
  30.       new_arr[1] = month;
  31.     }
  32.   }catch(e){
  33.     Logger.log("not a month");
  34.     Logger.log(e);
  35.     return false;
  36.   }
  37.   try{
  38.     Logger.log("Initial Year : -"+dataarr[2]+"-");
  39.     var year = parseInt(dataarr[2]);
  40.     Logger.log("Initial Parsed Year : "+year);
  41.     if(year < 1900){
  42.       Logger.log("Year Needs fixing");
  43.       if(year < 30){
  44.         Logger.log("Year Needs to be 2000+");
  45.         if(year < 10){
  46.           Logger.log("Year below 10");
  47.           year = "0"+String(year);
  48.         }
  49.         year = "20"+String(year);
  50.         Logger.log("Year fixed to: "+year);
  51.         new_arr[2] = year
  52.       }else{
  53.         year = "19"+String(year);
  54.         new_arr[2] = year
  55.       }
  56.     }else{
  57.       new_arr[2] = year;
  58.     }
  59.   }catch(e){
  60.     Logger.log("not a year");
  61.     Logger.log(e);
  62.     return false;
  63.   }
  64.   Logger.log("dob fixed")
  65.   return new_arr[0]+"/"+new_arr[1]+"/"+new_arr[2];
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement