get_suntimes: Calculates solar event times

View source: R/activity_code.r

get_suntimesR Documentation

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

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/

Value

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

References

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

Examples

data(BCItime)
dat <- subset(BCItime, species=="ocelot")$date
get_suntimes(dat, 9.156335, -79.847682, -5)

activity documentation built on Sept. 27, 2023, 9:08 a.m.