• bvs23bkv33 (unregistered)

    If 0 < comment < 1 return first;

  • Adriano (unregistered)

    "Hey Bob, What do I do with Canada, Mexico, Peru, Chile, Argentina, Colombia, Ecuador, Bolivia, Venezuela, all of Central America? This list is getting long" "Just chuck them in with the USA." "Ok. And... What do I do with Alaska?" "WE DO NOT TALK ABOUT ALASKA."

  • touchstone (unregistered)

    0.0655737704918 is 1/15.25 (instead of 1/15 which would be correct). This would result from a 366 degree circle... A typo, perhaps?

  • Nope (unregistered)

    24 ÷ 366 ≈ 0.0655737704918

  • (nodebb)

    And of course the "divide longitude by 15 and apply banker's rounding" is only approximate and it's wrong for much of Europe. In fact, it returns a notional timezone estimate of -1 for the extreme north-west of Spain, where the timezone is CE(S)T, i.e. +1/+2.

    No, guys, the only way to get this right is to ask the gdmf client. He knows where he is(1), and the Internet, as such, does not.

    (1) More to the point, perhaps, he knows in which country he lives, and that might not be the one from which his connection comes. (Example: if I'm on my phone or my tablet, and I'm nearer than a certain distance to the border with REDACTED, I may find it switching over to use a 4G network in [REDACTED], and then my packets will look like I'm there when I'm not.)

    (2) Douglas Adams was quite clear that the name of this country is, in fact, a very, very rude word.

  • Little Bobby Tables (unregistered) in reply to touchstone

    The constant is clearly calculated from a leap longitude.

  • Zug (unregistered)

    The appearance of 366 suggests that it was written to cope with leap-years. :^)

  • ray10k (unregistered)

    Given the neat, flat rectangles this code looks for, I'd almost think this was written by a flat-earther.

  • Stephen (unregistered) in reply to Adriano

    Longitude. So wouldn't the joke be "France, Turkey, China, Japan"? ;>

  • Chronomium (unregistered)

    Honestly, this isn't all that bad. If all you need is a general ballparking, rather than exact accuracy, this is probably good enough and easy to understand. In fact, if this creates a default for the user to select their own location/timezone afterward, it's quite good.

    It's like significant figures. Don't measure down to the thousandths if you only need tenths.

  • Brian Boorman (google)

    In all fairness, if the users of the application are just people in the company's office locations (and not the general internet population), and the company only has offices in GB, US, IN, and AU, then this gross country location algorithm may be all that's necessary.

    Is it elegant? No. Is it extensible? Not really. Does it need to be? Maybe not.

  • mike (unregistered)

    And triangles, surely

  • Dave (unregistered) in reply to Brian Boorman

    "In all fairness, if the users of the application are just people in the company's office locations (and not the general internet population), and the company only has offices in GB, US, IN, and AU, then this gross country location algorithm may be all that's necessary."

    In that situation, if you add in remote workers who are possibly in nearby countries, it may well be that the desired behaviour is to group them all under the four categories - if Bob is working in Amsterdam instead of London today, they still want his work timestamped with the UK time, for example.

  • (nodebb) in reply to Brian Boorman

    Similarly, the way timezone boundaries zig and zag all over the place, the incorrect multiplier is probably just as likely to be correct. Maybe the programmer even tweaked it because the "correct" multiplier was giving wrong answers for their office locations.

    OTOH, if this is just intended for their offices, TRWTF is using longitude at all. They probably could have just used IP address ranges.

  • Supersonic Tumbleweed (unregistered)

    TRWTF is web programming in Python

  • I dunno LOL ¯\(°_o)/¯ (unregistered)

    How many languages even support "A < B < C" anyhow? That's TRWTF here.

    But I'm glad to know that the US now owns Mexico and Canada. And Hawaii says "HI".

  • siciac (unregistered)

    I've done this. Had a mess of data geolocated from US addresses and I wanted a sanity check, so I figured out the lat/long bounds for the continental US and filtered it for coordinates falling outside the box. A mess of Illinois addresses in the Pacific was enough to embarrass the geolocation team.

  • mihi (unregistered)

    https://github.com/evansiroky/timezone-boundary-builder

    See releases for a precompiled shapefile.

  • (nodebb) in reply to Barry Margolin

    Unless they're also accounting for employees connecting from home.

  • (nodebb) in reply to Chronomium

    It's like significant figures. Don't measure down to the thousandths if you only need tenths.

    Beware of the difference between "significant figures" and "decimal places". After all, I can estimate your height "to the nearest thousandth" as a thousandth of a mile(1), and with very few exceptions(2), I'll be right, but it's only one significant figure.

    (1) Credit for this one has to be left to my high school Physics teacher who used it to drive home a very clear message about significant figures versus decimal places. "You, stand up! I'm going to estimate your height to the nearest thousandth..." Squints. "A thousandth of a mile."

    (2) Anyone between the heights of 2.64 feet = just taller than 2'7" and 7.92 feet = about 7'11". The very tallest adults ever topped eight feet, but there have been very few of them over the course of history.

  • Sole Reason For Visit (unregistered) in reply to Barry Margolin

    As a matter of fact, using IP ranges would be an even worse solution. Ranges are allocated in blocks, and part of those blocks go "astray" in interesting ways. Mostly, I presume, because large companies grab a big block and then distribute it as they see fit. But the result is, you could actually pick the wrong hemisphere based upon an IP range.

    From memory, I believe Bing uses IP ranges as the third most trustworthy indicator of location (obvious accurate ones like GPS not being available). I think this is common to all major IT companies, and I think, like Bing, they do their best to cross-reference against other potential sources.

    Of course, for the present requirements, the programmer could just have downloaded TimezoneDB, But that wouldn't have been nearly as much ... what the fun.

  • (nodebb)

    I was working on a program that needed to calculate intersections of lines on the earth. Some of these are described as latitude lines and great circle paths. Sometimes you can have TWO intersections of a line of latitude and a great circle route (you need to be special about this). Since the calculation with proper great circle paths was "expensive", I used a calculation based on a Mercator projection (weird squares and the like), and if that happened (an easy calculation), I went ahead and did it the more complicated way. Most of the time the two paths didn't intersect, so it was better that way.

    Of course I did this as the last part of a contract position, and they didn't understand what I had done, and threw out the code I had worked very carefully on. Oh, well. I got paid none the less, and life goes on. It was about 10 years ago.

  • Adam P. Goucher (unregistered)

    Using RIES, I get the following output:

    $ ./ries -l4 0.0655737704918

    Your target value: T = 0.0655737704918 mrob.com/ries

                  ln(x) = -e                     for x = T + 0.000414265 {51}
         cospi(sqrt(x)) = ln(2)                  for x = T + 7.6755e-05  {63}
                1/(3 x) = pi phi                 for x = T + 1.67238e-06 {77}
                   3"/x = cospi(1/e)             for x = T + 4.27421e-07 {73}
                1/x-1/4 = 3*5                    for x = T + 3.28904e-15 {86}
                4*1/x+3 = (sqrt(2)^6)^2          for x = T + 3.21965e-15 {116}
            1/(1/x+5)+1 = (2/9)^2+1              for x = T + 3.13638e-15 {124}
         sinpi(1/(x+2)) = cospi(1/(7*9))         for x = T + 3.02536e-15 {113}
           1/(4(1/x+5)) = ln((9^2)"/e)           for x = T + 2.69229e-15 {134}
            1/(1/x-3)+8 = (2/7)^2+8              for x = T + 2.28983e-15 {140}
                  (for more results, use the option '-l5')
    

    The remarkably simple one that agrees to within double-precision machine epsilon, namely 1/x-1/4 = 3*5, gives a value of x = 4 / 61. Why exactly they chose that is a mystery to me.

  • Decius (unregistered) in reply to herby

    Almost all of the lines of latitude that a great circle intersects will be intersected twice. Each great circle other than the equator has two lines of latitude that it intersects only once (counting 90 north and 90 south count as "lines of latitude" despite having zero arc length).

  • (nodebb) in reply to Chronomium

    Or they could just use the free GeoLite2 country database, which maps IP addresses to countries and is available as a CSV file.

  • JustSayin' (unregistered)

    BTW, if you make user select from a pulldown of 200+ countries, you deserve to be kicked in the genitals with steel toe construction boot (especially if USA is somewhere around Uganda and Uruguay) If you make the user select their state, still same applies. It doesn't matter that there are only 50. Pull down menus are awful if they have more than 10 rows. Use a freaking text field with autocomplete!!! Thanks for listintening.

Leave a comment on “Rectangle Marks The Spot”

Log In or post as a guest

Replying to comment #498898:

« Return to Article