Skip to content

Commit 56a1f29

Browse files
committed
fix issue #180
1 parent 5521cf4 commit 56a1f29

File tree

3 files changed

+82
-11
lines changed

3 files changed

+82
-11
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* new option `keep_timestamp` in `regularize_vpts()`, which allows individual profiles to keep there original timestamp instead of the timestamp of the regularized grid
66

7+
* improved documentation of sunrise/sunset functions (#180) and new option `force_tz` (4968019)
8+
79
# bioRad 0.5.1
810

911
Minor bugfixes. All issues included in this release can be found [here](https://github.com/adokter/bioRad/pull/334). This release primarily fixes a bug that will become effective once R version 4.0 is released.

R/sunrise_sunset.R

+41-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
#' @return The moment of sunrise or sunset for the date set by \code{date}and time zone as specified
1414
#' (by \code{date} and \code{tz}) or in UTC if not specified.
1515
#'
16-
#' @details The angular diameter of the sun is about 0.536 degrees,
16+
#' @details
17+
#' The day for which sunrise and sunset are calcuated is given by the input date.
18+
#' Sunrise and sunset are calculated relative to the moment of solar noon for that date,
19+
#' i.e. the first sunrise before the moment of solar noon, and the first sunset after the
20+
#' moment of solar noon. Therefore, depending on the timezone provided, it is possible that
21+
#' the nearest sunrise prior to solar noon occurs a day earlier than the input date.
22+
#' Similarly, sunset may occur a day later than the input date. See examples for details.
23+
#'
24+
#' The angular diameter of the sun is about 0.536 degrees,
1725
#' therefore the moment of sunrise/sunset corresponds to half that elevation
1826
#' at -0.268 degrees.
1927
#'
@@ -22,9 +30,6 @@
2230
#' Approximate astronomical formula are used, therefore the moment of
2331
#' sunrise / sunset may be off by a few minutes
2432
#'
25-
#' Sunrise and sunset is given for the day specified by \code{date}, with sunset always
26-
#' later than sunrise given the same \code{date}.
27-
#'
2833
#' If \code{force_tz} is \code{TRUE}, the input date is converted to the timezone
2934
#' set by \code{tz} prior to calculating the sunrise/sunset time, resulting in a shift by +/-1 day
3035
#'
@@ -35,8 +40,38 @@
3540
#' # sunset in the Netherlands
3641
#' sunset("2016-01-01", 5, 53)
3742
#'
38-
#' # civil twilight in Ithaca, NY, today
39-
#' sunrise(Sys.time(), -76.5, 42.4, elev = -6)
43+
#' # civil twilight in Ithaca, NY
44+
#' sunrise("2016-01-01", -76.5, 42.4, elev = -6)
45+
#'
46+
#' # next sunset in South Dakota, USA
47+
#' sunset("2016-11-15", -98, 45)
48+
#'
49+
#' # Beware that some days have two sunsets, or
50+
#' # two sunrises! E.g. on 5 Oct (local timezone) at
51+
#' # this location sunset is actually on the 6 Oct
52+
#' # in UTC time zone, i.e. the next day
53+
#' sunset("2016-10-5", -98, 45)
54+
#' # One day later, sunset is again on 6 Oct:
55+
#' sunset("2016-10-6", -98, 45)
56+
#'
57+
#' # working in local time zones typically avoids such ambiguities:
58+
#' sunset(as_datetime("2016-06-05",tz="America/Chicago"), -98, 45)
59+
#' sunset(as_datetime("2016-06-06",tz="America/Chicago"), -98, 45)
60+
#'
61+
#' # use force_tz to force output to a specific time zone, by default UTC:
62+
#' sunset(as_datetime("2016-06-05",tz="America/Chicago"), -98, 45, force_tz=T)
63+
#' sunset(as_datetime("2016-06-06",tz="America/Chicago"), -98, 45, force_tz=T)
64+
#'
65+
#' # Also beware of jumps in sunrise and sunset date with longitude:
66+
#' sunrise("2016-11-01", 100, 45)
67+
#' sunrise("2016-11-01", 102, 45)
68+
#'
69+
#' # sunrise date can even be two days earlier in specific cases:
70+
#' # e.g. "2016-10-31 00:00" in Asia/Ulaanbaatar time zone is converted to
71+
#' # 2016-10-30 16:00 UTC when force_tz=TRUE. Solar noon on 2016-10-30 at this
72+
#' location in Mongolia is at 04:55 UTC, and the first sunrise prior to this
73+
#' is on 2016-10-29:
74+
#' sunrise(as_datetime("2016-10-31",tz="Asia/Ulaanbaatar"), 120, 45, tz="UTC", force_tz=T)
4075
#' @name sunrise_sunset
4176
NULL
4277

man/sunrise_sunset.Rd

+39-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)