Issue with SugarDateTime::createFromFormat() function

Backstory: After fighting for over 3 weeks to get the API calls working on our SuiteCRMv7.10.14/Windows/IIS/MSSQL setup and continually running into non-stop issues I gave up on accessing it on the Windows platform.

I then created a test Ubuntu/Apache2/MySQL VM with 7.11.10 and the API calls worked correctly on my first call so I was excited and decided to migrate the whole thing to a Ubuntu/Apache2/MySQL VM as well as upgrade SuiteCRM to the current 7.11.10 version.

Data migration was pretty straight forward using the MySQL workbench data migration tool, though I did run into some issues with the converted character sets not being utf8 and instead being some Latin charset as well as some fields that were not converted to the same field type as var defs was expecting but that was easy enough to address.

Once everything was migrated and looked good I set up the cron job and proceeded to test the Marketing Email Campaign. When I got to the page in the wizard where you can schedule the date and time for the email campaign to begin emailing it wouldn’t save my start date and kept telling me “Missing Required Field Start Date”. After double-checking my date_start field in the email_marketing database(because of the data migration from mssql), my php.ini timezone settings, user profile time and timezone settings everthing looked right so then I began logging and debugging the EmailMarketing module attempting to find what the issue was.

I found that the bean’s date_start value was being lost after a call to the SugarBean’s check_date_relationships_load() function.

After further logging, I found that the call to parent::createFromFormat() in the SugarDateTime.php createFromFormat() function was returning false.

This is the code line in SurgarDateTime.php

$d = parent::createFromFormat($format, $time, $timezone);

These are the logged variable values:

$format = 'Y-m-d H:i:s'
$time = '2020-02-12 18:00:00.000000'
$timezone = 'UTC'

I rolled this up into a test php and even there I can’t get it to return a date, any ideas?
I have to be missing something somewhere cause this works in my prior test VM and even works in my windows vm…

Have you tried running any of the JS rebuild or repair commands? If no try running the following from the admin repair menu;

  1. Quick Repair and Rebuild
  2. Rebuild Minified JS Files
  3. Rebuild JS Grouping Files

Then test your issue again and let me know how it goes!

Unfortunately those were the first things I had tried…

Can you go into the createFromFormat function and see exactly where it fails?

Since the SugarDateTime class extends the PHP DateTime class itself

class SugarDateTime extends DateTime

and in the call

$d = parent::createFromFormat($format, $time, $timezone);

it is calling the parent of the SugarDateTime class probably not…

Ah right, parent. Sorry.

It seems to me that any of these two should work:

Remove the microseconds from time:

$format = 'Y-m-d H:i:s'
$time = '2020-02-12 18:00:00'

Or add microseconds to format:

$format = 'Y-m-d H:i:s.u'
$time = '2020-02-12 18:00:00.000000'

But I can see why it doesn’t work the way it is. So the bug is a bit before, when it is setting up those variables.

Documentation:

https://www.php.net/manual/en/datetime.createfromformat.php

1 Like

That makes sense and you are probably right and it is a bug earlier up the stack when setting up the format or the value. Thanks for the information.