I need to sort an array in react native without affecting the timestamp. I'm getting details from the backend with timestamp and I want to sort it. I have done the sorting part with first come first basis using the following code.
const members = out.game.gameMembers.map((elem) => {
return {
id: elem.userId._id,
profileImage: elem.userId.profileImage,
name: elem.userId.name,
status: elem.status,
position: elem.userId.position,
isDeleted: elem.userId.isDeleted,
createdAt: elem.createdAt,
updatedAt:elem.updatedAt
};
});
let sortedMembers = members.sort(function (x, y) {
// return x.updatedAt - y.updatedAt;
return new Date(x.updatedAt) - new Date(y.updatedAt);
});
Here I'm getting the sorted members and sorting it with respect to their timestamp. But the problem is the time zone. If a user 'A' is from Dubai and another user 'B' is from India, the time difference is around two and half hours.
For example user from India updated their profile status at 11:30 AM and after 10 minutes user from Dubai updated his status where the time is 10:00 AM. So at time of sorting then User from Dubai comes first which can't be happen. How exactly solve this issue and sort the details using timestamp first come first in basis. Additionally I'm getting timezone of both Dubai user and Indian user. Thank you