Learn R Programming

admiral (version 1.3.0)

is_partial_datetime: Check if a Partial Date/Time is a Datetime

Description

This function determines whether a given partial date/time structure represents a datetime or just a date.

Usage

is_partial_datetime(partial)

Value

A logical value. TRUE if the partial represents a datetime, FALSE if it represents a date only.

Arguments

partial

A named list containing date or datetime components.

Default value

none

Details

The function checks for the presence of all date components (year, month, day) and all time components (hour, minute, second) in the input list. If all components are present, it's considered a datetime. If only date components are present, it's considered a date. Any other combination will result in an error.

Examples

Run this code
# Datetime example
partial_datetime <- list(
  year = "2023", month = "05", day = "15",
  hour = "14", minute = "30", second = "00"
)
admiral:::is_partial_datetime(partial_datetime) # Returns TRUE

# Date example
partial_date <- list(year = "2023", month = "05", day = "15")
admiral:::is_partial_datetime(partial_date) # Returns FALSE

# Invalid example
if (FALSE) {
partial_invalid <- list(year = "2023", month = "05", hour = "14")
admiral:::is_partial_datetime(partial_invalid) # Throws an error
}

Run the code above in your browser using DataLab