473,789 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date () object in Safari .

According to the Safari browser the world began on "Fri Dec 13 1901
15:45:52 GMT-0500", but I need to be able to get around this limitation.

I am interested in dates from 1500 to 1901, as far as I can determine,
there are 14 possible calendar variations.

Year starts on Sun, Mon.....
Leap year starts on Sun, Mon..

I can label these early year "types" as a number between 0 and 13.

Let's say 2005 is type 5, and that 1655 is too. (In both years Jan 1
falls on a Saturday)

I'm trying to create a function that will identify the "type" of year.

function getYearType(yea r){

return Number // number between 0 and 13
}

Any suggestions?

Mick
Jul 20 '05 #1
7 3991
"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:ax******** ***********@twi ster.nyroc.rr.c om...
According to the Safari browser the world began on
"Fri Dec 13 1901 15:45:52 GMT-0500", but I need to
be able to get around this limitation.

<snip>

Before getting involved in some strange workaround it would probably be
a good idea to show us how you came to the above, frankly bizarre,
conclusions.

Richard.
Jul 20 '05 #2
Richard Cornford wrote:
Before getting involved in some strange workaround it would probably be
a good idea to show us how you came to the above, frankly bizarre,
conclusions.

Richard.


//Safari
document.write( new Date(1899,0,1))
// output= "Fri Dec 13 1901 15:45:52 GMT-0500"

Genesis, according to Safari 1.2 Mac, was in 1901.
Mick
Jul 20 '05 #3
Mick White <mw******@BOGUS rochester.rr.co m> writes:
I'm trying to create a function that will identify the "type" of year.


function isLeapYear(yr) {
return new Date(yr,2-1,29).getDate() ==29;
}

function getFirstDay(yr) {
return new Date(yr,1-1,1).getDay(); // 0=Sunday...6=Sa turday
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
JRS: In article <ax************ *******@twister .nyroc.rr.com>, seen in
news:comp.lang. javascript, Mick White <mw******@BOGUS rochester.rr.co m>
posted at Sat, 21 Feb 2004 02:39:02 :-
According to the Safari browser the world began on "Fri Dec 13 1901
15:45:52 GMT-0500", but I need to be able to get around this limitation.

Evaluating new Date(-Math.pow(2,31)* 1000)
gives me Fri Dec 13 20:45:52 UTC 1901
which is the same time.

In <URL:http://www.merlyn.demo n.co.uk/critdate.htm> you can read that :
* 1901-12-13 Fri - 20:45:52 is where UNIX should go to from 2038-01-19;
but I have read that systems can show Mon Jan -17 1902,
-03:-14:-08 or 17:00:00.

So it seems that Safari may do date arithmetic using signed 32-bit
time_t, in which case it might fail to go ahead to or past
* 2038-01-19 Tue - 03:14:08 GMT

For both UNIX/C time_t and Javascript, zero is 1970-01-01 00:00:00 GMT.
See what date range
<URL:http://www.merlyn.demo n.co.uk/js-clndr.htm#Ctrls > gives you; it is
programmed for 0100-01-01 to 9999-12-31.

If you can go past 2038, then for Gregorian work just add a multiple of
400 to the year number, since (ignoring Easter) the Gregorian Calendar
repeats every 400 years.

For Julian, since the calendar repeats every 28 years, you can use a
hand-calculated look-up table indexed with Year%28.

Otherwise, you can calculate day-of-week by Zeller's Congruence; see
<URL:http://www.merlyn.demo n.co.uk/zeller-c.htm> and the link to any of
his papers; Gregorian and Julian routines are in
<URL:http://www.merlyn.demo n.co.uk/zel-incl.js>
and visible in <URL:http://www.merlyn.demo n.co.uk/js-nclds.htm>.

I am interested in dates from 1500 to 1901, as far as I can determine,
there are 14 possible calendar variations.

Year starts on Sun, Mon.....
Leap year starts on Sun, Mon..

I can label these early year "types" as a number between 0 and 13.

Let's say 2005 is type 5, and that 1655 is too. (In both years Jan 1
falls on a Saturday)
Gregorian 1655 Jan 1 was a Friday.
Julian 1655 Jan 1 was a Monday.

