improve time format logic