Huh / collar

Utilities for exploring telemetry data
Other
7 stars 9 forks source link

Check that dates are valid #6

Open Huh opened 6 years ago

Huh commented 6 years ago

A function to format date time column. Helper functions might allow for checking that dates are valid (e.g. not in the future). We might also define some methods for splitting the date time values into separate values in columns, such as day, month, quarter, etc.

Other thoughts?

foresthayes commented 6 years ago

We probably need to choose a default date time format and time zone to work off of. I have collars that report a variety of formats [time, Julian day, year] and [time, mm/dd/yyyy] that record time in a variety of time zones.

I'm a little uncertain at this point if this should be its own function (to convert between date time formats) or built into the larger function to convert data from different manufacturers into a common format. Thoughts?

Huh commented 6 years ago

I am actually a big fan of GMT for time zone, but people will want to see local time too. Perhaps the data could be GMT and the print method convert to local? That said, this seems like a good place to leverage S3 methods. These are generally a good idea when you want to apply a function multiple times or on different types of data (~ classes).

http://adv-r.had.co.nz/S3.html

This is a big conversation because most other countries do dates quite differently. I tend to side with other countries in the small to big or big to small date format, however there is an argument for letting our freak flag fly and doing mm/dd/yyyy

teejclark commented 5 years ago

I figured I'd put the simple code that we've created to deal with the date-time columns. As it stands now, users will have to give a date format, something like "%Y-%M",etc, etc. Simply:

dater<-function(x,date_time,date_format,timezone){ x %>% unite(dt,date_time, sep="-") %>% mutate(datetimestamp=as.POSIXct( dt, paste(date_format,sep="-"), tz=timezone) )}

One thought is to make the default GMT (makes the most sense to me) - but if people are really picky they can change the time zone to what they want.

The ultimate issue with the above code is that it requires the user to specifically enter the format for date-time, which might be annoying. An idea that we are working on is to try and standardize different collar manufacturers date-time formats - so that the user could just put, e.g., date_format = "Lotek", and our code would automatically fill in "%Y-%m, etc, etc. Will work on this in the future.