01314: Problems with Calculations in custom PageVariables

Summary: Problems with Calculations in custom PageVariables
Created: 2013-03-27 16:50
Status: Closed, replied
Category: Bug
Assigned:
Priority: 3
Version: 2.2.21
OS: 5.2.17

Description: Hello,

I have two series of 50 dates used in a web page they all use the same formula except for a multiplier indicating which day in the series it is. Below is how I have some of them in my config.php

$FmtPV['$Omer06'] = 'date("Y-m-d", mktime(0, 0, 0, 3, 26, 2013)+(60*60*24*06)+(60*60*14))';
$FmtPV['$Omer07'] = 'date("Y-m-d", mktime(0, 0, 0, 3, 26, 2013)+(60*60*24*07)+(60*60*14))';
$FmtPV['$Omer08'] = 'date("Y-m-d", mktime(0, 0, 0, 3, 26, 2013)+(60*60*24*08)+(60*60*14))';
$FmtPV['$Omer09'] = 'date("Y-m-d", mktime(0, 0, 0, 3, 26, 2013)+(60*60*24*09)+(60*60*14))';
$FmtPV['$Omer10'] = 'date("Y-m-d", mktime(0, 0, 0, 3, 26, 2013)+(60*60*24*10)+(60*60*14))';

And a second group with the same issue

$FmtPV['$OmerDate07'] = 'date("F j", mktime(0, 0, 0, 3, 25, 2013)+(60*60*24*07)+(60*60*14))';
$FmtPV['$OmerDate08'] = 'date("F j", mktime(0, 0, 0, 3, 25, 2013)+(60*60*24*08)+(60*60*14))';
$FmtPV['$OmerDate09'] = 'date("F j", mktime(0, 0, 0, 3, 25, 2013)+(60*60*24*09)+(60*60*14))';
$FmtPV['$OmerDate10'] = 'date("F j", mktime(0, 0, 0, 3, 25, 2013)+(60*60*24*10)+(60*60*14))';

In my web page I added displays of these variables using:

OmerDate07={$OmerDate07}.\\
OmerDate08={$OmerDate08}.\\
OmerDate09={$OmerDate09}.\\
OmerDate10={$OmerDate10}.\\

Omer06={$Omer06}.\\
Omer07={$Omer07}.\\
Omer08={$Omer08}.\\
Omer09={$Omer09}.\\
Omer10={$Omer10}.\\

Everything works excepts the dates for 08 and 09. The program only picks up the result of mktime and does not add the day calculation.

I have sent config.php through a Hex Dump to see if there is an odd character in there but there is not.

Here is the output on my page:

Omer06=2013–04–01.
Omer07=2013–04–02.
Omer08=2013–03–26.
Omer09=2013–03–26.
Omer10=2013–04–05.

OmerDate07=April 1.
OmerDate08=March 25.
OmerDate09=March 25.
OmerDate10=April 4.

Notice that Omer08, Omer09 and OmerDate08, OmerDate09 all revert back to the date in mktime but don't add the values for the day.

I have tried copying the line for date 07 to 08 and 09 and then change the multiplier but that doesn't work either. I have also tried changing the variable names in case they were colliding with something to Omer08a, Omer09a, OmerDate08a and OmerDate09a. The result didn't change.

I have worked on this issue each year since 2009.

I appreciate your taking the time to check this.

Russell

Try "8" and "9" instead of "08" and "09" in the mktime() call. Numbers starting with "0" are considered in octal by PHP (not by PmWiki), can only contain digits 0-7 so 08 and 09 are parsed to "0". The octal numbers 01, 02, ..., 07 are the same as the decimal 1-7 so you don't notice an error. --Petko March 27, 2013, at 05:16 PM


I made the change both in the page and config.php but I get the same results, just without the leading zeroes. --RussellM March 28 02:39 PM CDT


