List Info

Thread: note 70031 added to function.date-sunset




note 70031 added to function.date-sunset
user name
2006-09-30 12:17:50
I use an IP to location database to determine the visitor's
approximate latitude and longitude and then serve them a day
or night color scheme based on whether it is before civil
dawn or dusk. I've had problems when not specifying the
timezone, specifically a 1 hour error, so I use GMT.

<?
date_default_timezone_set("GMT");

function scheme() {
        $sunrise = date_sunrise(time(), SUNFUNCS_RET_DOUBLE,
$latitude, $longitude, 96, 0);
        $sunset = date_sunset(time(), SUNFUNCS_RET_DOUBLE,
$latitude, $longitude, 96, 0);
        $now = date("H") + date("i") /
60 + date("s") / 3600;

        if ($sunrise < $sunset)
                if (($now > $sunrise) && ($now
< $sunset)) return "day";
                else return "night";
        else
                if (($now > $sunrise) || ($now <
$sunset)) return "day";
                else return "night";
}
?>
----
Server IP: 194.153.94.10
Probable Submitter: 86.108.85.74
----
Manual Page -- http://www.php.net/manual/en/function.date-sunset.php
Edit        -- https://master
.php.net/note/edit/70031
Del: integrated  -- h
ttps://master.php.net/note/delete/70031/integrated
Del: useless     -- http
s://master.php.net/note/delete/70031/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/70031/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/70031/spam
Del: non-english -- 
https://master.php.net/note/delete/70031/non-english
Del: in docs     -- http
s://master.php.net/note/delete/70031/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/70031
Reject      -- https://mast
er.php.net/note/reject/70031
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )