la-haute-societe / craft-elasticsearch

Bring the power of Elasticsearch to your Craft CMS projects
Other
18 stars 14 forks source link

Wrong date/time when you search #16

Closed vviacheslavv closed 2 years ago

vviacheslavv commented 3 years ago

Hi

There is an issue with date/time that is used to compare with postDate. At this line https://github.com/la-haute-societe/craft-elasticsearch/blob/master/src/records/ElasticsearchRecord.php#L424 $currentTimeDb = Db::prepareDateForDb(new \DateTime());

prepareDateForDb method switch your date/time to UTC timezone and because of this user wouldn't see new created items. In my case new \DateTime() shows object(DateTime)#1496 (3) { ["date"]=> string(26) "2021-04-09 12:46:34.850212" ["timezone_type"]=> int(3) ["timezone"]=> string(11) "Europe/Oslo" }

but after prepare prepareDateForDb method, this variable $currentTimeDb became 2021-04-09 10:46:34

So if i'll create some entry it'll be available for search only after 2hours.