Time comparison - is it semantically correct to compare two timestamps like this?

Hi there,

Is it semantically correct to compare two timestamps like this:

compare_time(T1, T2) when T1 > T2;
greater;
compare_time(T1, T2) when T1 < T2;
lesser;
compare_time(_T1, _T2);
equal.

while both T1 and T2 are erlang:timestamp()?

Thanks
/Zab

Well, time is always problematic. If it comes to comparing two tuples generated via erlang:timestamp(), then yes. Erlang term order applies. Both are tuples, so their sizes are compared. Both are of equal size, so the respective elements are compared, where again Erlang term order applies. All elements are integers and their orders in both tuples is most significant to least significant. So in a nutshell, a larger timestamp tuple compares greater than a smaller timestamp tuple and vice versa, and equal timestamp tuples compare equal.

2 Likes