Hi
I have a requirement to compare the user entry for mm/dd/yy/HH/mm
(month, day, year, hour, minute) to the Easter Standard Time.
I am using the following script, but it is not giving the right answer.
Your kind help is appreciated. Thank you!
//this is what user enters
var gdate = new Date(f.year.val ue, f.month.value, f.day.value,
f.hour.value, f.min.value);
var EST_offset = -4
var num_msecs = gdate.getTime() + gdate.getTimezo neOffset() * 60000
+ EST_offset *3600000;
//the current time of the desk top depends on location
var gdate2 = new Date();
var num_msecs2 = gdate2.getTime( )+ gdate2.getTimez oneOffset() *
60000;
//we don't know the offset from GMT! What does getTimezoneOffs et
return?
if (num_msecs < num_msecs2) {
alert("Schedule time has to be in the future");
return false;
} 10 2706 so***********@y ahoo.com wrote:
[snip] //we don't know the offset from GMT! What does getTimezoneOffs et return?
Local number of minutes that the client is offset(subtract ed) from Zulu
Time.
West of Greenwich positive, East negative.
Mick
Thanks Mick. What is zulu time ? This is how I ended up coding, for the
record
//Form date/time validation
//In the US, dst starts on the first sunday in april and ends on
the last
//sunday in october..
//the date of the 1st sunday in april is:
var curYear = new Date(); // get the year (or manually set it)
// set up the 1st of april of the chosen year
// remember months are zero based, so april = 3
var startDST = new Date(curYear.ge tFullYear(), 3, 1); // sets a
date to 1st of april
// use the day number of the week as an offset
// by subtracting from 7 (# days in week)
// and add to 1st
startDST.setDat e(1 + 7 - startDST.getDay ());
// set up last day of october
var endDST = new Date(curYear.ge tFullYear(), 9, 31);
// subtract the day number in week of last day to arrive at last
sunday in month
endDST.setDate( 31 - endDST.getDay() );
var gdate = new Date(f.year.val ue, f.month.value, f.day.value,
f.hour.value, f.min.value);
var tzoffset = -4;
if ( gdate < startDST || gdate > endDST )
tzoffset = -5;
var num_msecs = gdate.getTime() ;
var gdate2 = new Date();
var num_msecs2 = gdate2.getTime( ) + gdate.getTimezo neOffset() *
60000 + tzoffset*360000 0;
//alert("diff=" + (num_msecs - num_msecs2)/(60000*60) + "offset=" +
gdate.getTimezo neOffset() + "tzoffset=" + tzoffset );
if (num_msecs < num_msecs2) {
alert("Schedule time has to be in the future");
return false;
} so***********@y ahoo.com wrote: Thanks Mick. What is zulu time ? This is how I ended up coding, for the record
Your algorithm appears flawed.
The first issue is checking that the values entered by the user are
valid numbers and generate a valid date and time - hopefully you do that
elsewhere and just didn't show it.
The second issue is that you are dependent on the client's local system
settings for date, time, region and daylight saving being correct which
they likely aren't in a good percentage of cases.
The third issue is that daylight saving changes are made at 02:00am,
your algorithm assumes that the change happens at 00:00 AM.
Lastly, your algorithm for finding the first Sunday in April fails when
it falls on the 1st of April (2012).
I think you are better off to always do this stuff on the server. //Form date/time validation
//In the US, dst starts on the first sunday in april and ends on the last //sunday in october..
//the date of the 1st sunday in april is:
var curYear = new Date(); // get the year (or manually set it) // set up the 1st of april of the chosen year // remember months are zero based, so april = 3 var startDST = new Date(curYear.ge tFullYear(), 3, 1); // sets a
var startDST = new Date(curYear.ge tFullYear(), 3, 1, 2);
date to 1st of april // use the day number of the week as an offset // by subtracting from 7 (# days in week) // and add to 1st startDST.setDat e(1 + 7 - startDST.getDay ());
var startDST = new Date(curYear.ge tFullYear(), 3, 1, 2 );
startDST.setDat e( 1 + (7-d.getDay())%7 ); // set up last day of october var endDST = new Date(curYear.ge tFullYear(), 9, 31);
var endDST = new Date(curYear.ge tFullYear(), 9, 31, 2);
[...]
--
Rob
RobG wrote: so***********@y ahoo.com wrote: Thanks Mick. What is zulu time ? This is how I ended up coding, for the record Your algorithm appears flawed.
The first issue is checking that the values entered by the user are valid numbers and generate a valid date and time - hopefully you do that elsewhere and just didn't show it.
The user picks the data from pull-down menus.
The second issue is that you are dependent on the client's local system settings for date, time, region and daylight saving being correct which they likely aren't in a good percentage of cases.
I don't understand what you mean. Our server is in EST zone.
The client/browser could be in any time zone. One way to handle this
is to inject a timezone offset into the session.
The third issue is that daylight saving changes are made at 02:00am, your algorithm assumes that the change happens at 00:00 AM.
Thanks! I copied the code to determine DST from this group archives. :)
Lastly, your algorithm for finding the first Sunday in April fails when it falls on the 1st of April (2012).
I think you are better off to always do this stuff on the server.
//Form date/time validation
//In the US, dst starts on the first sunday in april and ends on the last //sunday in october..
//the date of the 1st sunday in april is:
var curYear = new Date(); // get the year (or manually set it) // set up the 1st of april of the chosen year // remember months are zero based, so april = 3 var startDST = new Date(curYear.ge tFullYear(), 3, 1); // sets a
var startDST = new Date(curYear.ge tFullYear(), 3, 1, 2); date to 1st of april // use the day number of the week as an offset // by subtracting from 7 (# days in week) // and add to 1st startDST.setDat e(1 + 7 - startDST.getDay ());
var startDST = new Date(curYear.ge tFullYear(), 3, 1, 2 ); startDST.setDat e( 1 + (7-d.getDay())%7 );
What is d.getDay? 'Guess it is startDST.getDay ()
Can we do something like this to figure out the first Sunday?
for(var i=1; i < 8; i++) {
var startDST = new Date(curYear.ge tFullYear(), 3, i, 2);
if (startDST.getDa y() == 0) {
break;
}
} // set up last day of october var endDST = new Date(curYear.ge tFullYear(), 9, 31);
var endDST = new Date(curYear.ge tFullYear(), 9, 31, 2);
[...]
-- Rob
Thanks a million! so***********@y ahoo.com wrote: Thanks Mick. What is zulu time ? This is how I ended up coding, for the record
Zulu time is GMT //Form date/time validation
//In the US, dst starts on the first sunday in april and ends on the last //sunday in october..
//the date of the 1st sunday in april is:
var curYear = new Date(); // get the year (or manually set it) // set up the 1st of april of the chosen year // remember months are zero based, so april = 3 var startDST = new Date(curYear.ge tFullYear(), 3, 1); // sets a date to 1st of april // use the day number of the week as an offset // by subtracting from 7 (# days in week) // and add to 1st startDST.setDat e(1 + 7 - startDST.getDay ());
startDST.setDat e(1 + (7-startDST.getDay ())%7)
// set up last day of october var endDST = new Date(curYear.ge tFullYear(), 9, 31); // subtract the day number in week of last day to arrive at last sunday in month endDST.setDate( 31 - .getDay());
endDST.setDate( 31 - endDST.getDay() + 7)%7);
Mick so***********@y ahoo.com wrote: RobG wrote:
so*********** @yahoo.com wrote:
Thanks Mick. What is zulu time ? This is how I ended up coding, for the record Your algorithm appears flawed.
The first issue is checking that the values entered by the user are valid numbers and generate a valid date and time - hopefully you do that elsewhere and just didn't show it.
The user picks the data from pull-down menus.
Hmm, for most users that is painful (i.e. I'm not fond of it), but it's
one way to solve the problem.
The second issue is that you are dependent on the client's local system settings for date, time, region and daylight saving being correct which they likely aren't in a good percentage of cases.
I don't understand what you mean. Our server is in EST zone. The client/browser could be in any time zone. One way to handle this is to inject a timezone offset into the session.
Yes, the client system could be set to anything - the location is
irrelevant. When you initialize gdate2, you accept the system time and
offset as accurate but you have no guarantee that it is.
You could send a time stamp from your server when the page loads and
create a local date object as the very first thing you do. Then keep
track of elapsed time so you always work in the one time system. It
should never be more than a few seconds out, or maybe a minute.
I can't comment on the robustness of that, if you consider malicious
users it may not be sufficient. The third issue is that daylight saving changes are made at 02:00am, your algorithm assumes that the change happens at 00:00 AM.
Thanks! I copied the code to determine DST from this group archives. :)
You need to be careful, not everything posted here is strictly kosher
(I'm as guilty as anyone of that :-x ).
As always, design test cases and test exhaustively. Changeover years
where DST starts on Sunday the 1st or 7th (2001, 2002, 2007, 2012) or
ends on the 25th or 31st (2004, 2009, 2010) plus times in the 'overlap'
would be very close to top of the list.
[...] var startDST = new Date(curYear.ge tFullYear(), 3, 1, 2 ); startDST.setDat e( 1 + (7-d.getDay())%7 );
What is d.getDay? 'Guess it is startDST.getDay ()
Ah, sorry, a leftover from my testing. Yes, d is startDST
Can we do something like this to figure out the first Sunday? for(var i=1; i < 8; i++) { var startDST = new Date(curYear.ge tFullYear(), 3, i, 2); if (startDST.getDa y() == 0) { break; }
Yes, but there's no need. The line I suggested is sufficient and more
concise. I have no idea which is faster, but in any case the difference
is probably undetectable without running the statements a few thousand
times.
A shorter version of the above algorithm is:
while ( startDST.getDay () != 0 ){
startDST.setDat e( startDST.getDat e() + 1);
}
But why use 2 lines when one will do? I can hear JRS muttering about
being paid by the yard...
The first line could be:
while ( startDST.getDay () ){
But some would consider that a maintenance hazard.
[...]
--
Rob
RobG said the following on 10/6/2005 9:09 AM: so***********@y ahoo.com wrote:
<snip> Can we do something like this to figure out the first Sunday? for(var i=1; i < 8; i++) { var startDST = new Date(curYear.ge tFullYear(), 3, i, 2); if (startDST.getDa y() == 0) { break; }
Yes, but there's no need. The line I suggested is sufficient and more concise. I have no idea which is faster, but in any case the difference is probably undetectable without running the statements a few thousand times.
A shorter version of the above algorithm is:
while ( startDST.getDay () != 0 ){ startDST.setDat e( startDST.getDat e() + 1); }
But why use 2 lines when one will do? I can hear JRS muttering about being paid by the yard...
Readability and maintenance come before any consideration of
compactness, let people mutter but it will never change.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
JRS: In article <11************ **********@g49g 2000cwa.googleg roups.com>
, dated Wed, 5 Oct 2005 14:02:37, seen in news:comp.lang. javascript, so***********@y ahoo.com posted : var curYear = new Date(); // get the year (or manually set it) // set up the 1st of april of the chosen year // remember months are zero based, so april = 3 var startDST = new Date(curYear.ge tFullYear(), 3, 1); // sets a date to 1st of april // use the day number of the week as an offset // by subtracting from 7 (# days in week) // and add to 1st startDST.setDat e(1 + 7 - startDST.getDay ());
The range of getDay() is 0..6. Therefore, according to you, DST can
start on April 2..8, and never on April 1. Try your code for the year
2001.
Note that DST changes are at 02:00 local extant time.
Code posted to Usenet should be executable, and so not wrapped by the
posting agent.
Read the FAQ; see below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
JRS: In article <h_************ *******@twister .nyroc.rr.com>, dated
Thu, 6 Oct 2005 12:43:57, seen in news:comp.lang. javascript, Mick White
<mw***********@ rochester.rr.co m> posted : startDST.setDa te(1 + (7-startDST.getDay ())%7)
endDST.setDate( 31 - endDST.getDay() + 7)%7);
Unnecessary arithmetic, even if correct, which the second cannot be.
One need only go back by the 0..6 days given by getDay() from the last
possible date. No need for mod 7 here.
Actually, after new Date(), setDate(2) will be just as accurate as your
inrtended code for startDST, and after the end of this Summer,
setDate(29) for endDST.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: MLH |
last post by:
I would like to be able to look up any 5-digit ZIP in a table
that would show the correct time zone for the area. For
example, I would like to look up 91915 in the table and
see something that indicates Pacific Time Zone or 27615\
would be found as Eastern Time Zone.
I guess I want Eastern Time Zone, Central Time Zone,
Mountain Time Zone, Pacific Time Zone, Atlantic Time
Zone along with Palau, Hawaii, Guam and all the others
for the...
|
by: Jon Davis |
last post by:
The date string: "Thu, 17 Jul 2003 12:35:18 PST"
The problem:
// this fails on PST
DateTime myDate = DateTime.Parse("Thu, 17 Jul 2003 12:35:18 PST");
Help?
Jon
|
by: Marc Pelletier |
last post by:
Hello,
I am writing an application that does some simple astronomical
calculations. One of the variables I need is the number of hours passed in
this year. I've written the following function
public static double GetHoursofYear( DateTime aTime )
{
DateTime StartYear = new DateTime( aTime.Year, 1, 1 );
return ( aTime.ToOADate() - StartYear.ToOADate() ) * 24;
|
by: Avi |
last post by:
I have a problem to get the different time zone's name for example
I need the name of time zone UTC + 4:30 ("Kabul")
The TimeZone.CurrentTimeZone get my current time zone name
and I couldn't see how to get a different time zone name
please hlp this is very important.
Avi
|
by: Clodoaldo Pinto Neto |
last post by:
Hi all,
I want to have the time zone string (like 'BRT') displayed after a
date-time. The date column is of the type timestamp with time zone. But
the time zone is not displayed.
It works for a timestamp without time zone column:
# select to_char(timestamp '2001-02-16 20:38:40' at time zone 'BRT',
'HH24:MI DD/MM/YYYY TZ');
to_char
| |
by: Cesar Ronchese |
last post by:
Hello!
I've built a program that show some dates to users. I got a problem when
users have different configured time zone machines, where:
- One machine that determined time zone the date displayed is 01/01/2006.
- In other different machine (and other configured time zone), the date
displayed is 12/31/2006 19:00:00
If I redefine the time zones of these two machines to the same, the date
|
by: Mike |
last post by:
I'm writing an application for Windows XP Embedded. This application
requires that the user be able to change the time zone from within the
application. I'm trying to do this using SetTimeZoneInformation, but
it's not working correctly and I can't figure out why. I'm using Visual
C# to write the application.
The problem I'm having is that if I choose US Eastern Time (-5:00)
Eastern Time (US & Canada) then the code below winds up setting...
|
by: Satish Itty |
last post by:
Hi all,
I have a big problem in my hands and not sure how I can fix this. Any
suggestions would be greatly appreciated.
I have a .NET 3 tier app developed in VS2003 and .NET 1.1. the client is a
windows application and middle tier runs on IIS. Data is passed between the
client and middle tier as DataSets and custom value object classes. The
problem in my hand is that the client application is deployed in different
time zones and the...
|
by: Steve |
last post by:
Hi All
I have a windows application written in VB.net 2005
The users have to select a State of Australia, which I use to check they have the correct windows time zone selected in control panel
Dim myzone As TimeZone = TimeZone.CurrentTimeZone
If they change the Time zone whilst my application is running, a new call to Dim myzone As TimeZone = TimeZone.CurrentTimeZone returns the same time zone NOT the new one
They have to restart my...
|
by: Correia |
last post by:
I have a webserver that is in another country and have a different
time zone.
How can i fix this and use the scripts with the correct time zone?
Thanks
|
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...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |