473,807 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script to Tell Tell Time then Limit by it?

Hi,
I'm hoping someone can help me with this.

I have a URL for which I'd like to limit access to by time. For
example,say I have a URL that I don't want accessable on Monday mornings
between 10am-noon and Fri. afternoons between 2-4pm. So when someone clicks
on the URL during those times a message pops up saying somthing like "sorry we're
closed now etc"

Is this possible? if yes, I'm guessing I'll need somesort of "onclick" for the
href and a script to check the sys time/date ?

TIA,
Mike
Jul 20 '05
17 4890
Thank you all for assisting me with this script. I'm in the process of
testing
it (Michael's last updated Usenet post) and Have a few followup
questions/uncertainties:

1. The href in question should only be avail on mondays 10-noon and
fridays 2-4pm, any other times the window.alert should appear. I think
this is working correctly, based on the code, is this correct?

2. I'm testing the various days/time periods by manually changing the
clock on my PC (windoze xp)I'm having problems when I change the time
on any given day. i.e. say I change the day to fri, and the time to
1pm, I should get the window.alert but I don't Is this normal?

Thank you for your patience.
Mike

Dr John Stockton <sp**@merlyn.de mon.co.uk> wrote in message news:<e6******* *******@merlyn. demon.co.uk>...
JRS: In article <15************ **************@ posting.google. com>, seen
in news:comp.lang. javascript, Mike A <mi***@capital. net> posted at Mon,
17 Nov 2003 09:49:58 :-
Ok, As a newbie, I'll have to ask as I'm now totally confused.
I'm trying to edit Michael Winter's original code with the edits
he suggested (in a previous post) with no luck, would someone
be kind and assist?


That may be sub-optimal.

To the article to which the above is a response, add :

or
HoW = D*100 + H
Not = (HoW>110 && HoW<112) || (HoW>514 && HoW<516)

or
HoW = D + H/100
Not = (HoW>1.10 && HoW<1.12) || (HoW>5.14 && HoW<5.16)

Note that the numbers are of the form <Day-of-JS-Week><Hours>; cf.
<URL:http://www.merlyn.demo n.co.uk/js-date1.htm#DC> and
<URL:http://www.merlyn.demo n.co.uk/js-date1.htm#TCp>.

Jul 20 '05 #11
JRS: In article <Xn************ *************** ****@193.38.113 .46>, seen
in news:comp.lang. javascript, Michael Winter <M.Winter@[no-spam]> posted
at Mon, 17 Nov 2003 22:24:01 :-
Unless someone can find any more errors (I did boundary test it) or I
overlooked something, this should be fine (under Opera 7.22 and IE 6,
at least). Any comments relating to date operations are also welcome.
I think you overlooked the possibility that it might be Tuesday, for
example; also Wed Thu Sat Sun.

Every switch statement should have a default: at the end, unless it is
absolutely certain that all possible cases are covered, and will remain
covered, above. If it is intended that all cases be covered above, use
default: alert('Blunder' ) // or suchlike.

You probably need :
default: return true
<A href="my-time-dependant-page.html"
onclick="return isAccessable(); ">Enter</A>


isAccessable should be isAccessible
dependant should be dependent

--
© 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 #12
Mike A wrote:
Ok, As a newbie, I'll have to ask as I'm now totally confused.
I'm trying to edit Michael Winter's original code with the edits
he suggested (in a previous post) with no luck, would someone
be kind and assist?

TIA,
Mike


The code is pointless, since you're telling me when the page is
unavailable, I can simply adjust the clock on my PC to avoid your
"security".

Also, even if the target audience is in North America, NA consists
of at least 3 time zones, making "10am to noon on Monday"
meaningless, except to users in your local time zone, and even then,
meaningful only if the clock on their local PC is set accurately.

The only way to disable a page for a specific period of time (to
perform maintenance, updating or backups) is to disable the page on
the server, using some sort of server-side processing. If you have
no access to server-side processing (Perl, PHP, ASP, etc), then the
simplest solution is to simply swap a "This page not available" page
in over the page you want to disable while you are performing
whatever updates are necessary.

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #13
Dr John Stockton wrote on 18 Nov 2003:
JRS: In article
<Xn************ *************** ****@193.38.113 .46>, seen in
news:comp.lang. javascript, Michael Winter <M.Winter@[no-spam]>
posted at Mon, 17 Nov 2003 22:24:01 :-
Unless someone can find any more errors (I did boundary test it)
or I overlooked something, this should be fine (under Opera 7.22
and IE 6, at least). Any comments relating to date operations
are also welcome.
I think you overlooked the possibility that it might be Tuesday,
for example; also Wed Thu Sat Sun.


They were omitted on purpose. This was only an example - in fact, an
implementation of the example given by the original poster. I
expected additional cases to be added as necessary.

I should have also commented the if statements better:

// If time is not between 10:00:00 and 11:59:59.999 UTC, the site
// is accessible (returns true).
if( !(( 10 <= now.getUTCHours () ) && ( now.getUTCHours () < 12 )))
return true;

It's a minor change, but it explains the logic a little better.
Every switch statement should have a default: at the end, unless
it is absolutely certain that all possible cases are covered,
and will remain covered, above. If it is intended that all
cases be covered above, use
default: alert('Blunder' ) // or suchlike.

You probably need :
default: return true;


You are absolutely correct: a default case is required for the script
to work as desired. The default case should return boolean true (as
quoted above).

I didn't discover this because I only tested the days that had
conditions (serves me right for not preparing proper test cases).
<A href="my-time-dependant-page.html"
onclick="return isAccessable(); ">Enter</A>


isAccessable should be
isAccessible
dependant should be dependent


I didn't think I had spelt either correctly, but I was more concerned
about replying then ensuring correct spelling.

Mike

--
Michael Winter
M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #14
Mike A wrote on 18 Nov 2003:
Thank you all for assisting me with this script. I'm in the
process of testing
it (Michael's last updated Usenet post) and Have a few followup
questions/uncertainties:

1. The href in question should only be avail on mondays 10-noon
and fridays 2-4pm, any other times the window.alert should
appear. I think this is working correctly, based on the code, is
this correct?
As Dr Stockton pointed out in his reply to the new code, I missed the
default case. The switch should read:

switch ( now.getUTCDay() )
{
case 1: // Monday
// If time is not between 10:00:00 and 11:59:59.999 UTC
// (inclusive), the site is accessible (returns true)

if ( !(( 10 <= now.getUTCHours ()) && ( now.getUTCHours () < 12 )))
return true;
break;
case 5: // Friday
// If time is not between 14:00:00 and 15:59:59.999 UTC
// (inclusive), the site is accessible (returns true)

if ( !(( 14 <= now.getUTCHours ()) && ( now.getUTCHours () < 16 )))
return true;
break;
default: // Other days have no restrictions
return true;
}

Now the script should only return false on Mondays, between 10:00 and
12:00, and Fridays between 14:00 and 16:00 (closed times). It will
return true at all other times.
2. I'm testing the various days/time periods by manually
changing the clock on my PC (windoze xp)I'm having problems when
I change the time on any given day. i.e. say I change the day to
fri, and the time to 1pm, I should get the window.alert but I
don't Is this normal?


The times the script checks are in the GMT time zone. You could
adjust your clock to cope with the difference in time zones, but
there is an easier way. It also means you don't have to play with
your system's clock.

Comment out the line beginning: var now = .... Add a new line after
it like this:

var now = new Date(
Date.UTC(year, month (zero-based), day, hour, min, sec, millisec));

If you entered: Date.UTC( 2003, 10, 21, 13, 0, 0, 0 ) [Friday, 21
November 2003 @ 1pm], you will get the alert. Just remember to change
back to "var now = new Date();" when you've finished testing.

Remember that using the UTC methods is the only way to ensure that
the date and times will be evaluted consistently across the world.
When you set the disallowed dates and times, change them from your
local time zone to GMT.

Mike

--
Michael Winter
M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #15
Grant Wagner wrote on 18 Nov 2003:
The only way to disable a page for a specific period of time (to
perform maintenance, updating or backups) is to disable the page on
the server, using some sort of server-side processing.
The preferred use of server-side processing has already been
pointed out, but it appears that the original poster doesn't have
that ability.
If you have no access to server-side processing (Perl, PHP, ASP,
etc), then the simplest solution is to simply swap a "This page not
available" page in over the page you want to disable while you are
performing whatever updates are necessary.


I don't believe this is to allow updates. The OP asked for something
to disable pages on a regular, weekly schedule.

Mike

--
Michael Winter
M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #16
JRS: In article <15************ **************@ posting.google. com>, seen
in news:comp.lang. javascript, Mike A <mi***@capital. net> posted at Tue,
18 Nov 2003 07:44:51 :-
Dr John Stockton <sp**@merlyn.de mon.co.uk> wrote in message news:<e6qby0B5z Tu$Ew
lQ@merlyn.demo n.co.uk>...
JRS: In article <15************ **************@ posting.google. com>, seen
in news:comp.lang. javascript, Mike A <mi***@capital. net> posted at Mon,
17 Nov 2003 09:49:58 :-
>Ok, As a newbie, I'll have to ask as I'm now totally confused.
>I'm trying to edit Michael Winter's original code with the edits
>he suggested (in a previous post) with no luck, would someone
>be kind and assist?
That may be sub-optimal.


Responses should go after quotes; corrected. Read the FAQ.

I'm in the process of
testing
it (Michael's last updated Usenet post) and Have a few followup
questions/uncertainties:
When responding to Michael, please follow-up to the relevant post of
Michael's - not to one of someone else's.

1. The href in question should only be avail on mondays 10-noon and
fridays 2-4pm, any other times the window.alert should appear. I think
this is working correctly, based on the code, is this correct?
Only, I think, if you are referring to code that I have not seen.

2. I'm testing the various days/time periods by manually changing the
clock on my PC (windoze xp)I'm having problems when I change the time
on any given day. i.e. say I change the day to fri, and the time to
1pm, I should get the window.alert but I don't Is this normal?


That is an ABOMINABLE technique; all sorts of other date/time-dependent
actions in your computer system may get fired or missed.

A function like isAccessible() should take the actual date through its
parameter(s), then a specific date can be given for test such as by
isAccessible(ne w Date("2003/11/21 13:00 GMT")); note that I use a form
in which each month is represented by its customary number, to avoid
confusion. In this case one might also get isInaccessible( ) to
alert(now) in order to be sure of the day of week being tested.

--
© 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 #17
JRS: In article <3F************ ***@agricoreuni ted.com>, seen in
news:comp.lang. javascript, Grant Wagner <gw*****@agrico reunited.com>
posted at Tue, 18 Nov 2003 19:05:19 :-
The code is pointless, since you're telling me when the page is
unavailable, I can simply adjust the clock on my PC to avoid your
"security".
You can; but the practice is dangerous if any other date/time dependent
processes may be running.

Code as requested would not prevent access, but it would in practice
limit it to the persistent.

Also, even if the target audience is in North America, NA consists
of at least 3 time zones, making "10am to noon on Monday"
meaningless, except to users in your local time zone, and even then,
meaningful only if the clock on their local PC is set accurately.


Most North Americans don't believe in time zones other than their own
.... . The 48 States use 4 full zones, Canada adds 1.5 Eastwards, Alaska
adds 1 Westwards, and various islands add another, still within the 50
States. Then there's Greenland ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 20 '05 #18

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

Similar topics

7
3667
by: Damien | last post by:
Hello to all, I've written a script that take quite a long time to execute (email sending). Last time I ran it, PHP gave me a "execution time limit exceeded" (or something like that), so I changed the value in php.ini. Now, the questions are : - How can I make sure I'm not going to have problems when execution time lengthens still ? I'm afraid to set too high a time limit in case other scripts run astray. - Can I "break" the job into...
6
4173
by: Jeffrey Silverman | last post by:
Hi, all. Sorry, first off, for the kidna weird selection of crossposted groups, but this question touches on aspects of discussion in each of the groups. So I have a group of around 500 email addresses to which I would like to send a mass email occasionally. The group will never be much larger than 500 email addresses and will occasionally be about half that size. I have written a simple HTML interface and PHP backend to process the...
0
6033
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited programming knowledge. Basically, we are trying to add a few lines to this script that will execute a few shell commands (see comments at the very end of the code). We think this may be ActionScript2 but aren't sure. If you can offer any help, or know...
4
1296
by: R.Meijer | last post by:
Hi, I've been busy with an experimental script, and I can't seem to see what is wrong with it, can somebody tell me? Here it is: a = 0 b = 1 mainloop = 1 print "Welcome to pyFibo"
6
1769
by: Justice | last post by:
Just moved site to different web server. Previously no problems. Now, the script will time out after 90 minutes. I've set set_time_limit(0) but no effect. Any ideas? John
11
24180
by: www.MessageMazes.com | last post by:
I sometimes get this error after about 60 seconds of "waiting for mazes.com" (but when the page works, it usually loads in less than 12 seconds). > Active Server Pages error 'ASP 0113' > Script timed out > /asp-maze/amazingtest.asp > The maximum amount of time for a script to execute was exceeded. You can > change this limit by specifying a new value for the property Server.ScriptTimeout > or by changing the value in the IIS...
3
3976
by: Hugo Lefebvre | last post by:
Is there a maximum number of emails CDONTS can handle in an asp script? I have different questions about this. Question1: example1: set objSendMail = createobject("CDONTS.NewMail") ...... objSendMail.To = emailto
5
3489
by: This | last post by:
I have a pretty basic emailing script that sends a relatively small number (150) of html emails. The emails are compiled, personalised from a mysql db subscribers list, and sent using mail() - after sending, a small summary html page is sent to the user with number sent, time taken and a simple navigation choice. Up to about 100 emails it all works fine - this takes the server about 27 secs . Any more than that and although the emails are...
1
47496
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
9721
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...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9195
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...
0
6880
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
5547
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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.