Lua os.date() defies Lua 5.2 Reference Manual

For Lua blocks, it’s important to be able to construct DateTime strings in ISO 8601 format to use with my.farm.bot REST API methods.

This sample Lua shows my problem. Any help or hints gratefully accepted :slight_smile:

now = os.time()
now_date = os.date()

soon = 600 + math.ceil(now)          -- now +10 minutes

-- Try to create a future date string ISO 8601 -style
-- -- this does NOT work 
soon_date = os.date('%FT%TZ', soon)

send_message(
  'success',
  'now '..tostring(now)..', soon '..tostring(soon),
  {'toast'}
  )
send_message(
  'warn',
  'now_date '..now_date..', soon_date '..soon_date,
  {'toast'}
  )

@jsimmonds This is a good point. I will add it to my TODO list. You might want to bring this up to the luerl folks also.

In our case, we will probably just patch ontop of os.date() and re-implement the function to work. Either that, or we can create our own helper that uses a different name, such as json.date(). :thinking:

1 Like

Thanks @RickCarlino.

Seems Connor already notified Robert Virding via this luerl issue ( still open ).
I might offer Robert a pointer to the official Lua manual :slight_smile: which states:

If format is not "*t", then date returns the date as a string,
formatted according to the same rules as the ISO C function strftime.
1 Like