Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Instead of creating a date object and calling format('t') we should use the built in PHP function cal_days_in_month();
I've included an XHProf comparison of the performance gains from using the core function.
A patch to follow.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1933572-optimize-date_days_in_month.patch | 632 bytes | minorOffense |
date_days_in_month optimized.png | 83.88 KB | minorOffense | |
date_days_in_month original.png | 108.57 KB | minorOffense |
Comments
Comment #1
minorOffense CreditAttribution: minorOffense commentedPatch as promised.
Comment #2
arlinsandbulte CreditAttribution: arlinsandbulte commentedlooks reasonable to me.
Comment #4
tsyvs CreditAttribution: tsyvs commentedComment #5
tsyvs CreditAttribution: tsyvs commentedPatch #1 is ok.
The problem of testing is about incorrect $year and/or $month values that are passed to function.
So, when incorrect $year and/or $month issue is fixed, the patch will pass tests.
Comment #7
tsyvs CreditAttribution: tsyvs commented