I even tried changing Omer8 to OmerE, Omer9 to OmerN, OmerDate8 to OmerDateE and OmerDate9 to OmerDateN to remove the possible octal issue and the problem continues. This would suggest the formula has an error, but I have deleted the current definition and copied another line to its place and adjusted the names but the problem continues. --RussellM March 28 03:35 PM CDT

When I said "in the mktime() call", I really meant "inside the mktime() call", that is inside the parentheses after the word "mktime", for example

  $FmtPV['$OmerDate09'] = 'date("F j", mktime(0, 0, 0, 3, 25, 2013)+(60*60*24*9)+(60*60*14))';

instead of (60*60*24*09). I have enabled some of these for this page and I have no bug, see:

OmerDate07={$OmerDate07}.\\
OmerDate08={$OmerDate08}.\\
OmerDate09={$OmerDate09}.\\
OmerDate10={$OmerDate10}.

OmerDate07=April 1.
OmerDate08=April 2.
OmerDate09=April 3.
OmerDate10=April 4.

You can have the name of the variable with leading zeros if you like, I'm talking about the numbers used in the calculation. Petko March 28, 2013, at 04:03 PM


You are a GENIUS Petko. That solved an old problem. I don't think I would have ever caught that. Great observation and understanding. --RussellM March 28 04:17 PM CDT P.S. How do I close the status? Just change it to closed or is there other things that need to be done? RussellM

BTW, if you only need the date 7-8-9 days after March 25 at 14:00, there is a shorter calculation:

$FmtPV['$OmerDate07'] = 'date("F j", mktime(14, 0, 0, 3, 25+7, 2013))';
$FmtPV['$OmerDate08'] = 'date("F j", mktime(14, 0, 0, 3, 25+8, 2013))';
$FmtPV['$OmerDate09'] = 'date("F j", mktime(14, 0, 0, 3, 25+9, 2013))';
$FmtPV['$OmerDate10'] = 'date("F j", mktime(14, 0, 0, 3, 25+10))'; # current year, not only 2013

And if you omit the last ", 2013" your custom page variables will be automatically updated to the current year. See also the 'ftime' MarkupExpressions for a different way to do something like this. --Petko March 28, 2013, at 05:53 PM


Thank you for the great information. This is why I love PmWiki so much. It is flexible and people will help. I will update my calculations as you suggested. It will be nice not to have to adjust things.

I'd like to ask a question. I start out with a specific date each year for Pesach (Passover) and I'm basically counting the next 50 days to Shavuout (Pentecost). Here are my first three entries:

$FmtPV['$Pesach'] = 'date("Y-m-d", mktime(14, 0, 0, 3, 25))'; $FmtPV['$Omer1'] = 'date("Y-m-d", mktime(14, 0, 0, 3, 26)+(60*60*24*1))'; $FmtPV['$Omer2'] = 'date("Y-m-d", mktime(14, 0, 0, 3, 26)+(60*60*24*2))';

Is there a simplier way to compute the Omer by adding on day to $Pesach so that they no longer need adjusting each year. Something along the lines of

$FmtPV['$Omer1'] = 'date("Y-m-d", mktime($Pesach)+(60*60*24*1))';

Thank you for taking the time to help educate me on how to better program for PmWiki. Russell March 29, 2013, at 11:08 AM

You can probably have something like this:

  $PesachStamp = mktime(14, 0, 0, 3, 25, 2013); # set it once in config.php
  $FmtPV['$Pesach'] = 'date("Y-m-d", $GLOBALS["PesachStamp"])'; # use it 
  for ($i=1; $i<51; $i++) # loop 50 times
    $FmtPV['$Omer'.$i] = 'date("Y-m-d", $GLOBALS["PesachStamp"]+(86400*'.$i.'))';

See also http://php.net/calendar where there are some calendar functions like easter_date() or jewishtojd() and calfromjd() which may help calculating the Passover date. --Petko March 29, 2013, at 05:33 PM