Date modified for nodes can sometimes be showing 1970 (null time value)

Created on 22 February 2023, over 1 year ago
Updated 26 July 2023, 11 months ago

Problem/Motivation

Noticed that dates came out as 1970 for some nodes on a site, not sure why but this patch resolves it, very simple patch.
environment has PHP 8.0.20, should be updated to 8.0.28 soon.

Steps to reproduce

see patch

Proposed resolution

see patch

Remaining tasks

see patch

πŸ› Bug report
Status

Closed: outdated

Version

4.5

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada joseph.olstad

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joseph.olstad
  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    Here's the patch that resolves the issue.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    low risk change, suggest adding this.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    For some strange reason the node can return a time of 9600-02-22 which in unformated $time value is 240784073640.
    In this case, use the value of time() instead

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡¨πŸ‡¦Canada smulvih2 Canada 🍁

    @joseph, I think the only way that $time is empty is if your entity is not an instanceof NodeInterface. Can you verify what $node contains when this happens? Or maybe if you are creating the said node programmatically or via migration that the changed date is not being set correctly.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    @smulvih2 , the date modified needs to work on all pages, not just node pages. With that said, the patch is harmless and did fix someones severaly hosed environment.

    I haven't observied this issue but I saw it first hand in another groups project.

  • πŸ‡¨πŸ‡¦Canada smulvih2 Canada 🍁

    @joseph I agree the date modified needs to work across all pages, not just nodes, but the description of the ticket mentions it happens "for some nodes" which is why I figured the nodes in question might be the issue. I'm not sure what would cause this, but the date modified block works for me across node and non-node pages, on all sites I manage. If you are able to provide steps to reproduce that would be very helpful!

    For non-node pages, the $time = $this->dateTime->getRequestTime(); line should grab the current time. It is only when the current page is a node that it grabs the time from the node in question. This is what leads me to believe the nodes have an issue with them.

  • πŸ‡¨πŸ‡¦Canada nancyHebert

    I created a new patch the item in $value for the date modified is already a unix timestamp and it was the correct timestamp (i.e) 1645488000), using strtotime on it changed it to be 190296492348 i.e year 8000.
    I added a function to check if the timestamp was a valid gregorian date as well.

  • Status changed to Closed: outdated 11 months ago
Production build 0.69.0 2024