
export function packTime( mytime ){
    if( mytime < 0) mytime = -mytime;
    let obj = {'v': mytime};
    let h =  parseInt(mytime / 3600);
    let m =  parseInt( (mytime %3600)/60);
    let s = mytime % 60;
    obj.h = h<10?"0"+h:h;
    obj.m = m<10?"0"+m:m;
    obj.s = s<10?"0"+s:s;
    return obj;
}

export function time2str( mt ){
    let  timestamp4 = new Date( mt*1000 );
    return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
}


export function timeinfo( mt ){
    let  timestamp4 = new Date( mt*1000 );
    return timestamp4.toTimeString().substr(0, 8);
}


export function getTime(){
    return parseInt( Date.now()/1000);
  }


export function saveExam( info, qustionList ){
  info.answers = qustionList
  localStorage.setItem( "@examData", JSON.stringify( info ))
}

export function delExam(  ){
  localStorage.removeItem("@examData" )
}


export function getExam(){
  let item =localStorage.getItem("@examData")
  try {
    if( item ) return JSON.parse( item  );
    return false
  } catch(e) {
    return false
  }
}

export function getSelect( answers ){
  if(!answers) return 0;
  let select = 0;
  if(answers>=0 && answers < 10 ) return answers
  answers = answers.filter(v=>{return v>0}).sort();
  for( let i =0; i < answers.length; i++){
    if(+answers[i]) select = (select*10 + answers[i]);
  }
  return select
}
