Just leaving a note in case anyone runs into this post, as it had me puzzled for a bit...
If you're using LFForm.getFieldValues to get the value from a date time field, it seems like they return two different objects based on whether the form is readonly or not.
live form
{dateStr: '29/06/2023', timeStr: '09:00 AM', momentObj: '2023-06-28T23:00:00.000Z'}
read only (ie. monitor page/repository/email task)
{dateStr: '29/06/2023', timeStr: '09:00 AM', dateTimeObj: '2023-06-28T23:00:00.000Z'}
Not sure if there are any others that we need to keep an eye out on, but this snippet seems to work nicely when converting it into a JavaScript date object:
const d = form.readonly ? new Date(validUntil.dateTimeObj) : new Date(validUntil.momentObj)