powered by
Calculates approximate times of sunrise and sunset and day lengths for given dates at given locations.
get_suntimes( date, lat, lon, offset, ..., tryFormats = c("%Y-%m-%d %H:%M:%OS", "%Y/%m/%d %H:%M:%OS", "%Y:%m:%d %H:%M:%OS", "%Y-%m-%d %H:%M", "%Y/%m/%d %H:%M", "%Y:%m:%d %H:%M", "%Y-%m-%d", "%Y/%m/%d", "%Y:%m:%d") )
A dataframe with columns sunrise and sunset (given in the timezone defined by offset) and daylength, all expressed in hours.
character, POSIX or Date format date/time value(s)
latitude and longitude in decimal degrees
the time offset in hours relative to UTC (GMT) for results
arguments passed to as.POSIXlt
formats to try when converting date from character, passed to as.POSIXlt
Function adapted from https://www.r-bloggers.com/2014/09/seeing-the-daylight-with-r/
Teets, D.A. 2003. Predicting sunrise and sunset times. The College Mathematics Journal 34(4):317-321.
data(BCItime) dat <- subset(BCItime, species=="ocelot")$date get_suntimes(dat, 9.156335, -79.847682, -5)
Run the code above in your browser using DataLab