I'm trying to create a function that will identify the "type" of year.

function getYearType(yea r){

return Number // number between 0 and 13
}

Any suggestions?


Javascript will need assistance for that, since 1500 was a Leap Tear
everywhere that used the Christian Calendar, and 1700 was not Leap in
the British Empire, to which you then belonged. And also because, while
the succession of days of the week was unbroken, eleven days of 1752
were omitted for us. // Be thankful you're not Swedish.
ISTM that the simplest way will be to do something like

X = new Date(Y, 0, 64) // 64th day of year
Week = X.getDay() // 64 = Jan 1 + 9 weeks
Leap = 5 - X.getDate()
Number = Leap*7 + Week

but that uses the Proleptic Gregorian Calendar. For the Julian you'll
need to implement suitable routines.
The following may well set a Date Object from an ISO-8601-style Julian-
Calendar Greenwich date string :

function JCDtoDObj(A) { var Yr, Y, D // A = [Y, M, D]
Yr = +A[0] ; Y = Yr%4 ; D = (Yr-Y)/4 * 1461
return new Date(Date.UTC(2 04+Y, A[1]-1, A[2]-74511+D)) }

function DObjToJCD(DOb) { return '?' } // may be done now, needs test

function JulDatTry() { var DObj, F = document.forms. Frm8
F.GD.value = DObj = JCDtoDObj(F.XX. value.split(/\D+/)) // OK so far
F.QQ.value = DObjToJCD(DObj) }

Testable at foot of <URL:http://www.merlyn.demo n.co.uk/js-tests.htm>, at
least for the meanwhile.

--
© 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 #5
Dr John Stockton wrote:
JRS: In article <ax************ *******@twister .nyroc.rr.com>, seen in
news:comp.lang. javascript, Mick White <mw******@BOGUS rochester.rr.co m>
posted at Sat, 21 Feb 2004 02:39:02 :-

According to the Safari browser the world began on "Fri Dec 13 1901
15:45:52 GMT-0500", but I need to be able to get around this limitation.


Evaluating new Date(-Math.pow(2,31)* 1000)
gives me Fri Dec 13 20:45:52 UTC 1901
which is the same time.

In <URL:http://www.merlyn.demo n.co.uk/critdate.htm> you can read that :
* 1901-12-13 Fri - 20:45:52 is where UNIX should go to from 2038-01-19;
but I have read that systems can show Mon Jan -17 1902,
-03:-14:-08 or 17:00:00.

So it seems that Safari may do date arithmetic using signed 32-bit
time_t, in which case it might fail to go ahead to or past
* 2038-01-19 Tue - 03:14:08 GMT

For both UNIX/C time_t and Javascript, zero is 1970-01-01 00:00:00 GMT.
See what date range
<URL:http://www.merlyn.demo n.co.uk/js-clndr.htm#Ctrls > gives you; it is
programmed for 0100-01-01 to 9999-12-31.

If you can go past 2038, then for Gregorian work just add a multiple of
400 to the year number, since (ignoring Easter) the Gregorian Calendar
repeats every 400 years.

For Julian, since the calendar repeats every 28 years, you can use a
hand-calculated look-up table indexed with Year%28.

Otherwise, you can calculate day-of-week by Zeller's Congruence; see
<URL:http://www.merlyn.demo n.co.uk/zeller-c.htm> and the link to any of
his papers; Gregorian and Julian routines are in
<URL:http://www.merlyn.demo n.co.uk/zel-incl.js>
and visible in <URL:http://www.merlyn.demo n.co.uk/js-nclds.htm>.
I am interested in dates from 1500 to 1901, as far as I can determine,
there are 14 possible calendar variations.

Year starts on Sun, Mon.....
Leap year starts on Sun, Mon..

I can label these early year "types" as a number between 0 and 13.

