0

Is there anything wrong with sorting local time by UTC timestamp?

I store time as Unix timestamps in UTC and output local time in a pretty complex format that is user friendly but would be a nightmare to sort. So I decided to sort it by UTC time.

Here is an exaggerated example:

<td data-utc-timestamp="1514372400">
    <b>7:00<i>PM</i></b> December 27th, 
    beautiful Wednesday evening in Shanghai,
    the year of the Rooster, 2017 :D
</td>

Seems perfectly fine to me to sort this by UTC timestamp, but I am not an expert in the field so I am having doubts.

Is there any scenario where an array of UTC times will have a different order than the same array of UTC times converted to local times?

Arthur Tarasov
  • 3,517
  • 9
  • 45
  • 57

1 Answers1

0

UTC time is constant (i.e. there is no day light savings time or time changes ever). The only time that an issue is possible is when your local time observes DST. The sorting during the transition might mess you up. But as long as you handle that properly (i.e. your time codes are ordered correctly), UTC time and local time will mesh.

This answer has more details: Does UTC observe daylight saving time?

dnishiyama
  • 101
  • 1
  • 4
  • So then if something happens during one hour of transition from DST back regular time, then it will appear to have happened in the future if sorted by UTC, but put past events after the events that haven't happened yet if sorted by local time? Mind-boggling... – Arthur Tarasov Mar 02 '18 at 06:00