Skip to content

Commit

Permalink
Use a different offset for readability, clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Dec 23, 2024
1 parent eeee004 commit 887a471
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,34 +168,34 @@ get_age <- function(birthdays, ref_dates) {
stopifnot(inherits(birthdays, "Date"), inherits(ref_dates, "Date"))
# NB: Strips fractional day parts
birthdays_unix <- as.integer(birthdays)
days_in_unix_quadrennium <- birthdays_unix %% 1461L
days_after_feb29 <- (birthdays_unix - 790L) %% 1461L
ref_dates_unix <- as.integer(ref_dates)
# days in current quadrennium _of life_, i.e. relative quadrennial date
rem = (ref_dates_unix - birthdays_unix) %% 1461L
# Use double-fcase() for #18, though earlier this used double-foverlaps()
# and could also easily use double-findInterval().
# nolint start: indentation_linter, spaces_left_parentheses_linter.
extra_part = fcase(
days_in_unix_quadrennium < 59L | days_in_unix_quadrennium >= 1155L,
days_after_feb29 < 365L,
fcase(rem < 365L, 0.0+(rem- 0.0)/365.0,
rem < 730L, 1.0+(rem- 365.0)/365.0,
rem < 1095L, 2.0+(rem- 730.0)/365.0,
rem < 1461L, 3.0+(rem-1095.0)/366.0),
days_after_feb29 < 730L,
fcase(rem < 365L, 0.0+(rem- 0.0)/365.0,
rem < 730L, 1.0+(rem- 365.0)/365.0,
rem < 1096L, 2.0+(rem- 730.0)/366.0,
rem < 1461L, 3.0+(rem-1096.0)/365.0),
days_in_unix_quadrennium < 424L,
days_after_feb29 < 1095L,
fcase(rem < 365L, 0.0+(rem- 0.0)/365.0,
rem < 731L, 1.0+(rem- 365.0)/366.0,
rem < 1096L, 2.0+(rem- 731.0)/365.0,
rem < 1461L, 3.0+(rem-1096.0)/365.0),
days_in_unix_quadrennium < 790L,
days_after_feb29 < 1461L, # TODO: use default=. Just let vector default bake longer.
fcase(rem < 366L, 0.0+(rem- 0.0)/366.0,
rem < 731L, 1.0+(rem- 366.0)/365.0,
rem < 1096L, 2.0+(rem- 731.0)/365.0,
rem < 1461L, 3.0+(rem-1096.0)/365.0),
days_in_unix_quadrennium < 1155L,
fcase(rem < 365L, 0.0+(rem- 0.0)/365.0,
rem < 730L, 1.0+(rem- 365.0)/365.0,
rem < 1095L, 2.0+(rem- 730.0)/365.0,
rem < 1461L, 3.0+(rem-1095.0)/366.0)
)

Check warning on line 199 in R/utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/utils.R,line=199,col=3,[missing_argument_linter] Missing argument 9 in function call.
# nolint end.
4.0 * ((ref_dates_unix - birthdays_unix) %/% 1461.0) + extra_part
Expand Down

0 comments on commit 887a471

Please sign in to comment.