Learn R Programming

activity (version 1.3.4)

get_suntimes: Calculates solar event times

Description

Calculates approximate times of sunrise and sunset and day lengths for given dates at given locations.

Usage

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")
)

Value

A dataframe with columns sunrise and sunset (given in the timezone defined by offset) and daylength, all expressed in hours.

Arguments

date

character, POSIX or Date format date/time value(s)

lat, lon

latitude and longitude in decimal degrees

offset

the time offset in hours relative to UTC (GMT) for results

...

arguments passed to as.POSIXlt

tryFormats

formats to try when converting date from character, passed to as.POSIXlt

Details

Function adapted from https://www.r-bloggers.com/2014/09/seeing-the-daylight-with-r/

References

Teets, D.A. 2003. Predicting sunrise and sunset times. The College Mathematics Journal 34(4):317-321.

Examples

Run this code
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