citHeader("To cite stepmetrics in publications, please use:")

vers <- meta$Version
year <- local({
  if (!is.null(meta[["Date/Publication"]])) {
    as.character(as.POSIXlt(meta[["Date/Publication"]], tz = "UTC")$year + 1900)
  } else if (!is.null(meta$Date)) {
    as.character(as.POSIXlt(meta$Date, tz = "UTC")$year + 1900)
  } else if (!is.null(meta$Packaged)) {
    pkgd <- sub(" .*", "", meta$Packaged)
    as.character(as.POSIXlt(pkgd, tz = "UTC")$year + 1900)
  } else {
    format(Sys.Date(), "%Y")
  }
})

doi <- "10.5281/zenodo.7858094"

bib <- bibentry(
  bibtype  = "Manual",
  title    = "stepmetrics: Calculate Step and Cadence Metrics from Wearable Data",
  author   = person(given = "Jairo H", family = "Migueles",
                    email = "jairo@jhmigueles.com", role = c("aut", "cre")),
  year     = year,
  note     = paste("R package version", vers),
  url      = "https://github.com/jhmigueles/stepmetrics"
)

# Add DOI if present
if (!is.null(doi) && nzchar(doi)) {
  bib$doi <- doi
}

# Add a human-readable text version
bib$textVersion <- sprintf(
  "Migueles JH (%s). stepmetrics: Calculate Step and Cadence Metrics from Wearable Data. R package version %s. Available at https://github.com/jhmigueles/stepmetrics%s",
  year, vers, if (!is.null(doi) && nzchar(doi)) paste0(". doi:", doi) else ""
)

bib
