Hi,
I’m binding a PCF control to a field of type DateAndTime.DateAndTime which is defined in Dataverse as Time-Zone independent, i.e. everything is in UTC.
In order to rule out any date arithmetic inside the control, as a test I’ve built a control which simply copies one field to another (so you need 2 DateTime fields, both of which must be time-zone independent). When you run it, the fields end up with different values.
My ControlManifestInput.xml (with some boilerplate removed for brevity) looks like:
<property name="destinationDate" of-type="DateAndTime.DateAndTime" usage="bound" required="true" />
<property name="sourceDate" of-type="DateAndTime.DateAndTime" usage="input" required="true" />
And the guts of the class is:
private notifyOutputChanged: () => void;
private sourceDate: Date | null;
public init(…):{
this.notifyOutputChanged = notifyOutputChanged
}
public updateView(…):{
this.sourceDate = context.parameters.sourceDate.raw
this.notifyOutputChanged()
}
public getOutputs(): {
return { destinationDate: new Date(this.sourceDate!) }
}
Let’s say I set the source date to April 21 2023 9am UTC, the control is correctly called with a sourceDate value of 1682067600000. The control copies this to the destination date but PowerApps immediately calls updateView with destinationDate equal to 1682071200000 (which corresponds to 10am UTC on the same day). If you save the record from the screen these are the values that get persisted to the database.
Since the error is 1 hour and my current time zone (UK) is one hour away from UTC I tried setting my local time zone to Paris and sure enough the destinationDate instead gets set to 1682074800000 (which is 11am UTC on the same day – 2 hours from the input date).
So it seems that something in the PCF is trying to do some kind of time zone adjustment even though both dates are UTC, and even though JavaScript dates can’t hold Time Zone information.
Note this does not depend on the user’s PowerApps time zone setting or their Microsoft account time zone setting; just the local PC time zone setting (I have tried with both Firefox and Chrome on PC but not on other operating systems). I'm reluctant to put a workaround in my code because other environments might not have the same bug and then the control would produce the wrong result.