Error using server Parser - toUTCTime

Wappler Version : 3.4.0 (but happened in previous version too)
Operating System : Win10, NodeJS / Docker project

Expected behavior

When you convert a date or time to UTC or Other format options on the server action side, it should convert to the chosen format

Actual behavior

What actually happens?

It does not convert the date/time and the server action (a database update in this case) fails.

Error message:

{status: "500",…}
message: "Parser Error: Formatter "toUTCTime" does not exist, expression {{$_POST.start.toUTCTime()}}"
stack: "Error: Parser Error: Formatter "toUTCTime" does not exist, expression {{$_POST.start.toUTCTime()}}↵    at /opt/node_app/lib/core/parser.js:694:27↵    at /opt/node_app/lib/core/parser.js:661:25↵    at parser (/opt/node_app/lib/core/parser.js:352:19)↵    at parseValue (/opt/node_app/lib/core/parser.js:725:24)↵    at parseValue (/opt/node_app/lib/core/parser.js:716:26)↵    at parseValue (/opt/node_app/lib/core/parser.js:716:26)↵    at Object.parseValue (/opt/node_app/lib/core/parser.js:716:26)↵    at App.parseSQL (/opt/node_app/lib/core/app.js:348:23)↵    at App.update (/opt/node_app/lib/modules/dbupdater.js:38:26)↵    at App._exec (/opt/node_app/lib/core/app.js:255:57)"
status: "500"

This is an image of the server action step. Its a simple UPDATE. The START and END fields in this case are TIME inputs. I have also tried with date, datetime and also the DMX date/time picker inputs. Anytime the formatter is used it fails and throws the above error

How to reproduce

As above. Set up a DB action, such as a DB UPDATE and use a date or time input that uses the toUTCTime() formatter or the toLocalTime() formatter.

The formatters are not missing and seem to work for me.

Do you have only problems with the date specific formatters? Please check the lib/formatters folder if the file date.js exists. Open the file and check if the methods toLocalTime and toUTCTime in it.

It was just those two formatters I’d tried. I’ll check what you’ve mentioned and see what I find.

Hey @patrick. I was able to check this, and it looks like those formatters do not exist
in the file. The only one there is toTimestamp.

Here is an image, condensed for easier viewing.

I did update to latest version… something is missing here though right?

When looking in the windows folder structure, the last modified date for that file is 26/07/2020.

image

I believe Wappler only updates files depending on the file date, the date.js is from 22/07/2020. Not sure why your file is from 26/07/2020, but that is probably the cause that it wasn’t updated. I’m not sure if new files are copied again when you remove the lib folder, perhaps @George knows that.

Here the up-to-date file: date.zip (836 Bytes)

Thanks @patrick. I’ll update this tomorrow morning. Would there be any chance the other formatters are missing functions or hadn’t been updated? Any way of telling without waiting untill something doesn’t work?

Try to rename the lib folder and then start Wappler with that project and see if it recreates the lib folder, it should then have all the latest versions.

Thanks for this. This tip worked. I created a lib - Copy, restarted Wappler and it created a new lib folder.

Based on Wappler detecting which files were new/different, the date.js file and the util.js file had been updated.

All good now.

