Link to home
Start Free TrialLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

Datetime calculation and Holidays

This is what I need to do and I want to see if I can do it in Javascript:

1. Get the current date time
2. Get the difference of current date/time with 3PM Central US time. For example, if it's 1:05 PM now...the difference until 3PM is 1:55 hours.
3. Then display this : if you call within the next 1:55 hours (this is the difference), you get your order the next day.

4. BUT if it's Friday, I have to say : if you order within the next 1:55 hours, you will get your order on Monday.
5. If it's  Holiday, i have to know the next day after the holiday.

How can I do this?? I think the hard part is #4 and #5.
Avatar of neeraj523
neeraj523
Flag of India image

5. If it's  Holiday, i have to know the next day after the holiday.

who will define if next day is a holiday or not (other than weekends )
Avatar of Camillia

ASKER

Holiday's are Dec 25, Dec 24, July 4th, Thanksgiving day.
Will VBSCRIPT function work ??
yes, anything that gets this working, I googled for JS code, didnt find anything good.
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unfortunately, I have been unable to locate an accurate "daylight savings time"
determination routine in JavaScript.  This routine would be very complex because
of the complexity of the daylight savings time computation.  For example, there
are sections of the US that still do not observer DST (e.g. in Arizona).

For example, take a look at: http://en.wikipedia.org/wiki/Daylight_saving_time,
and the comment on this page: http://www.energy.ca.gov/daylightsaving.html

"Daylight Saving Time - for the U.S. and its territories - is NOT observed in Hawaii, American Samoa, Guam, Puerto Rico, the Virgin Islands, and by most of Arizona (with the exception of the Navajo Indian Reservation in Arizona)."

This makes it difficult to "accurately" determine if the user is resides in a DST zone,
or not.  Especially if they don't keep their system clock accurate...
From what kind of server is, or will, your html served?

Is. or would, this server be in Central US time?

Would it be possible to use a trivial Ajax call to basically ask the server what time of day it is?

Do you want to believe the date/time currently available from the users machine?

Do you want to provide an input field that can be filled in with the "current date/time", and allow the client to adjust this to be a "more accurate" representation of the users timezone?
HonorGod, let me review your code but some answers:

The app will hosted on a webserver, US Cnetral time zone. So webserver's time. Nothing to do with user's machine.

No, dont want an input field. When user goes to the first page, the "script" should calculate and display the time remaining until 3PM US central time.

I havent used Ajax but i know Ajax is serverside code. I'd like to stay with JS to avoid the server side code.
So, this implies that you want to presume that date, time, and locale on the
user machine are correct.

If we "assume" that these values are correct, we can tell the difference from
the user's machine to GMT.  In my case, since I'm in East Coast US, this is
currently 4 hours.

Then, we need to determine the "date/time/timezone" for US Central.

This would allow us to calculate the time difference to the 3pm Central
"ship" time.

Q: From what kind of environment will the HTML be served?

By this, I mean, is this on web server (e.g., Apache, or IIS), or some kind
of application server?

The reason I'm asking is that I'm wondering if we might be able to somehow
determine the date & time that the HTML was served, and from that compute
a very close approximation of the actual date and time on the server.

Does this make sense?
IIS...

>>The reason I'm asking is that I'm wondering if we might be able to somehow
determine the date & time that the HTML was served, and from that compute
a very close approximation of the actual date and time on the server.

can we not use "current date time". I think this is doable in Javascript but i'm not a Javascripter.
Yes, we can use "current date & time", but

That is the date and time as currently known by the users machine.

It may, or may not be accurate.

That is why I was trying to find out an accurate way to determine the date & time
of the machine from which the HTML is being served.  If you control the server, you
can also control the clock accuracy.

Does this make sense?

havent forgot about this, got busy with other stuff.
understood.  Let me know how I can help
Thanks for the grade & points.  I hope this helps you out.

Good luck & have a great day.