This forum has been archived. Please start a new discussion on GitHub.

Using IceUtil::Time in a Slice definition

Hi all,

I am trying to design an interface that needs to transfer high-precision time information as parameters and/or return values, and the IceUtil::Time would be quite suitable for this purpose. I have two questions:

(1) Is this a good idea? The type is defined in the "C++ utility" part of the manual, and I can only assume that it's not available from other languages.

(2) If I wanted to use the IceUtil::Time type, how would I do it, i.e., what would be the proper way to include the "IceUtil" module declaration into my ice file?

Best regards, Sidney


  • mes
    mes California
    Hi Sidney,

    It's not possible to include language-specific types in your Slice definitions. Instead, you will need to define an equivalent type in Slice. It's possible that Slice's long type (a signed 64-bit integer) would be sufficient for your purposes, and the IceUtil::Time class provides static methods that convert long values into IceUtil::Time objects.

    For example:
    Ice::Long v = someProxy->getTime(); // get time in milliseconds
    IceUtil::Time t = IceUtil::Time::milliSeconds(v);
    Of course, if these time values will be used in multiple programming languages, you'll have to ensure that you handle them portably (i.e., use the same epoch across all languages, or convert the values when necessary, and so on).

    Hope that helps,
  • Ok, that's clear -- I'll define my own high-resolution time type, then.

    Thanks, Sidney