note 70031 modified in function.date-sunset by danbrown

From: Date: Sun, 20 Jul 2008 02:36:39 +0000
Subject: note 70031 modified in function.date-sunset by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-141971@lists.php.net to get a copy of this message
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. <?php 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"; } ?> --was-- 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"; } ?> http://php.net/manual/en/function.date-sunset.php

« previous php.notes (#141971) next »