Hey,
I am getting what looks to be the same error:

  1. code: 0
  2. file: “/var/www/html/dmxConnectLib/lib/core/Parser.php”
  3. line: 413
  4. message: “Formatter toLocalTime does not exist.”
  5. trace: “#0 /var/www/html/dmxConnectLib/lib/core/Parser.php(364): lib\core\Parser->objectMember(Object(Closure))↵#1 /var/www/html/dmxConnectLib/lib/core/Parser.php(306): lib\core\Parser->primary()↵#2 /var/www/html/dmxConnectLib/lib/core/Parser.php(283): lib\core\Parser->group()↵#3 /var/www/html/dmxConnectLib/lib/core/Parser.php(263): lib\core\Parser->unary()↵#4 /var/www/html/dmxConnectLib/lib/core/Parser.php(253): lib\core\Parser->multiplicative()↵#5 /var/www/html/dmxConnectLib/lib/core/Parser.php(243): lib\core\Parser->addictive()↵#6 /var/www/html/dmxConnectLib/lib/core/Parser.php(233): lib\core\Parser->bitwiseShift()↵#7 /var/www/html/dmxConnectLib/lib/core/Parser.php(223): lib\core\Parser->relational()↵#8 /var/www/html/dmxConnectLib/lib/core/Parser.php(213): lib\core\Parser->equality()↵#9 /var/www/html/dmxConnectLib/lib/core/Parser.php(203): lib\core\Parser->bitwiseAnd()↵#10 /var/www/html/dmxConnectLib/lib/core/Parser.php(193): lib\core\Parser->bitwiseXor()↵#11 /var/www/html/dmxConnectLib/lib/core/Parser.php(183): lib\core\Parser->bitwiseOr()↵#12 /var/www/html/dmxConnectLib/lib/core/Parser.php(171): lib\core\Parser->logicalAnd()↵#13 /var/www/html/dmxConnectLib/lib/core/Parser.php(155): lib\core\Parser->logicalOr()↵#14 /var/www/html/dmxConnectLib/lib/core/Parser.php(151): lib\core\Parser->conditional()↵#15 /var/www/html/dmxConnectLib/lib/core/Parser.php(96): lib\core\Parser->expression()↵#16 /var/www/html/dmxConnectLib/lib/App.php(222): lib\core\Parser->parse(‘NOW.toLocalTime…’, NULL)↵#17 /var/www/html/dmxConnectLib/lib/App.php(207): lib\App->parseObject(’{{NOW.toLocalTi…’, NULL)↵#18 /var/www/html/dmxConnectLib/lib/App.php(213): lib\App->parseObject(Object(stdClass), NULL)↵#19 /var/www/html/dmxConnectLib/lib/App.php(207): lib\App->parseObject(Array, NULL)↵#20 /var/www/html/dmxConnectLib/lib/App.php(207): lib\App->parseObject(Object(stdClass), NULL)↵#21 /var/www/html/dmxConnectLib/modules/dbupdater.php(179): lib\App->parseObject(Object(stdClass))↵#22 /var/www/html/dmxConnectLib/modules/dbupdater.php(16): modules\dbupdater->parseOptions(Object(stdClass))↵#23 /var/www/html/dmxConnectLib/lib/App.php(174): modules\dbupdater->insert(Object(stdClass), ‘insert_billing_…’)↵#24 /var/www/html/dmxConnectLib/lib/App.php(138): lib\App->execSteps(Object(stdClass))↵#25 /var/www/html/dmxConnectLib/lib/App.php(108): lib\App->execSteps(Array)↵#26 /var/www/html/dmxConnectLib/lib/App.php(73): lib\App->exec(Object(stdClass))↵#27 /var/www/html/dmxConnect/api/billing/update_billing_note.php(8): lib\App->define(Object(stdClass))↵#28 {main}”

I’ve updated date.js with the file included, however I am getting the same error.

When trying to rename the old lib folder, a new folder is not re-generated.

The topic is about NodeJS server model, while your error is showing PHP files, which means you are using PHP server model.
Probably you have a different issue. Please explain where exactly are you trying to use this formatter when this error appears.

Thanks for getting back to me @Teodor.

Sorry. I didn’t see this error was a NodeJS issue and you’re right I am using PHP.

The error occurs when trying to do the following in server connect:

I am trying to convert server time to local time since in this case I need the actual timestamp since I need to display for users in the front end.

For what it’s worth, I find it more flexible to store all datetimes in the db as UTC, and then format to timezone on the front end (since that is where the time zone is determined). This allows for people to set their time zone, as well as move across different time zones, and just adds some consistency to things across the datetime coding world.

1 Like

Makes perfect sense and is a better more consistent approach.

This however beckons the question of how to show local time on the front end. I don’t see any functions to convert datetime to local datetime. I could subtract the hours to arrive at my result, however employing a local time function would be ideal.

The toLocalTime formatter should actually not be available for PHP (in the UI), it is only available for NodeJS.

What exactly are you trying to achieve?

I am recording a user’s note on a record with a timestamp (auto generated by the DB).

Similar to how this forum records your statement from 2 minutes ago. Except, my use case is more simple in that I just want to show the timestamp at which the user made their comment.

So user Teodor said “abc” at 4:22 pm (local time). Right now, the datetime value is stored in UTC. So I just want to show the datetime timestamp in local time.