Time Service returns UNIMPLEMENTED: Method not found: com.daml.ledger.api.v1.testing.TimeService/GetTime

Using java bindings and daml start i get UNIMPLEMENTED: Method not found: com.daml.ledger.api.v1.testing.TimeService/GetTime when calling ledgerClient.timeClient.getTime()

based on Can't fetch the ledger time from DAML ledger through the JSON API - Stack Overflow I see that it should not be available when in sandbox? But this appears to be older as it indicates the time service would be activated.

If time service is not available in sandbox, is there config that can be detected through the ledger api for a ledger being in sandbox mode / which services are available / not available based on the config?

Thanks

The time service is only intended for testing and is only available in static time mode. You can turn on static time via daml sandbox --static-time. Take a look at Is it possible to start Canton Sandbox in static time mode, specified in the `daml.yaml` file? - #2 by cocreature for some caveats if you try to do this in daml start.

As for detecting whether you’re in static time mode, you can catch the unimplemented exception. Navigator does something like this here daml/PlatformStore.scala at f4211b709ffd31453ed94b99538c6434647f520d · digital-asset/daml · GitHub.

Maybe worth adding: If you’re just interested in getting the time and not in setting it, just get the utc time on the client side and make sure both your client & your ledger have ntp enabled.

@cocreature thank you