Replies: 8 comments 3 replies
-
|
No they don't. I was looking for this some time ago when I was putting together my app. I was working in Javascript so I used https://github.com/mourner/suncalc to get that data. It's a fairly easy integration since you're either searching by Lat/Lon, or can get the Lat/Lon from one of the API calls and then pass that to the suncalc library to get sunrise and sunset. |
Beta Was this translation helpful? Give feedback.
-
|
Correct, it's not something we currently expose. We do actually calculate it internally, because it's needed for some metadata bits on the forecast and observation endpoints, but we don't output the actual times anywhere. I'm honestly not really sure where it would fit. Maybe a whole new endpoint. Suggestions welcome. |
Beta Was this translation helpful? Give feedback.
-
|
Perhaps in the daily forecast endpoint? Seems like it might make sense there. |
Beta Was this translation helpful? Give feedback.
-
|
Maybe, but the forecast isn't actually daily, it's semi-daily (12-hour periods, 6-6), and sunrise/sunset don't always fit neatly into those boxes, especially as we get around the solstices. And don't even get me started on Alaska. Still, it's something we'll try to think about. |
Beta Was this translation helpful? Give feedback.
-
|
Has this been turned into a formal feature request? I'd like to see this additional functionality as well. Where ever it goes it would be nice to have the sunrise/sunset for the days available in the forecast. |
Beta Was this translation helpful? Give feedback.
-
|
Hi there, So I take it that this has not been added/exposed yet? I think this could easily be included in the It already includes all kinds of other info/data. It includes an {
"properties": {
"validTimes": "2025-02-01T14:00:00+00:00/P7DT11H",
"sunData": {
"0": {
"sunrise": "2025-02-01T06:46:00",
"sunset": "2025-02-01T17:22:00",
"validDate": "2025-02-01"
},
"1": {
"sunrise": "2025-02-01T06:50:00",
"sunset": "2025-02-01T17:26:00",
"validDate": "2025-02-02"
}
}
}
}I think this is the best place for it since there is all sorts of other data there, and this would be similar to how all the other data is exposed. Just an idea. UPDATE: I was just thinking that {
"properties": {
"validTimes": "2025-02-01T14:00:00+00:00/P7DT11H",
"astronomicalData": {
"0": {
"sunrise": "2025-02-01T06:46:00",
"sunset": "2025-02-01T17:22:00",
"validDate": "2025-02-01",
"moonrise": "2025-02-01T08:52:00",
"moonset": "2025-02-01T21:13:00"
},
"1": {
"sunrise": "2025-02-01T06:50:00",
"sunset": "2025-02-01T17:26:00",
"validDate": "2025-02-02",
"moonrise": "2025-02-01T09:21:00",
"moonset": "2025-02-01T22:21:00"
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
|
This is what I wrote up many years ago in PHP. It doesn't have a return type on the classes, so you know it's been a REALLY long time since I've touched this code. namespace Whatever;
use \DateTimeInterface as DateTimeInterface;
class DateTime extends \DateTime
{
/**
* Sunrise
*
* Returns time of sunrise for a given day and location.
*
* @param DateTime $timestamp If not set assumes this instance, otherwise must be a DateTime object.
* @param float $latitude Defaults to North, pass in a negative value for South. See also: date.default_latitude.
* @param float $longitude Defaults to East, pass in a negative value for West. See also: date.default_longitude.
* @param float $zenith Default: date.sunrise_zenith
* @param float $gmt_offset Specified in hours.
* @return Returns the sunrise time in a specified format on success or FALSE on failure.
*/
public function sunrise(DateTimeInterface $timestamp = null, float $latitude = null, float $longitude = null, float $zenith = null, float $gmt_offset = null)
{
$timestamp = ($timestamp) ? $timestamp->format('U') : $this->format('U');
$latitude = ($latitude) ?: ini_get("date.default_latitude");
$longitude = ($longitude) ?: ini_get("date.default_longitude");
$zenith = ($zenith) ?: ini_get("date.sunrise_zenith");
$return = date_sunrise($timestamp, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith, $gmt_offset);
return ($return) ? (new DateTime())->setTimestamp($return) : false;
}
/**
* Sunset
*
* Returns time of sunset for a given day and location.
*
* @param DateTime $timestamp If not set assumes this instance, otherwise must be a DateTime object.
* @param float $latitude Defaults to North, pass in a negative value for South. See also: date.default_latitude.
* @param float $longitude Defaults to East, pass in a negative value for West. See also: date.default_longitude.
* @param float $zenith Default: date.sunrise_zenith
* @param float $gmt_offset Specified in hours.
* @return Returns the sunset time in a specified format on success or FALSE on failure.
*/
public function sunset(DateTimeInterface $timestamp = null, float $latitude = null, float $longitude = null, float $zenith = null, float $gmt_offset = null)
{
$timestamp = ($timestamp) ? $timestamp->format('U') : $this->format('U');
$latitude = ($latitude) ?: ini_get("date.default_latitude");
$longitude = ($longitude) ?: ini_get("date.default_longitude");
$zenith = ($zenith) ?: ini_get("date.sunrise_zenith");
$return = date_sunset($timestamp, SUNFUNCS_RET_TIMESTAMP, $latitude, $longitude, $zenith, $gmt_offset);
return ($return) ? (new DateTime())->setTimestamp($return) : false;
}
/**
* Sun Info
*
* Returns an array with information about sunset / sunrise and twilight begin / end
*
* @param DateTime $timestamp If not set assumes this instance, otherwise must be a DateTime object.
* @param float $latitude Defaults to North, pass in a negative value for South. See also: date.default_latitude.
* @param float $longitude Defaults to East, pass in a negative value for West. See also: date.default_longitude.
* @return Returns array on success or FALSE on failure.
*/
public function sunInfo(DateTimeInterface $timestamp = null, float $latitude = null, float $longitude = null)
{
$timestamp = ($timestamp) ? $timestamp->format('U') : $this->format('U');
$latitude = ($latitude) ?: ini_get("date.default_latitude");
$longitude = ($longitude) ?: ini_get("date.default_longitude");
return date_sun_info($timestamp, $latitude, $longitude);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
I'll plus one, I currently retrieve that from |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Do any of the API endpoints provide the Sunset and Sunrise time for that day?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions