Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test_dobf1(){
- var dob = "10/7/08";
- Logger.log(fix_datex(dob.split("/")));
- }
- function fix_datex(dataarr){
- var new_arr = [0, 0, 0];
- try{
- var day = parseInt(dataarr[0]);
- if(day < 10){
- day = "0"+String(day);
- new_arr[0] = day
- }else{
- new_arr[0] = day;
- }
- }catch(e){
- Logger.log("not a day");
- Logger.log(e);
- return false;
- }
- try{
- var month = parseInt(dataarr[1]);
- if(month < 10){
- month = "0"+String(month);
- new_arr[1] = month
- }else{
- new_arr[1] = month;
- }
- }catch(e){
- Logger.log("not a month");
- Logger.log(e);
- return false;
- }
- try{
- Logger.log("Initial Year : -"+dataarr[2]+"-");
- var year = parseInt(dataarr[2]);
- Logger.log("Initial Parsed Year : "+year);
- if(year < 1900){
- Logger.log("Year Needs fixing");
- if(year < 30){
- Logger.log("Year Needs to be 2000+");
- if(year < 10){
- Logger.log("Year below 10");
- year = "0"+String(year);
- }
- year = "20"+String(year);
- Logger.log("Year fixed to: "+year);
- new_arr[2] = year
- }else{
- year = "19"+String(year);
- new_arr[2] = year
- }
- }else{
- new_arr[2] = year;
- }
- }catch(e){
- Logger.log("not a year");
- Logger.log(e);
- return false;
- }
- Logger.log("dob fixed")
- return new_arr[0]+"/"+new_arr[1]+"/"+new_arr[2];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement