dt_parts: Pull POSIXct datetime back into date, time, and time zone...

View source: R/dt_parts.R

dt_partsR Documentation

Pull POSIXct datetime back into date, time, and time zone columns. Add comments if there are any differences.

Description

This function will take a datetime POSIXct vector and save the date, time, and timezone elements into their respective destination columns. This is intended to apply any corrections from datetime back to the original date, time, and timezone columns.

Usage

dt_parts(
  df,
  datetime_col = "datetime",
  date_col = "Activity.Start.Date",
  time_col = "Activity.Start.Time",
  tz_col = "Activity.Start.End.Time.Zone",
  comment_col = "Datetime.Comment",
  tz_comment = "corrected timezone",
  dst_comment = "corrected for DST",
  tzdst_comment = "corrected timezone and for DST"
)

Arguments

df

Data frame to be evaluated.

datetime_col

Column name in df holding the POSIXct datetime values. Default is "datetime"

date_col

Destination column name in df holding the POSIXct date values. Default is "Activity.Start.Date"

time_col

Destination column name in df holding the POSIXct time values. Default is "Activity.Start.Time".

tz_col

Destination column name in df holding the timezone string values. Default is "Activity.Start.End.Time.Zone".

comment_col

Column name in df holding the comment column. Default is "Datetime.Comment".

tz_comment

Comment in string format to add to comment_col if the timezone changed. Default is "corrected timezone".

dst_comment

Comment in string format to add to comment_col if their was a time change. Default is "corrected for DST".

tzdst_comment

Comment in string format to add to comment_col if their was a timezone and time change. Default is "corrected timezone and for DST".

Details

The destination date_col and time_col are formatted as POSIXct values and are equal datetime_col. tz_col is formatted as a string. e.g. format(df$datetime_col, format="%Z").

A comparison is made between the value derived from datetime_col to the value in the destination column. If the values are different a comment is recorded in comment_col. Any existing comments are retained and new comments appended.

There are three different comments for three different situations: when only the timezone changes, when only the date/time changes, and when both the timezone and the date/time changes. A date/time change is usually due to adjustment for DST.

Value

returned data frame.


DEQrmichie/odeqcdr documentation built on Feb. 15, 2025, 10:01 a.m.