Skip to contents

Creates a new temporal variable by extracting temporal unit, such as year, month, or day from a date variable.

Usage

temporal_mod(
  dat,
  project,
  x,
  define.format = NULL,
  timezone = NULL,
  name = NULL,
  log_fun = TRUE,
  ...
)

Arguments

dat

Primary data containing information on hauls or trips. Table in FishSET database contains the string 'MainDataTable'.

project

Project name.

x

Time variable to modify from dat.

define.format

Format of temporal data. define.format should be NULL if converting timezone for x but not changing format. Format can be user-defined or from pre-defined choices. Format follows as.Date format. See Details for more information.

timezone

String, defaults to NULL. Returns the date-time in the specified time zone. Must be a recognizable timezone, such as "UTC", "America/New_York", "Europe/Amsterdam".

name

String, name of created variables. Defaults to `TempMod`.

log_fun

Logical, whether to log function call (for internal use).

...

Additional arguments. Use tz='' to specify time zone.

Value

Primary data set with new variable added.

Details

Converts a date variable to desired timezone or units using as.Date. date_parser is also called to ensure the date variable is in an acceptable format for as.Date. define.format defines the format that the variable should take on. Examples include "%Y%m%d", "%Y-%m-%d %H:%M:%S". Users can define their own format or use one of the predefined ones. Hours is 0-23. To return a list of time-zone name in the Olson/IANA database paste OlsonNames() to the console.

  • year: Takes on the format "%Y" and returns the year.

  • month: Takes on the format "%Y/%m" and returns the year and month.

  • day: Takes on the format "%Y/%m/%d" and returns the year, month, and day.

  • hour: Takes on the format "%Y/%m/%d %H" and returns the year, month, day and hour.

  • minute: Takes on the format "%Y/%m/%d %H:%M" and returns the year, month, day, hour, and minute.

For more information on formats, see https://www.stat.berkeley.edu/~s133/dates.html.

Examples

if (FALSE) {
pcodMainDataTable <- temporal_mod(pcodMainDataTable, "pcod", 
   "DATE_LANDED", define.format = "%Y%m%d")
pcodMainDataTable <- temporal_mod(pcodMainDataTable, "pcod", 
   "DATE_LANDED", define.format = "year")
}


# Change to Year, month, day, minutes