Custom Snippet Using getDate Does Not Retrieve Start Date

I have a simple custom snippet called PNL, used on ModX 2.8.3, that retrieves template variable values from resources specified with a date range.

The date range is specified with start and end date parameters, and each date is created with the getDate snippet.

Here is an example snippet call:

[[PNL? &date1=`[[!getDate? &offset=`first day of last month`]]` &date2=`[[!getDate? &offset=`last day of last month`]]`]]

This is the snippet:

$fdate = $modx->getOption('date1', $scriptProperties, '');
$ldate = $modx->getOption('date2', $scriptProperties, '');

/* Get all children of resource */

$docs = $modx->getCollection('modResource', array(
'parent' => 6, 
'deleted' => false,
'published' => true,
'publishedon:>=' => $fdate,
'publishedon:<=' => $ldate
));

/* get number of documents */
$count = count($docs);

/* initialize total PNL at 0 */
$totalPNL = 0;

foreach ($docs as $doc) {
     $pnl = $doc->getTVValue('pnl');
     $id[] = $doc->get('id');
     $totalPNL += $pnl;
}

return $totalPNL;

First thing - I’m not a developer, and have cobbled this together as best I could (so far). I’m sure you pros will see better ways to go about this…

The issue encountered is, using the call above as an example, all results are returned except for the actual ‘first day of last month’ (December 1st, for which a resource has been published and is viewable, etc.).

To Troubleshoot:
I printed $id(array) to verify the Dec 1 resource ID is not included.

This is hosted locally, and I checked the system timestamp with [!+nowdate:default=now:strtotime:date=%Y-%m-%d %H:%M].

I placed getDate calls into the test resource to ensure that they pass the correct dates to PNL.

I returned and converted the $fdate and $ldate Unix timestamps to ensure that these also are correct. They appear to be so.

Regarding timestamps, I do think that this may be the issue. I have, for instance, another PNL call like this:
[[PNL? &date1=[[!getDate? &offset=Monday last week]] &date2=[[!getDate? &offset=Saturday last week]]]]

If I use ‘Friday last week’ for date2, results for that date are not returned. I suspect that it is because the getDate timestamp is set for 08:00:00 GMT+0000, which is 00:00:00 PST (where I am located).

Perhaps the issue is the datetime stamp provided by getDate - I’m not sure. Any feedback is greatly appreciated.

Edit:
I converted 12-01-2022 00:00:00 to Unix and passed that value to the snippet, and the correct array of resource IDs is retrieved.

The datetime stamp passed by getDate provides the correct date. However, by refreshing the test resource. I can see that the embedded getDate calls changed each time, and randomly provide a different timestamp.

I think, you have to call PNL uncached, too

[[!PNL