Let's say 2005 is type 5, and that 1655 is too. (In both years Jan 1
falls on a Saturday)

Gregorian 1655 Jan 1 was a Friday.
Julian 1655 Jan 1 was a Monday.
I'm trying to create a function that will identify the "type" of year.

function getYearType(yea r){

return Number // number between 0 and 13
}

Any suggestions?

Javascript will need assistance for that, since 1500 was a Leap Tear
everywhere that used the Christian Calendar, and 1700 was not Leap in
the British Empire, to which you then belonged. And also because, while
the succession of days of the week was unbroken, eleven days of 1752
were omitted for us. // Be thankful you're not Swedish.
ISTM that the simplest way will be to do something like

X = new Date(Y, 0, 64) // 64th day of year
Week = X.getDay() // 64 = Jan 1 + 9 weeks
Leap = 5 - X.getDate()
Number = Leap*7 + Week

but that uses the Proleptic Gregorian Calendar. For the Julian you'll
need to implement suitable routines.
The following may well set a Date Object from an ISO-8601-style Julian-
Calendar Greenwich date string :

function JCDtoDObj(A) { var Yr, Y, D // A = [Y, M, D]
Yr = +A[0] ; Y = Yr%4 ; D = (Yr-Y)/4 * 1461
return new Date(Date.UTC(2 04+Y, A[1]-1, A[2]-74511+D)) }

function DObjToJCD(DOb) { return '?' } // may be done now, needs test

function JulDatTry() { var DObj, F = document.forms. Frm8
F.GD.value = DObj = JCDtoDObj(F.XX. value.split(/\D+/)) // OK so far
F.QQ.value = DObjToJCD(DObj) }

Testable at foot of <URL:http://www.merlyn.demo n.co.uk/js-tests.htm>, at
least for the meanwhile.


Thanks, John, for the comprehensive answer, I had been taking a
rudimentary approach to Date calculations (Along with your isLeapYear()
function):
http://www.mickweb.com/javascript/da...Functions.html

You have introduced some interesting grist for the meal.
Mick
Jul 20 '05 #6
JRS: In article <65**********@h otpop.com>, seen in
news:comp.lang. javascript, Lasse Reichstein Nielsen <lr*@hotpop.com >
posted at Sat, 21 Feb 2004 16:26:09 :-
Mick White <mw******@BOGUS rochester.rr.co m> writes:
I'm trying to create a function that will identify the "type" of year.


function isLeapYear(yr) {
return new Date(yr,2-1,29).getDate() ==29;
}

function getFirstDay(yr) {
return new Date(yr,1-1,1).getDay(); // 0=Sunday...6=Sa turday
}


Constructing a Date Object must take time, and only one is needed; the
day-of-week of the alleged Feb 29 is 3 mod 7 days after that of Jan 1,
and will suffice of itself or can be converted back to that of Jan 1.

My news server has been down since Saturday evening, which has delayed
posting the above.
The new range of the Greenwich Julian Calendar Date <-> Date Object
conversions includes -4713-01-01, another important chronological date.

Those functions, converted to Date Object Methods, are in the new
version of <URL:http://www.merlyn.demo n.co.uk/js-date8.htm#JCDM> , with
year range exceeding +-1e5. There are two other functions; all seem to
agree. The code needs testing in locations ahead of and behind GMT.

The code which was in js-tests.htm is superseded, and no longer there.

--
© 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> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #7
My news-service was sick from Saturday to Tuesday; the following was
probably not available to Demon users, and possibly not to anyone.
There is some new material after the repeat.
<repeat>

JRS: In article <ax************ *******@twister .nyroc.rr.com>, seen in
news:comp.lang. javascript, Mick White <mw******@BOGUS rochester.rr.co m>
posted at Sat, 21 Feb 2004 02:39:02 :-
According to the Safari browser the world began on "Fri Dec 13 1901
15:45:52 GMT-0500", but I need to be able to get around this limitation.

