getDate: Get Date

Description Usage Arguments Details Value Note Examples

View source: R/formatValue.R

Description

Robust conversion of variably formatted characters to dates

Usage

1
getDate(x, orders, year = 1957, tz = "GMT", ...)

Arguments

x

vector of character dates

orders

lubridate formatting possibilities. If missing, selects a reasonable default (see Details).

year

4 digit integer, the oldest year expected in x; default is 1957. See Note.

tz

time zone of output; default is GMT (in GMT no times missing due to daylight savings, so more robust)

...

arguments to pass to lubridate::parse_date_time

Details

See lubridate::parse_date_time for a summary of how to specify orders. Examples show a conversion of variable formats. The only reason this function exists is that parse_date_time did not handle the century very well on some test data.

The default orders is paste0( rep(c("ymd", "mdy", "Ymd", "mdY"),each=5), c(" HMS"," HM", " H", "M", "") )

Value

a vector of dates formatted as POSIXct

Note

In 2056 I will turn 70. At that point, I'll still be able to assume that a date of '57 associated with an ecological field observation was probably made in 1957. If I see '56, I'll round it up to 2056. I'll probably retire by the time I'm 70, or hopefully someone else will have cleaned up the date formats in all ecological data sets by that time. Either way, it is in my own self interest to set the default as ‘year=1957'; I do not currently use very many data sets that begin before 1957 (and none of such vast size that I need computer code to automate the corrections), and as a result, the default 1957 will continue to work for me until I retire. After that, a date of ’57 that was actually taken in 2057 will have its date reverted to 1957. Shame on them.

Oh, and the oldest observation in this package is 1958, I believe (the soda bottom temperatures). As for trawl data, NEUS goes back to 1963. So 1957 is a date choice that will work for all dates currently in this package, and given a 1 year buffer, maximizes the duration of the appropriateness of this default for these data sets into the future.

Examples

1
2
3
4
5
6
7
8
test <- c(
	"2012-11-11", "12-5-23", "12/5/86",
	"2015-12-16 1300", "8/6/92 3:00", 
	"11/6/14 4", "10/31/14 52", "06/15/2014 14:37:01", 
	"2/10/06", "95-06-26", "82-10-03", 
	"11/18/56 2:30:42pm", "11/18/57 1:00", "11/18/58"
)
getDate(test, orders=orders, truncated=3) # default orders ignores pm

rBatt/trawlData documentation built on June 30, 2017, 12:59 p.m.