Tuesday 17 September 2013

[dcphp-dev] Re: Repeating pattern incongruent to any calendar increment

Andrew,
I'll tinker with Unix Time. I'll have to account for the server timezone, then reduce it to a date without time, to prevent 00:01 to 23:59 from being counted as a full day (and thus two dates).

Ed,
The trouble is, I should be able to query any specific date in time and know what static value is set for that date. That requires a static pairing of X date = Y value to start with. Today +/- 70 tells me the date, but without knowing what today's value is I can't calculate the value of the +/- 70 date. When I say value, imagine:

09-01-2013 = A
09-02-2013 = B
09-03-2013 = C
09-04-2013 = A
09-05-2013 = B
09-06-2013 = C

Now find out what letter (A/B/C) 05-21-2075 is. If I know any one of those six dates and their value, I can figure it out. What I'm trying to avoid is hardcoding that pairing and in 2075 still calculating from 2013 as a jump-off point.

I'm doing that now, and it works. I just figured the equivalent of 2013 AD in days would skip the first half of the logic:

$pattern = array();

$i=1;
while($i <= 70){
$pattern[$i] = $i. "val";
$i++;
} //echo "<pre>"; print_r($pattern); echo "</pre>";

$reference_date = date_create('2013-09-01'); //any date the pattern begins on; array key 1
$today = date_create(); //echo " [" .date_format($today, "Y-d-m"). "] ";

$days_ago = date_diff($reference_date, $today); //echo " [" .$days_ago->format('%a'). "] ";

$remainder = (float)($days_ago->format('%a')/70);
$remainder = ($remainder - (int)$remainder)*70 +1; //echo $remainder;

echo $pattern[$remainder]; // today's value

--
You received this message because you are subscribed to the Google
Group: "Washington, DC PHP Developers Group" - http://www.dcphp.net
To post, send email to washington-dcphp-group@googlegroups.com
To unsubscribe, send email to washington-dcphp-group+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/washington-dcphp-group?hl=en
---
You received this message because you are subscribed to the Google Groups "Washington, DC PHP Developers Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to washington-dcphp-group+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 comments:

Post a Comment