Evaluating new Date(-Math.pow(2,31)* 1000)
gives me Fri Dec 13 20:45:52 UTC 1901
which is the same time.

In <URL:http://www.merlyn.demo n.co.uk/critdate.htm> you can read that :
* 1901-12-13 Fri - 20:45:52 is where UNIX should go to from 2038-01-19;
but I have read that systems can show Mon Jan -17 1902,
-03:-14:-08 or 17:00:00.

So it seems that Safari may do date arithmetic using signed 32-bit
time_t, in which case it might fail to go ahead to or past
* 2038-01-19 Tue - 03:14:08 GMT

For both UNIX/C time_t and Javascript, zero is 1970-01-01 00:00:00 GMT.
See what date range
<URL:http://www.merlyn.demo n.co.uk/js-clndr.htm#Ctrls > gives you; it is
programmed for 0100-01-01 to 9999-12-31.

If you can go past 2038, then for Gregorian work just add a multiple of
400 to the year number, since (ignoring Easter) the Gregorian Calendar
repeats every 400 years.

For Julian, since the calendar repeats every 28 years, you can use a
hand-calculated look-up table indexed with Year%28.

Otherwise, you can calculate day-of-week by Zeller's Congruence; see
<URL:http://www.merlyn.demo n.co.uk/zeller-c.htm> and the link to any of
his papers; Gregorian and Julian routines are in
<URL:http://www.merlyn.demo n.co.uk/zel-incl.js>
and visible in <URL:http://www.merlyn.demo n.co.uk/js-nclds.htm>.

I am interested in dates from 1500 to 1901, as far as I can determine,
there are 14 possible calendar variations.

Year starts on Sun, Mon.....
Leap year starts on Sun, Mon..

I can label these early year "types" as a number between 0 and 13.

Let's say 2005 is type 5, and that 1655 is too. (In both years Jan 1
falls on a Saturday)
Gregorian 1655 Jan 1 was a Friday.
Julian 1655 Jan 1 was a Monday.

I'm trying to create a function that will identify the "type" of year.

function getYearType(yea r){

return Number // number between 0 and 13
}

Any suggestions?


Javascript will need assistance for that, since 1500 was a Leap Tear
everywhere that used the Christian Calendar, and 1700 was not Leap in
the British Empire, to which you then belonged. And also because, while
the succession of days of the week was unbroken, eleven days of 1752
were omitted for us. // Be thankful you're not Swedish.
ISTM that the simplest way will be to do something like

X = new Date(Y, 0, 64) // 64th day of year
Week = X.getDay() // 64 = Jan 1 + 9 weeks
Leap = 5 - X.getDate()
Number = Leap*7 + Week

but that uses the Proleptic Gregorian Calendar. For the Julian you'll
need to implement suitable routines.
The following may well set a Date Object from an ISO-8601-style Julian-
Calendar Greenwich date string :

function JCDtoDObj(A) { var Yr, Y, D // A = [Y, M, D]
Yr = +A[0] ; Y = Yr%4 ; D = (Yr-Y)/4 * 1461
return new Date(Date.UTC(2 04+Y, A[1]-1, A[2]-74511+D)) }

function DObjToJCD(DOb) { return '?' } // may be done now, needs test

function JulDatTry() { var DObj, F = document.forms. Frm8
F.GD.value = DObj = JCDtoDObj(F.XX. value.split(/\D+/)) // OK so far
F.QQ.value = DObjToJCD(DObj) }

Testable at foot of <URL:http://www.merlyn.demo n.co.uk/js-tests.htm>, at
least for the meanwhile.

</repeat>
// above URL is now <URL:http://www.merlyn.demo n.co.uk/js-date8.htm>
It has always seemed to me a pity that an Object does not invariably
have a Duplicate method, with a parameter for shallow or deep copy.

In particular, one sometimes wants to take a Date Object, and generate
another object representing the same instant and capable of being
fiddled with independently.

ISTM that D2 = new Date(D1) is commonly used for this.

