Solution to count back a year in 6.x and 5.x

caomhin - January 1, 2009 - 09:26
Project:Archive
Version:HEAD
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community
Description

This morning I was greeted by an error saying there was an incorrect date on line 106. The following change appears to work:

if($month==1) {
$num_days_prev = cal_days_in_month(CAL_GREGORIAN, 12, $prev_year);
} else {
$num_days_prev = cal_days_in_month(CAL_GREGORIAN, $month-1, $year); // orig code
}

#1

bouddidje@drupa... - January 1, 2009 - 11:03

same same:

warning: cal_days_in_month() [function.cal-days-in-month]: invalid date. in /homez.59/my_DB_name/www/sites/all/modules/archive/archive.module on line 106.

I've tried to replace line 106 by your code:

  • at first, issue still here :(
  • second, I clic on the link "function.cal-days-in-month", and error desappear... but come back when clic on another node...

#2

Maggot - January 1, 2009 - 13:58

Same issue here but the code appeared to fix the problem.

Thanks.

#3

sietecoyote - January 1, 2009 - 21:31
Title:Can't count back a year» works with 5.14
Version:6.x-1.3» 5.x-1.4

I used your solution with version 5.14 and fixed the warning of cal_days_in_month,,

I just removed the comment in the original code line because leaving it causes a Parse error;
so, my final code is like this:

if($month==1) {
$num_days_prev = cal_days_in_month(CAL_GREGORIAN, 12, $prev_year);
} else {
$num_days_prev = cal_days_in_month(CAL_GREGORIAN, $month-1, $year);
}

#4

sietecoyote - January 1, 2009 - 21:54
Title:works with 5.14» Solution to count back a year in 6.x and 5.x

just fixing the forum title to a better search :)

#5

sietecoyote - January 1, 2009 - 21:55
Version:5.x-1.4» HEAD

just fixing the forum title to a better search :)

#6

TomChiverton - January 2, 2009 - 02:19

Same error here on latest 5.x Drupal core and latest version of this module.
Made the change indicated above by hand, and the errors have cleared.

#7

StS - January 2, 2009 - 11:18
Status:active» reviewed & tested by the community

The fix is also a possible solution to the same problem with drupal 6.8.

#8

mdin617 - January 2, 2009 - 20:09

A better patch for the 6.x one at least (I don't have 5.x to test with):

// OLD: $num_days_prev = cal_days_in_month(CAL_GREGORIAN, $month-1, $year);
$num_days_prev = cal_days_in_month(CAL_GREGORIAN, $prev_month, $prev_year);

It only requires the one line because the current version of the 6.x branch already works out what last month was and what year it was in and assigns it to the prev_month and prev_year variables.

#9

pht3k - January 5, 2009 - 00:16

i tested it on 5.x and it doesn't work for me.(#8)
the other patch is perfect.(#3)
thanks all!

#10

cssdru - January 4, 2009 - 00:52

Hello,

I had the same issue but solved now. I tried the mdin617's patch (Drupal 6 too) and it worked perfectly.

Thank you very much!

#11

tetramentis - January 4, 2009 - 20:52

same issue here:

cal_days_in_month() [function.cal-days-in-month]: invalid date. in sites/all/modules/archive/archive.module line 359.

PHP version is 5.2.6-5, Drupal core 5.14, archive module 5.x-1.11.

solution #3 by sietecoyote worked fine, patch file is attached.

AttachmentSize
archive-line-359-error.patch 280 bytes

#12

bismigalis - February 4, 2009 - 19:32

This is more correct fix:

$num_days_prev = cal_days_in_month(CAL_GREGORIAN, $prev_month, $prev_year);

#13

tetramentis - February 4, 2009 - 19:57

according to #9, this one-liner doesn't work on Drupal 5.

 
 

Drupal is a registered trademark of Dries Buytaert.