473,224 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec
")
document.write('<table>');
var event = "Spirit of the Dance - 8:00 pm (<a
href=ticketorderform_spiritofthedance.html>Order Tickets</a>)";
var date = new Date("October 30, 2003");
date.setHours (23);
date.setMinutes (21);
date.setSeconds (59);
var year=date.getYear()
if (year < 1000)
year+=1900
var day=date.getDay()
var month=date.getMonth()
var daym=date.getDate()
var cdate=dayarray[day]+", "+montharray[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 4149
JRS: In article <ac******************************@news.teranews.co m>,
seen in news:comp.lang.javascript, Treetop <tr*****@netfront.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","Mon","Tue","Wed","Thu","Fri","Sat") var dayarray=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"] var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul"," Aug","Sep","Oct","Nov","Dec
")
document.write('<table>');
var event = "Spirit of the Dance - 8:00 pm (<a
href=ticketorderform_spiritofthedance.html>Orde r 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.getYear()
if (year < 1000)
year+=1900
var year = 1900 + date.getYear()%1900 // < AD 3800
var day=date.getDay()
var month=date.getMonth()
var daym=date.getDate()
var cdate=dayarray[day]+", "+montharray[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",
"spiritofthedance", "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",
"spiritofthedance", "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.demon.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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.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
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......
8
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,...
4
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...
7
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...
6
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...
6
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...
3
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...
4
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
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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.