I tried to reproduce the issue, but everything worked on my side. Could you double-check that the correct library is added? Just a quick reminder: the returned moment.js object needs to be converted into a Datetime data type, which you can do by calling .toJSON().
I used the Moment.js package, not Moment Timezone since it is Deprecated.
When using Moment.js I ran into several problems like the one above. All of these failed:
moment.min()
moment.max()
moment.tz()
In the function editor, it looks like all these functions exist. However, running the function fails with the error “moment. (…) is not a function”
I double-checked how moment works inside Appfarm Create functions, and here’s the key point:
When you call moment(...) in a function, the App Time Zone is applied automatically. That means you don’t need (and can’t) call .tz(...) yourself.
There was a short period (around version 113, earlier this year) where .tz(...) looked like it worked, but that was actually a bug. It’s not supported anymore.
Still have some questions. First why do you need .toJSON() ? Im not using it anywhere and the solution seems to work just fine. See the relevant parts of the code below:
We recommend using .toJSON() as outlined in the documentation to ensure the value is converted to the correct data type. While it may sometimes work without it, as you mentioned, skipping it can lead to issues. For example, in the min/max case, omitting .toJSON() results in this type of error:
To add to this, toJSON() is only required when returning a Moment value from a function. This is to ensure that the output of the function is a primitive value and not an object.