Jump to content

Can't getUnformatted for datetime fields


Matzn
 Share

Recommended Posts

Hi,

i have two date fields. One stores in unix timestamp (ratingDate) the other as a normal date (googlePageSpeedDate). Both have the same settings! How can I influence the saving?

The strange thing is that I can't get the unix timestamp by (Check is the FieldsetPage) $page->Check->getUnformatted('googlePageSpeedDate');

ProcessWire\FieldsetPage Object
(
    [id] => 9932
    [name] => for-page-1072
    [parent] => /admin_panel_page/repeaters/for-field-389/
    [template] => repeater_Check
    [name1067] => 
    [status1067] => 1
    [googlePageSpeedDate] => 2021-05-17 00:00:00
    [data] => Array
        (
            [name1067] => 
            [status1067] => 1
            [googlePageSpeedDate] => 2021-05-17 00:00:00
        )

)
ProcessWire\RepeaterPage Object
(
    [id] => 1137
    [name] => 1618998033-3988-1
    [parent] => /admin_panel_page/repeaters/for-field-312/for-page-1075/
    [template] => repeater_businessProvider
    [name1067] => 
    [status1067] => 1
    [isSocialMedia] => 0
    [businessProviderPage] => (Page) 1132
    [rating] => 4,6
    [ratingUsers] => 10
    [ratingDate] => 1621240175
    [urlTo] => https://maps.google.com/?cid=11132489695980159614
    [reviewUrl] => 
    [data] => Array
        (
            [name1067] => 
            [status1067] => 1
            [isSocialMedia] => 0
            [businessProviderPage] => ProcessWire\Page Object

 

Link to comment
Share on other sites

@wbmnfktr ic know this postes, but no way to get the unix timestamp by

$page->getUnformatted('yourDateField');

I also used it in several projects, but now the output must be set for date field to none. So i use this date field only as

$page->yourDateField;

I also don't understand why one field is save as unix and the other not (same settings).

Link to comment
Share on other sites

you must have some bug or other issue;

$page->getUnformatted('date_field'); always returns a unix timestamp.

All datetime fields are stored in the DB as datetime which is not unix timestamp (it is Y-m-d H:i:s), but that database value is converted to the unix timestamp for the unformatted value of a datetime field;

You can see this in the sleepValue and wakeupValue for the fieldtype, which converts it like this:

return is_int($value) ? date('Y-m-d H:i:s', $value) : '';

 

Link to comment
Share on other sites

@Macrura I have tested something. If add the date field to page or repeater page it works, but not to a fieldsetpage:

echo "\nFieldsetPage:\n";
echo $page->Check->ratingDate;
echo "\n";
echo $page->Check->getUnformatted("ratingDate");
echo "\nPage:\n";
echo $page->ratingDate;
echo "\n";
echo $page->getUnformatted("ratingDate");
echo "\nRepeaterPage:\n";
echo $page->About->businessProvider->first()->ratingDate;
echo "\n";
echo $page->About->businessProvider->first()->getUnformatted("ratingDate");

Live Result:

FieldsetPage:
19.05.2021
19.05.2021
Page:
19.05.2021
1621375200
RepeaterPage:
19.05.2021
1621429619

It's a bug or i can set somthing?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...