Search code examples
javatimestarteam

Calculate client-server time difference in Borland Starteam server 8


Problem. I need a way to find Starteam server time through Starteam Java SDK 8.0. Version of server is 8.0.172 so method Server.getCurrentTime() is not available since it was added only in server version 9.0.

Motivation. My application needs to use views at specific dates. So if there's some difference in system time between client (where the app is running) and server then obtained views are not accurate. In the worst case the client's requested date is in the future for server so the operation results in exception.


Solution

  • After some investigation I haven't found any cleaner solution than using a temporary item. My app requests the item's time of creation and compares it with local time. Here's the method I use to get server time:

    public Date getCurrentServerTime() {
        Folder rootFolder = project.getDefaultView().getRootFolder();
    
        Topic newItem = (Topic) Item.createItem(project.getTypeNames().TOPIC, rootFolder);
        newItem.update();
        newItem.remove();
        newItem.update();
        return newItem.getCreatedTime().createDate();
    }