How can I get the actual time when running scrips on VisualStudio Code

G-d willing

Hello,
I need to design a contract (Agreement) that will need to be created only between time limits (it has 2 properties beginTime & endTime).
I have another contract (Proposal) that one of its choices is creating the Agreement. So, inside the choice I added validation for the time limits.

          time <- getTime
          let currentTime = toDateUTC time
          assertMsg "The proposal is out of the time limit" (currentTime >= info.registrationBegins && currentTime <= info.registrationBegins)

The problem I am having is when I run the script inside VisualStudio Code and also use daml test, it fails since the getTime function returns 1970-01-01.
How can I make sure that the date & time will be correct?
Calling the setTime will help with the Visual Studio, but won’t be enough due to daml test.
How can I overcome this to make sure my tests will work properly?

Thanks,

Can you expand on what you mean by that? daml test should also start at 1970-01-01 and advance time only via setTime just like Daml Studio.

From the documentation:

setTime
: HasCallStack => Time -> Script ()

Set the time via the time service.

This is only supported in static time mode when running over the gRPC API and in Daml Studio.

Note that the ledger time service does not support going backwards in time. However, you can go back in time in Daml Studio.

Consider 2 templates: Proposal and Agreement and the agreement should be created if the current date & time is between the proposal definition. How can I test it correctly considering that the getTime returns 1970-01-01?

Thanks for pointing that out. The docs are misleading here. It is definitely supported in daml test.

1 Like