Time Zone error JS

hi team

On our Cometchat module, mainly IOS and APK, under the contact name it has “Last seen today 2:31am” But this time zone is wrong. Actually we are in Sydney and its 4pm, but its showing as 2:30am … My dev said thsi is coming from server and he doesn’t know how to change this, do you have any idea how to resolve?

Is there any solution to this?

Hello @flipspot,

Can you please elaborate more on the issue? The user for whom you are seeing last seen as 2:31 am, from where did the user login/logout? Is that user also from Sydney? Please provide us with some more details so that we can help you solve this issue.

CometChat server stores a UNIX timestamp. It has nothing to do with timezone. In your front end when you convert a timestamp into human readable date it converts the timestamp based on the local timezone.

Warm Regards,

CometChat Pro
Mayur Bhandari

1 Like

We are able to collect the timestamp but we are having trouble converting it to the format of “Last seen today, 3:00PM” for example.

Right now we can just collect the last time user was online, but not in the format we want, like on Whatsapp or Facebook. How do we convert this? @mayur.bhandari

Please refer to https://www.toptal.com/software/definitive-guide-to-datetime-manipulation

Hi guys @anant.garg @mayur.bhandari

We have managed to ‘manipulate’ the timestamp however we have noticed one bug across all our platforms (ios/js/apk) which is causing the last logged in time to be incorrect. After the user logs off on any platform, the user is still stuck on online and is not refreshing. We have checked the code but we are not sure if this is an error from cometchat’s end.

Here is the code snippet:

@Override
public void fecthUsers(ArrayList userIdList) {

    if (usersRequest == null) {
        usersRequest = new UsersRequest.UsersRequestBuilder().setLimit(userListLimit).build();

        //Log.e(TAG, "userListSize" + String.valueOf(userIdList));
        usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
            @Override
            public void onSuccess(List<User> users1) {
               // Log.d(TAG, "onSuccess: ");

                //Logger.error("cometchat_userList", users1.toString());
                Logger.error("backend_userList", userIdList.toString());
                List<User> users = new ArrayList<>();
                

                for (int i = 0; i < users1.size(); i++) {
                    users.add(users1.get(i));
                    listArray.addAll(users);
                }


                if (users.size() > 0) {
                    count = 0;
                    lastmessage = new ArrayList<>();
                    limit = 1;
                    UserConversation(users.get(count).getUid(), users);
                }

            }

            @Override
            public void onError(CometChatException e) {

            }
        });

    } else {
        usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {
            @Override
            public void onSuccess(List<User> users1) {
                if (users1 != null && users1.size() != 0) {
                    Logger.error("old user list resquest obj");
                    Logger.error("userList", " " + users1.size());

                    List<User> users = new ArrayList<>();
                    

                    for (int i = 0; i < users1.size(); i++) {
                        users.add(users1.get(i));
                        listArray.addAll(users);
                    }

                    if (users.size() > 0) {
                        count = 0;
                        lastmessage = new ArrayList<>();
                        limit = 1;
                        UserConversation(users.get(count).getUid(), users);
                    }
                }
            }

            @Override
            public void onError(CometChatException e) {
                Log.d(TAG, "onError: ");
                e.getMessage();
            }

        });

    }
}

Can you please confirm if we are doing anything wrong, or if this a cometchat server issue? I will wait for your prompt response, many thanks in advance.

Hi @flipspot ,

The code snippet you shared is used to fetch UserList.
We suggest you to please check for UserListener which will help you to check real-time presence of user’s.

To learn more about user presence please check below documentation link.

We are using the listeners to fetch the last seen activity, however its not updating in real-time. E.g as the chat is going and user is chatting, it’s not updating in real-time, you need to manually refresh the page.

Is there any API or guide for this? @darshan.bhanushali

Hey,

First off, kudos to your dev for being honest about not knowing how to fix it. Admitting that is a mark of a good developer! But fear not, I might have a suggestion to tackle this quirk.

It seems like the issue lies within the server’s configuration. If you have access to the server settings, try checking the time zone configuration there. Make sure it’s set to the right time zone, like “Australia/Sydney” or “UTC+10.” Sometimes, the server’s default setting can mess things up…

If you’re not in control of the server, consider reaching out to Cometchat’s support team. They might have encountered this before and could provide you with a nifty fix. Plus, they could improve their system if it’s a widespread concern.

As for my experience, I once encountered a similar time warp problem with a website I was developing for a project at Andersen. It turned out to be a mix of server and client-side settings. So, don’t forget to double-check the client’s time zone settings too, just in case!

Best of luck, dear author! I hope you can zap that time zone bug and enjoy smooth chats in sync with the Aussie clock. Remember, technology can be a bit wonky sometimes, but with a little patience and exploration, you’ll conquer it!