- Issue created by @m.stenta
- 🇺🇸United States m.stenta
This seems to happen when the log timestamp is in the distant past. I was able to replicate it with a date of Jan 1, 1902 12:00:00.
- 🇺🇸United States m.stenta
I've traced this to the
CalendarViewBase::ensureTimestampValue()
method in the Calendar View → module:/** * Helper method to make sure a timestamp is a timestamp. * * @param mixed $value * A given value. * * @return int * The timestamp or the original value. */ public function ensureTimestampValue($value) { return !empty($value) && !ctype_digit(strval($value)) ? strtotime($value) : (int) $value; }
Passing a
$value
of-2145898800
(Jan 01 1902 00:00:00) into that method returnsFALSE
becausestrtotime(-2145898800)
returnsFALSE
.Moving this to the Calendar View module issue queue...
- 🇺🇸United States m.stenta
It looks like the
ctype_digit()
function does not work with negative numbers.Here are some tests with
drush php:cli
to show how it works:> ctype_digit(strval(1)) = true > ctype_digit(strval(-1)) = false
This means that any date before the Unix epoch (1 January 1st, 1970 00:00:00 UTC) will not work with this module.
- 🇺🇸United States m.stenta
I wonder if we can use
is_numeric()
instead ofctype_digit
? I tested that out locally and it fixes the issue for me.Change from:
return !empty($value) && !ctype_digit(strval($value)) ? strtotime($value) : (int) $value;
To:
return !empty($value) && !is_numeric($value) ? strtotime($value) : (int) $value;
I will open a MR for consideration.
- @mstenta opened merge request.
- Status changed to Needs review
about 1 year ago 2:45pm 16 August 2023 - 🇮🇳India NivethaSubramaniyan
The given patch is working fine. We can go with is_numeric. I have detailed the steps and attached the screenshot for the reference.
Steps to reproduce:
1) Created a content with authored on date 15 May 1923.
2) Created a calendar view with content
3) Got the issue - InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp() [ Attached the image ]
4) Applied the patch.
5) Now I am able to view the content which I have created on date 15 May 1923. [ Attached an image ]I have done this steps with drupal 9.5 and calendar_view-2.1.1.
- First commit to issue fork.
- Status changed to Fixed
about 1 year ago 10:11am 15 September 2023 Thanks a lot for fixing this issue.
Marking as fixed as it is committed on 2.1.x
Will be shipped in a new release soon.
-
matthieuscarset →
committed 2c00121b on 2.1.x authored by
m.stenta →
Issue #3381473: InvalidArgumentException: The timestamp must be numeric...
-
matthieuscarset →
committed 2c00121b on 2.1.x authored by
m.stenta →
Automatically closed - issue fixed for 2 weeks with no activity.