PDA

View Full Version : Need help - If statement script which trigers by definite dates



Ahmed_AA
Mar 15th, 2007, 07:01 AM
I am creating site about Islam and muslims (www.islammuslim.lv) and I want that on site would be daily praying times. They changes day from day so I need unique for every day. On internet there is some 2-3 muslim portals who offers javascript code and they send to your site prayer times, but they do not give enough options for making it fit in design.

So I am trying to create my self script in which I could wrote in those prayertimes.

As far as I understand I need something like this:

var now date = 14/03/2007
var now date = 15/03/2007
var now date = 16/03/2007
var now date = 17/03/2007
etc

so if (or case) today = 14/03/2007 then display 04:33 06:43 12:33 15:34 18:24 20:24
so if (or case) today = 15/03/2007 then display 04:32 06:41 12:32 15:36 18:26 20:26
so if (or case) today = 16/03/2007 then display 04:30 06:40 12:32 15:38 18:28 20:28
so if (or case) today = 17/03/2007 then display 04:29 06:38 12:31 15:39 18:29 20:29

etc

So how does it is in Javascript code? (I have very small knowledge about scripting...)

phoenixshade
Mar 15th, 2007, 08:56 AM
You'd be much (much) better off either: (a) finding the formula to calculate these dates, or (b) using a database/php solution. Why? This would be a HUGE switch/case statement, and would result in slow loading times just to display one piece of information.

Solution (a) is difficult but better, because from what I've read, Latitude and Longitude are necessary to calculate accurate times (for Asr in particular). I can't imagine a database, and especially not a javascript switch/case statement, that could possibly take all this into account. (Well, perhaps a database, but it would be absolutely huge.) When you compound this with the fact that there are (at least) five schools of law regarding how these are calculated, you end up getting a database that must approach several hundred Mb in size, maybe more.

I was unable to find the formulae an the web in a quick search, but I'm sure a more thorough search would result in something.

For what it's worth, case statement syntax is this:

switch (n) {
case 0:
code to be executed. NOT enclosed in a block {}.
break /* This is not completely necessary, but if absent, the next case will also execute. This kicks control out of the switch altogether. */
case 1:
code to be executed.
break
case 2:
[ . . . ]
default:
code to be executed if none of above cases are met
}
n must be an integer number, so you should probably convert the date to a "unix epoch" day (Days since... 1/1/70, I believe?) which could then be fed into the case statement.

Good luck.

Kor
Mar 15th, 2007, 09:53 AM
The Data base can be build also in XML and accesed with AJAX. The speed will be satisfactory even for a medium DB.

On the other hand there must be a pattern (a math equation) which build the set of values (the way the time for praying changes from a day to another). If you know that equation (written as algebraical linear equation), the translation in javascript is simple

Ahmed_AA
Mar 15th, 2007, 11:59 PM
Sorry, but Yours advices was so complicated that I could not use them.
I have truly little knowledge.

But on another forum one men gave me this working script:


<script language="JavaScript">
var date = new Date();
var today = date.getFullYear() + '/' + date.getMonth() + '/' + date.getDate();

switch (today)
{
case '2007/2/15':
document.write('04:33 06:43 12:33 15:34 18:24 20:24');
break;

case '2007/2/16':
document.write('04:33 06:43 12:33 15:34 18:24 20:24');
break;

default:

}

</script>

Sorry for not using Yours efforts.