hi,

welcome to the forum and thanks for reaching us out. Thanks for the question and the clarity of it.

The issue here is that you are changing the Time value of the keys but not their indexes.
One function that could help you is SortKeysByTime but as you can see, it is marked as private. I am not sure why it is marked private here. There might have some cases where this function will not give you the correct result. you could create your own algorithm to sort those keys.

Another solution could be to delete those keys and re-insert them, they will be sorted as you insert them.

Cheers,
Manuel