% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dendro.truncate.R
\name{dendro.truncate}
\alias{dendro.truncate}
\title{Truncation of dendrometer data}
\usage{
dendro.truncate(df, CalYear, DOY)
}
\arguments{
\item{df}{A data frame where the first column contains date or date-time
values. The first column is renamed to \code{TIME} in the returned data.}

\item{CalYear}{Numeric value or numeric vector of length two giving the
calendar year or start and end calendar years.}

\item{DOY}{Numeric value or numeric vector of length two giving the day of
year or start and end day of year.}
}
\value{
A tibble containing the truncated dendrometer data.
}
\description{
Truncates dendrometer data to a user-defined calendar-year and day-of-year
window.

The first column of \code{df} is treated as the date-time column and is
renamed internally to \code{TIME}. The date-time column may be a
\code{Date}, \code{POSIXct}, or character vector in the format
\code{"yyyy-mm-dd HH:MM:SS"}. Character dates in the format
\code{"yyyy-mm-dd"} are also accepted.

This version supports leap years correctly. For example, \code{DOY = 366}
is valid for leap years such as 2016, 2020, or 2024, but invalid for
non-leap years.
}
\details{
The truncation rules are:
\itemize{
  \item If \code{CalYear} has length one and \code{DOY} has length one,
    data from that single day are returned.
  \item If \code{CalYear} has length one and \code{DOY} has length two,
    data from the first DOY to the second DOY within the same year are
    returned.
  \item If \code{CalYear} has length two and \code{DOY} has length one,
    data from that DOY in the first year to the same DOY in the second year
    are returned.
  \item If \code{CalYear} has length two and \code{DOY} has length two,
    data from the first DOY of the first year to the second DOY of the
    second year are returned.
}

The function uses real calendar dates internally rather than row positions.
Therefore, leap-year DOY 366 is handled correctly.
}
\examples{
\donttest{
library(dendRoAnalyst)
data(nepa)

# Extract data from DOY 20 to 50 in 2017
trunc1 <- dendro.truncate(df = nepa, CalYear = 2017, DOY = c(20, 50))
head(trunc1, 10)

# Leap-year example, if the data contain year 2020
# trunc2 <- dendro.truncate(df = df2020, CalYear = 2020, DOY = c(1, 366))
}

}
