You are here: Re: Can this code be improoved? If so how? « PHP Language « IT news, forums, messages
Re: Can this code be improoved? If so how?

Posted by Daedalus.OS on 05/27/05 13:39

And since I can't sleep (insomnia probably) here is a little more... using a
simple function

Instead of giving the $HOLIDAYS array values referring to code A through F,
lets give it the number of day we have to add to current date. So the array
would now look like this:
$HOLIDAYS = array(
'Nov 23'=>5, 'May 27'=>4, 'Jul 1'=>4,... // and so on
);

Now lets define a function that will deal with these days:

function shippingDay($days){
$shipDay = date("l F jS", time()+($days*24*60*60));
return $shipDay;
}

Now lets rewrite the loop I posted earlier:

if (isset($HOLIDAYS[$DELAYDAYFL])){
$IS_SHP_HOLIDAY = true;
$ORDER_WILL_SHIP = HOLIDAY_SHIP_TEXT .' '.
shippingDay($HOLIDAYS[$DELAYDAYFL]);
}else{
$IS_SHP_HOLIDAY = false;
}

Later in your script if you would need to get a shipping date, all you need
is to call this function and pass it the number of day to add (
shippingDay(0) would mean today).

Now see how this:
#################################
$ORDER_WILL_SHIPA = date("l F jS");
$ORDER_WILL_SHIPB = date("l F jS", time()+86400); //86400 = 1 day this is
seconds
$ORDER_WILL_SHIPC = date("l F jS", time()+172800);
$ORDER_WILL_SHIPD = date("l F jS", time()+259200);
$ORDER_WILL_SHIPE = date("l F jS", time()+345600);
$ORDER_WILL_SHIPF = date("l F jS", time()+432000);
//Define $IS_SHP_HOLIDAY true
if ($DELAYDAYFL == 'Nov 23' || $DELAYDAYFL == 'May 27' || $DELAYDAYFL ==
'Jul 1' || $DELAYDAYFL == 'Sep 2' || $DELAYDAYFL == 'Oct 7' || $DELAYDAYFL
== 'Nov 8' || $DELAYDAYFL == 'Nov 24' || $DELAYDAYFL == 'Dec 23' ||
$DELAYDAYFL == 'May 28' || $DELAYDAYFL == 'Jul 2' || $DELAYDAYFL == 'Sep 3'
|| $DELAYDAYFL == 'Oct 8' || $DELAYDAYFL == 'Nov 9' || $DELAYDAYFL == 'Nov
25' || $DELAYDAYFL == 'Dec 24' || $DELAYDAYFL == 'May 29' || $DELAYDAYFL ==
'Jul 3' || $DELAYDAYFL == 'Sep 4' || $DELAYDAYFL == 'Oct 9' || $DELAYDAYFL
== 'Dec 25' || $DELAYDAYFL == 'Jan 1' || $DELAYDAYFL == 'May 30' ||
$DELAYDAYFL == 'Jul 4' || $DELAYDAYFL == 'Sep 5' || $DELAYDAYFL == 'Oct 10'
|| $DELAYDAYFL == 'Dec 26' || $DELAYDAYFL == 'Jan 2') {${IS_SHP_HOLIDAY} =
'true';}
else $IS_SHP_HOLIDAY = 'false';
//Define Regular Weekday ship days
if ($TDAY == 'Mon' || $TDAY == 'Tue' || $TDAY == 'Wed' || $TDAY ==
'Thu'){$STDSHIPWD = 'true';}
else $STDSHIPWD = 'false' ;

if ($DELAYDAYFL == 'Nov 23'){${ORDER_WILL_SHIP} = HOLIDAY_SHIP_TEXT . ' ' .
$ORDER_WILL_SHIPF;}
if ($DELAYDAYFL == 'May 27' || $DELAYDAYFL == 'Jul 1' || $DELAYDAYFL == 'Sep
2' || $DELAYDAYFL == 'Oct 7' || $DELAYDAYFL == 'Nov 8' || $DELAYDAYFL ==
'Nov 24' || $DELAYDAYFL == 'Dec 23'){${ORDER_WILL_SHIP} = HOLIDAY_SHIP_TEXT
.. ' ' . $ORDER_WILL_SHIPE . PERD;}
if ($DELAYDAYFL == 'May 28' || $DELAYDAYFL == 'Jul 2' || $DELAYDAYFL == 'Sep
3' || $DELAYDAYFL == 'Oct 8' || $DELAYDAYFL == 'Nov 9' || $DELAYDAYFL ==
'Nov 25' || $DELAYDAYFL == 'Dec 24'){${ORDER_WILL_SHIP} = HOLIDAY_SHIP_TEXT
.. ' ' . $ORDER_WILL_SHIPD . PERD;}
if ($DELAYDAYFL == 'May 29' || $DELAYDAYFL == 'Jul 3' || $DELAYDAYFL == 'Sep
4' || $DELAYDAYFL == 'Oct 9' || $DELAYDAYFL == 'Dec 25' || $DELAYDAYFL ==
'Jan 1' ){${ORDER_WILL_SHIP} = HOLIDAY_SHIP_TEXT . ' ' . $ORDER_WILL_SHIPC .
PERD;}
if ($DELAYDAYFL == 'May 30' || $DELAYDAYFL == 'Jul 4' || $DELAYDAYFL == 'Sep
5' || $DELAYDAYFL == 'Oct 10' || $DELAYDAYFL == 'Dec 26' || $DELAYDAYFL ==
'Jan 2') {${ORDER_WILL_SHIP} = HOLIDAY_SHIP_TEXT . ' ' . $ORDER_WILL_SHIPB .
PERD;}
#######################
Turn into this:
+++++++++++++++++++++
$HOLIDAYS = array(
'Nov 23'=>5, 'May 27'=>4, 'Jul 1'=>4,
'Sep 2'=>4, 'Oct 7'=>4, 'Nov 8'=>4,
'Nov 24'=>4, 'Dec 23'=>4, 'May 28'=>'D',
'Jul 2'=>3, 'Sep 3'=>3, 'Oct 8'=>3,
'Nov 9'=>3, 'Nov 25'=>3, 'Dec 24'=>3,
'May 29'=>2, 'Jul 3'=>2, 'Sep 4'=>2,
'Oct 9'=>2, 'Dec 25'=>2, 'Jan 1'=>2,
'May 30'=>1, 'Jul 4'=>1, 'Sep 5'=>1,
'Oct 10'=>1, 'Dec 26'=>1, 'Jan 2'=>1
);
function shippingDay($days){
$shipDay = date("l F jS", time()+($days*24*60*60));
return $shipDay;
}
if (isset($HOLIDAYS[$DELAYDAYFL])){
$IS_SHP_HOLIDAY = true;
$ORDER_WILL_SHIP = HOLIDAY_SHIP_TEXT . ' ' .
shippingDay($HOLIDAYS[$DELAYDAYFL]);
}else{
$IS_SHP_HOLIDAY = false;
}
++++++++++++++++++++++

And some may have better ways than this one... Anyway I think you get the
picture...
Good learning.

Dae

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация