473,804 Members | 3,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

make a time script shorter

I used the following script for a site to stop displaying after a date /
time, but it seems huge. Any ideas on how to make it shorter? There are
many events in this list.
function events() {

var today = new Date();
var dayarray=new Array("Sun","Mo n","Tue","Wed", "Thu","Fri","Sa t")
var montharray=new
Array("Jan","Fe b","Mar","Apr", "May","Jun","Ju l","Aug","Sep", "Oct","Nov","De c
")
document.write( '<table>');
var event = "Spirit of the Dance - 8:00 pm (<a
href=ticketorde rform_spiritoft hedance.html>Or der Tickets</a>)";
var date = new Date("October 30, 2003");
date.setHours (23);
date.setMinutes (21);
date.setSeconds (59);
var year=date.getYe ar()
if (year < 1000)
year+=1900
var day=date.getDay ()
var month=date.getM onth()
var daym=date.getDa te()
var cdate=dayarray[day]+", "+montharra y[month]+" "+daym+" "+year+" "
if (today.getTime( ) <= date.getTime()) {
document.write( '<tr><td valign=top>');
document.write( cdate);
document.write( '</td><td>- ');
document.write( event);
document.write( '</td></tr>');
}
document.write( '</table>');

}
Jul 20 '05 #1
1 4166
JRS: In article <ac************ *************** ***@news.terane ws.com>,
seen in news:comp.lang. javascript, Treetop <tr*****@netfro nt.net> posted
at Fri, 3 Oct 2003 16:42:30 :-
I used the following script for a site to stop displaying after a date /
time, but it seems huge. Any ideas on how to make it shorter? There are
many events in this list.
function events() {

var today = new Date();
var dayarray=new Array("Sun","Mo n","Tue","Wed", "Thu","Fri","Sa t") var dayarray=["Sun","Mon","Tu e","Wed","Thu", "Fri","Sat"] var montharray=new
Array("Jan","F eb","Mar","Apr" ,"May","Jun","J ul","Aug","Sep" ,"Oct","Nov","D ec
")
document.write ('<table>');
var event = "Spirit of the Dance - 8:00 pm (<a
href=ticketord erform_spiritof thedance.html>O rder Tickets</a>)";
var date = new Date("October 30, 2003");
date.setHours (23);
date.setMinutes (21);
date.setSeconds (59);
var date = new Date(2003,9,30, 23,21,59)
var date = new Date("2003/10/31") // near enough ?
var date = new Date("2003/10/30 23:21:59")
var year=date.getYe ar()
if (year < 1000)
year+=1900
var year = 1900 + date.getYear()% 1900 // < AD 3800
var day=date.getDay ()
var month=date.getM onth()
var daym=date.getDa te()
var cdate=dayarray[day]+", "+montharra y[month]+" "+daym+" "+year+" "
if (today.getTime( ) <= date.getTime()) {
document.write ('<tr><td valign=top>');
document.write (cdate);
document.write ('</td><td>- ');
document.write (event);
document.write ('</td></tr>');
}
if (today <= date) with (date)
document.write( '<tr><tc valign=top>, dayarray[getDay()], ', ',
montharray[getMonth()], ' ', getDate(), ' ',
1900 + date.getYear()% 1900, '<\/td><td>- ', event, '<\/td><\/tr>')

document.write ('</table>');

}


After testing, then shorten variable names.

For World-Wide Web use, M D Y is silly; use Y M D. Consider LZ, or
equivalent, to add leading zero to getDate().

There is no point in calculating anything that will not get used; test
the date earlier.

To shorten repetitive work, use a function with parameters. For
example, function WriteTable(Evnt , Till) ; today, dayarray,
montharray can be global. If the Evnt always has a similar URL,
parameterise the variable part of that, too :-

WT("Spirit of the Dance - 8:00 pm",
"spiritofthedan ce", "2003/10/30 23:21:59")

Then you can, for a slight gain on a long schedule, supply those as
elements of an array :

var Data = [
["Spirit of the Dance - 8:00 pm",
"spiritofthedan ce", "2003/10/30 23:21:59"],
["Mozart - 15:30", "wam", "2003/12/31 11:45"], ... ... ]

Read the FAQ, thoughtfully.

Note that the event occurs at a specific time and location; you want to
prevent ticket ordering at that absolute time or a fixed offset from
that, independently of the orderer's location. The chronologically
retarded, such as Alaskans, should not be able to take undue advantage;
the advanced Maoris should not be handicapped.

It is still possible, I think, to be using a computer
in the VIP lounge at LHR, and to arrive in or near NYC
at an earlier local time.

NOTE to all, prompted by above :

<URL:http://www.merlyn.demo n.co.uk/js-date5.htm#DDTA> is much changed;
it could do with a functionality test on later browsers, a correctness
check, and any suggestions for reasonable code reduction. I think the
page displays all relevant code, except imports.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
6756
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site... this number is always changing as I have hundreds of thousand of pages of text on my site. Problem: - in my opinion this just not only look weird, but the variable "n" (number)
8
3363
by: jasonbrown1999 | last post by:
Someone told me the following script could be used to run harmful commands on the server, by passing commands into the script. What the script does is encode an affiliate URL, create two frames, with the affiliate URL decoded and placed in the bottom URL. The top frame contains http://www.domain.com/selectanothercard.html for navigation back to the originating site. The script is accessed with a link like this: <a...
4
1566
by: Spencer | last post by:
I am interested in making my own forums (powered by Python). I was wondering what would be needed to make one, so that I can start making it. I have always used the login script I made (it uses PHP and MySQL), will people be able to use the forums using a PHP/MySQL login script? Will it makes things more complicated? Of course I will answer any questions you may have.
7
2336
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten it. Perhaps there are some python features or libraries I'm not taking advantage of. The way it works is that it puts references to all the files in a dictionary with file size being the key. The dictionary can hold multiple values per key....
6
4906
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
6
1308
by: AlGorr | last post by:
Hello,,, I don't know much about PHP+SQL but I have to find the better way to make my query work and to be shorter and better. All help will be appreciated. //Check if IP exists in banIP $res = mysql_query("SELECT ip FROM banIP WHERE ip = '".$_SERVER."'"); $res = mysql_num_rows($res);
3
1860
by: skanemupp | last post by:
is there anyway to make this shorter? i hate having these big blocks of similar-looking code, very unaesthetic. maybe doesnt matter good-code-wise? anyway can i make some function that makes this shorter? like put the etiquettes on the button froma string of '123+456-789*0Cr/' ? problem is the command and lambda-func for each button is different. self.btnDisplay = Button(self,text='1',command=lambda
4
1546
by: raylopez99 | last post by:
Please consider the below and how to make name references shorter-- there has to be a way. RL using System; namespace MyNamesSpace1 { class ManagerClass
1
47493
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10567
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.