By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 429,426 Members | 1,729 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,426 IT Pros & Developers. It's quick & easy.

Date () object in Safari .

 P: n/a 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(year){ return Number // number between 0 and 13 } Any suggestions? Mick Jul 20 '05 #1
Share this Question
7 Replies

 P: n/a "Mick White" wrote in message news:ax*******************@twister.nyroc.rr.com...According to the Safari browser the world began on"Fri Dec 13 1901 15:45:52 GMT-0500", but I need tobe able to get around this limitation. 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

 P: n/a 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

 P: n/a Mick White 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=Saturday } /L -- Lasse Reichstein Nielsen - lr*@hotpop.com DHTML Death Colors: 'Faith without judgement merely degrades the spirit divine.' Jul 20 '05 #4

 P: n/a JRS: In article , seen in news:comp.lang.javascript, Mick White posted at Sat, 21 Feb 2004 02:39:02 :- According to the Safari browser the world began on "Fri Dec 13 190115: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 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 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 and the link to any of his papers; Gregorian and Julian routines are in and visible in . 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 1falls 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(year){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(204+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 , at least for the meanwhile. -- © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. © Web - w. FAQish topics, links, acronyms PAS EXE etc : - see 00index.htm Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc. Jul 20 '05 #5

 P: n/a Dr John Stockton wrote: JRS: In article , seen in news:comp.lang.javascript, Mick White posted at Sat, 21 Feb 2004 02:39:02 :-According to the Safari browser the world began on "Fri Dec 13 190115: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 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 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 and the link to any of his papers; Gregorian and Julian routines are in and visible in . 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 1falls 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(year){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(204+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 , 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

 P: n/a JRS: In article <65**********@hotpop.com>, seen in news:comp.lang.javascript, Lasse Reichstein Nielsen posted at Sat, 21 Feb 2004 16:26:09 :-Mick White 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=Saturday} 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 , 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 © Jim Ley's FAQ for news:comp.lang.javascript jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links. Jul 20 '05 #7

 P: n/a 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. JRS: In article , seen in news:comp.lang.javascript, Mick White 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 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 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 and the link to any of his papers; Gregorian and Julian routines are in and visible in . 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(year){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(204+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 , at least for the meanwhile. // above URL is now 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 - w. FAQish topics, links, acronyms PAS EXE etc : - see 00index.htm Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc. Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.