I checked the Daml docs for Date.
I can’t find what would instantiate the current date.
I’m using this in a scenario for which I have a defined model that specifies as part of the set of fields (“with s”) for the model class
I’m also not getting what I would expect to be the intellisense help from VSCode i.e. I have DA.Date imported which VS Code is not complaining about and yet its not picking up “Date” and thus I can’t readily find static side instance creation api etc, not that I see what I need in the docs
e.g. I have tried this , which doesn’t work
1 Like
Hi @amiracam, take a look at a related question on this.
Basically it boils down to using getTime
and extracting the date from taht new Date ()
is Java syntax and not valid Daml. You also cannot do this at the top-level, so you have to move it in the do-block. Putting things together, your example could be something like this:
repo_test_1 =
scenario do
jpm <- getParty "JPM"
fed <- getParty " FED"
nowTime <- getTime
let nowDate = toDateUTC nowTime
submit jpm do
create Repo with
owner = jpm
regulator = fed
par = 1.5
cusip = "9999999"
trateDate = nowDate
Lastly, I recommend to use Daml Script instead of scenarios for all new projects. Your example translates to Daml Script with minimal changes:
repo_test_1 =
script do
jpm <- allocateParty "JPM"
fed <- allocateParty " FED"
nowTime <- getTime
let nowDate = toDateUTC nowTime
submit jpm do
createCmd Repo with
owner = jpm
regulator = fed
par = 1.5
cusip = "9999999"
trateDate = nowDate
2 Likes
k, now that i’m doing all “script”
it compiles but I get a strange bug namely what I expected to me “Date now” shows up as Epoch ?
So why ?
and again how can I get the current timestamp so that I can extract the current day ?
thanks
Thank you @cocreature this was a great tip
1 Like
Daml Studio runs in static time mode, meaning it starts at unix epoch and time only advances if you call pass
or setTime
. So in your example, nothing changes the time so you get the unix epoch.
Real ledgers usually run in wallclock mode where getTime
will provide you with the current time and time will advance automatically. Some ledgers, most notably sandbox also provide a --static-time
option which causes the ledger to run in the same static time mode that you get in Daml Studio.
1 Like
ok, thanks, but then what’s the significance of specifying “wall clock time” in the daml.yaml ?
I’ll assume that only controls the sandbox ledger i.e. the generated dar ?
1 Like
Exactly, the --wallclock-time
option is only for Sandbox.
1 Like