calculate time difference correctly