Store Time in R
Description
Store Time in R
Usage
pl$PTime(x, tu = c("s", "ms", "us", "ns"), format = "%H:%M:%S")
Arguments
x
|
an integer or double vector of n epochs since midnight OR a char vector of char times passed to as.POSIXct converted to seconds. |
tu
|
timeunit either "s","ms","us","ns" |
format
|
a format string passed to as.POSIXct format via … |
Details
PTime should probably be replaced with package nanotime or similar.
base R is missing encoding of Time since midnight "s" "ms", "us" and "ns". The latter "ns" is the standard for the polars Time type.
Use PTime to convert R doubles and integers and use as input to polars functions which needs a time.
Loosely inspired by data.table::ITime which is i32 only. PTime must support polars native timeunit is nanoseconds. The R double(float64) can imitate a i64 ns with full precision within the full range of 24 hours.
PTime does not have a time zone and always prints the time as is no matter local machine time zone.
An essential difference between R and polars is R prints POSIXct/lt without a timezone in local time. Polars prints Datetime without a timezone label as is (GMT). For POSIXct/lt taged with a timexone(tzone) and Datetime with a timezone(tz) the behavior is the same conversion is intuitive.
It appears behavior of R timezones is subject to change a bit in R 4.3.0, see polars unit test test-expr_datetime.R/"pl$date_range Date lazy/eager".
Value
a PTime vector either double or integer, with class "PTime" and attribute "tu" being either "s","ms","us" or "ns"
Examples
#> PTime [ double ]: number of epochs [ s ] since midnight
#> [1] "20:53:40 val: 75220" "09:45:17 val: 35117" "00:55:08 val: 3308"
#> [4] "16:59:40 val: 61180" "16:43:39 val: 60219"
#> PTime [ double ]: number of epochs [ ms ] since midnight
#> [1] "11:55:29:794ms val: 42929794" "21:47:45:801ms val: 78465801"
#> [3] "06:09:54:546ms val: 22194546" "09:34:05:769ms val: 34445769"
#> [5] "09:48:39:227ms val: 35319227"
#> PTime [ double ]: number of epochs [ us ] since midnight
#> [1] "11:28:38:644_161us val: 41318644161" "04:44:40:175_330us val: 17080175330"
#> [3] "13:07:26:896_114us val: 47246896114" "22:34:00:191_998us val: 81240191998"
#> [5] "01:59:38:178_285us val: 7178178285"
#> PTime [ double ]: number of epochs [ ns ] since midnight
#> [1] "15:24:18:413_875_848ns val: 55458413875848"
#> [2] "02:14:35:686_975_568ns val: 8075686975568"
#> [3] "13:10:46:622_449_904ns val: 47446622449904"
#> [4] "13:59:56:896_107_494ns val: 50396896107494"
#> [5] "16:58:12:357_004_433ns val: 61092357004433"
#> PTime [ double ]: number of epochs [ s ] since midnight
#> [1] "23:59:59 val: 86399"
#> polars Series: shape: (5,)
#> Series: '' [time]
#> [
#> 20:28:54
#> 00:39:51
#> 22:40:49
#> 00:51:32
#> 10:10:51
#> ]
#> polars Series: shape: (1,)
#> Series: '' [time]
#> [
#> 23:59:59
#> ]
#> PTime [ double ]: number of epochs [ ns ] since midnight
#> [1] "23:59:59:000_000_000ns val: 8.6399e+13"