In testing Gregorian <-> Julian date conversions, I got an unexpected
NaN result from such code. Admittedly D1 was 0000-02-29, i.e. BC 1 Feb
29, proleptic Gregorian Astronomical. But the following, executed in
MSIE 4, gives me NaN in the middle result for any date in the important
Year -68..+99 region :

D = new Date(0) ; D.setFullYear(-19,0,29)
x = [D, new Date(D), new Date(+D)]

/* setFullYear seems to do the sensible thing with any year, unlike
setYear, and so is better than new Date(Y, M-1, D). Using new Date(0)
gets midnight, or at least GMT midnight. /*

Of course, many coders don't care about dates so long ago.

However, on considering what is actually happening, ISTM likely that in
new Date(D) D is converted to string, which is re-converted to be
stored in the new Object.

In new Date(+D) ISTM that the unary + is taken as "don't convert to
string" rather than "convert to Number.
Therefore, new Date(+D) seems likely to be quicker than new
Date(D), and test confirm over 10% improvement in my system.
--
© 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 #8

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

Similar topics

13
2235
by: Dr John Stockton | last post by:
Javascript date strings can have a one-letter postfix; it is taken as indicating time zone (not J, which causes NaN). // IIRC, VB accepts A & P in that location, for AM & PM. In my MS IE 4, the object generated by new Date("2001/1/1 0:0:0R") has value meaning Sun Dec 31 19:00:00 UTC 2000. That combination of local time and UTC corresponds, AIUI, to Tashkent and Karachi, in Asia (and not to any US towns of the...
16
2117
by: KL | last post by:
I am working on a problem and desperately need help! I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables to build a date object. Then print the resulting date object, in it's full form. on the screen using document.write. This IS for school and I think I am starting out right, but can't quite seem to grasp what I am doing wrong, or where to go from...
23
3085
by: Ash | last post by:
Hi everyone, This problem has been puzzling me for a fair time now, and has severely frustrated me!! Perhaps I'm just not getting the syntax right, but the problem is rather simple... Take a look at: http://www.gasthofreiner.com/ The small booking form on the left, we're using the same one, but we need to
2
6486
by: Martin Honnen | last post by:
I was playing around with canvas support in recent Safari, Mozilla and Opera (only version 9 preview) but run into issues with Safari related to the very old DOM Level 0 Image object for preloading images. When doing e.g. var img = new Image(); img.onload = function (evt) { alert(this); }; img.src = 'whatever.gif';
4
2312
by: zoookapi | last post by:
I'm attempting to dynamically add a link so I can take a mouseover action on it and am having problems in Safari (this works fine in Firefox and IE (Windows version of IE)). When I add the img object it shows fine, but when I try to contain it within a link, it does not display. I've tried using the IE and non-IE method below but neither seem to work. Is this a bug in Safari or is there a different way to achieve this? I was testing with...
9
1922
by: Cylix | last post by:
The following example are going to create an object to store the client Information, I would like to new the object to init all the properties by function: setProperty() Can I set the value to the object without using the global variable ? Thank you. ///---------------The object ------------------------------- function clientENV {
2
1923
by: ipy2006 | last post by:
Only in Safari browser the current year shows as 1970. Also "Non digits found in year" is triggered in the Safari broswer. Please help. Thanks, Yasaswi function verifyYear( field ) { var _x = field.value; var _exp = new RegExp(/^\d+$/);
3
1536
by: gg9h0st | last post by:
function aa() {}; var bb = new aa(); var dd = new function cc() {}; aa.prototype.rr = 100; cc.prototype.rr = 100; ---------------------------------------------------------------
12
2689
by: jodishowers | last post by:
Greetings all. My 1st post here - hoping someone can help out. First I've tested this on FF 1.5.0.9, 2.x and Safari on OSX. here's the code that exhibits the behaviour: #case 1 - fails var date1 = new Date(); date1.setYear(2007); date1.setMonth(3);
0
9666
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
10408
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
10199
jinu1996
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...
0
9983
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
9020
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
7529
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
5417
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...
1
4092
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
3
2909
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.