Created
March 17, 2021 16:12
-
-
Save jnolis/e3ba8f786527a4ba17c9a9b7997c55e6 to your computer and use it in GitHub Desktop.
Get the sunrise and sunset times for one location on one day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_sunrise_sunset <- function(lat,long, date, tz){ | |
# tz is required to know when daylight savings happens | |
response <- httr::GET(glue::glue("https://api.sunrise-sunset.org/json?lat={lat}&lng={long}&date={date}&formatted=0")) | |
results <- httr::content(response)$results | |
results[["day_length"]] <- NULL | |
results <- lapply(results, function(x) as.POSIXct(x,format="%Y-%m-%dT%T",tz="UTC")) | |
results <- lapply(results, function(x) lubridate::with_tz(x, tzone = tz)) | |
results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment