Re: Complicated Date to Lat Reverse function



JRS: In article <1136912794.590558.264570@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
, dated Tue, 10 Jan 2006 09:06:34 local, seen in
news:comp.lang.javascript, jshanman <jcshanks@xxxxxxxxxxxxx> posted :
>I am writing a timeline that uses Google Maps. I have a function that
>converts a date time to latitude coords. This function is used to draw
>the markers on the timeline. I need a reverse function to convert a
>latitude coord back to an accurate date time. Then I could detect the
>day/hour in the viewport when the timeline is zoomed in or out, or if
>it is moved. I cannot use the javascript date functions because this
>timeline will eventually be used for BC and AD years.

Javascript dates have a span of +-10^8 days from 1970-01-01.0 GMT.
That's more than a quarter of a million years each side of Year Zero.

Before posting, you should read the newsgroup FAQ; see below.

>The map is accurate until zoom level 6
>http://www.wwcompclub.org/worldwar/wiki/map.php?year=1865
>
>Also, the add event and edit event forms don't work, so don't bother
>trying.
>
>Days[][] is an array of each month containing the number of days in
>each month.
>So
>Days[1].length = 31;
>And
>Days[1][30] = "31st";

Unnecessary. Suffices and month-length can easily be computed.


> HourConst = 0.00035673379898071291666666666666667;

It's not clear what that might be, or whether it is correctly entered.
It should be entered as a self-explanatory expression, and calculated
once.

> byear = 1808;
> ayear = 1922;
>
>function isLeapYear(year) { //this function seems to work OK
> yr = parseInt(year);

If year happens to be a string with a leading zero, that will give a
wrong result. If it's a string without, unary + is better. If it's a
number, parseInt should force conversion to string and back. Never use
parseInt or parseFloat when it's not necessary; never use parseInt with
only one parameter unless you can prove it safe to do so.

> if (yr % 4 != 0) return false;
> else if (yr % 400 == 0) return true;
> else if (yr % 100 == 0) return false;
> else return false;
>}

The difference in speed will be imperceptible; but for efficiency the
100 test should precede the 400 test. However, I doubt whether the
function is really needed.

// Consider: Leap = !new Date(year, 0, 31+366).getMonth()


The rest looks as bad; but your actual intentions are not clear.



Before writing in a language, you should read about it.



If latitude is to be linearly dependent on absolute time Y M D h m s ms,

Lat = A + B*new Date(Y, M-1, D, h, m, s, ms)
DOb = new Date((Lat-A)/B)
where A is the Lat for 1970.0 GMT and B is something like 180/1e13 or
smaller; DOb is a Date Object.

Note that the above may have a small error, depending on the location of
the browser. Use, instead, IIRC,
A + B*new Date(Date.UTC(Y, M-1, D, h, m, s, ms))
and the UTC functions to expand DOb, and there'll be no need to worry.
Also it will execute faster. Unless you want linear dependence on
browser's *civil* time.

That will, of course, use Proleptic Astronomical Gregorian dates; but
you can find Julian <-> Gregorian conversion (via below).

Do not, of course, use getYear, unless you must allow for browsers
without getFullYear in which case use it only in function getFY (").

You may need to trap first-centade years; add 400 years and subtract
4800 months. Or don't test, and +120000 -1440000 if you can accept the
range limitation.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.



Relevant Pages

  • Javascript Latitude to Date function
    ... I am writing a timeline that uses Google Maps. ... converts a date time to latitude coords. ... RelYear = syear - byear; ...
    (sci.math.num-analysis)
  • Complicated Date to Lat Reverse function
    ... I am writing a timeline that uses Google Maps. ... converts a date time to latitude coords. ... RelYear = syear - byear; ...
    (comp.lang.javascript)
  • Re: Not master documents (MSWord + bonus OO.org question)
    ... it's WRITING. ... of my own head. ... I also did a timeline, to make sure that various statements about what ... happened when in the past were consistent with each other, ...
    (rec.arts.sf.composition)
  • Re: Complicated Date to Lat Reverse function
    ... >I am writing a timeline that uses Google Maps. ... >converts a date time to latitude coords. ... Calculate the position of an instrument that logs light or dark with a ... This is a real project that we did some years ago for an instrument ...
    (comp.lang.javascript)
  • Re: Question about "the Gros Venure" as mentioned by Aubrey
    ... But I'm arguing that it's not predestined by God, ... could have chosen to buy apples instead of bananas at the supermarket. ... I'm writing the lines and following the lines at the same time: ... Now, outside and not touching that timeline, add a God who can see the ...
    (rec.arts.sf.composition)

Loading