R Under development (unstable) (2025-05-21 r88220 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # some tests to ensure that modifications don't change > # the global behaviour of Time*DataFrame > > #===================== > # TimeInstantDataFrame > library( timetools ) > > tidf <- TimeInstantDataFrame(as.POSIXct(sprintf('2012-01-%02i', 4:8), 'UTC'), + 'CET', data.frame(un=1:5, two=6:10)) > tidf when un two 1 2012-01-04 01:00:00 CET 1 6 2 2012-01-05 01:00:00 CET 2 7 3 2012-01-06 01:00:00 CET 3 8 4 2012-01-07 01:00:00 CET 4 9 5 2012-01-08 01:00:00 CET 5 10 > timezone(tidf) <- 'UTC' > tidf when un two 1 2012-01-04 UTC 1 6 2 2012-01-05 UTC 2 7 3 2012-01-06 UTC 3 8 4 2012-01-07 UTC 4 9 5 2012-01-08 UTC 5 10 > tidf[3:4,'two'] when two 3 2012-01-06 UTC 8 4 2012-01-07 UTC 9 > when(tidf) [1] "2012-01-04 UTC" "2012-01-05 UTC" "2012-01-06 UTC" "2012-01-07 UTC" [5] "2012-01-08 UTC" > > tidf <- TimeInstantDataFrame(as.POSIXct(sprintf('2012-01-%02i', 4:8), 'CET'), + 'UTC', data.frame(un=1:5, two=6:10)) > tidf when un two 1 2012-01-03 23:00:00 UTC 1 6 2 2012-01-04 23:00:00 UTC 2 7 3 2012-01-05 23:00:00 UTC 3 8 4 2012-01-06 23:00:00 UTC 4 9 5 2012-01-07 23:00:00 UTC 5 10 > timezone(tidf) <- 'CET' > tidf when un two 1 2012-01-04 CET 1 6 2 2012-01-05 CET 2 7 3 2012-01-06 CET 3 8 4 2012-01-07 CET 4 9 5 2012-01-08 CET 5 10 > tidf[3:4,'two'] when two 3 2012-01-06 CET 8 4 2012-01-07 CET 9 > when(tidf) [1] "2012-01-04 CET" "2012-01-05 CET" "2012-01-06 CET" "2012-01-07 CET" [5] "2012-01-08 CET" > > split( tidf, c(rep('C', 3), rep('A', 2)) ) $A when un two 4 2012-01-07 CET 4 9 5 2012-01-08 CET 5 10 $C when un two 1 2012-01-04 CET 1 6 2 2012-01-05 CET 2 7 3 2012-01-06 CET 3 8 > > #====================== > # TimeIntervalDataFrame > > tidf <- TimeIntervalDataFrame(as.POSIXct(sprintf('2012-01-%02i', 4:9), 'UTC'), + tiemzone='CET', data=data.frame(un=1:5, two=6:10)) > tidf start end un two 1 2012-01-04 UTC 2012-01-05 UTC 1 6 2 2012-01-05 UTC 2012-01-06 UTC 2 7 3 2012-01-06 UTC 2012-01-07 UTC 3 8 4 2012-01-07 UTC 2012-01-08 UTC 4 9 5 2012-01-08 UTC 2012-01-09 UTC 5 10 > timezone(tidf) <- 'UTC' > tidf start end un two 1 2012-01-04 UTC 2012-01-05 UTC 1 6 2 2012-01-05 UTC 2012-01-06 UTC 2 7 3 2012-01-06 UTC 2012-01-07 UTC 3 8 4 2012-01-07 UTC 2012-01-08 UTC 4 9 5 2012-01-08 UTC 2012-01-09 UTC 5 10 > tidf[3:4,'two'] start end two 3 2012-01-06 UTC 2012-01-07 UTC 8 4 2012-01-07 UTC 2012-01-08 UTC 9 > when(tidf) [1] "2012-01-04 00:00:00 <-> 2012-01-05 00:00:00" [2] "2012-01-05 00:00:00 <-> 2012-01-06 00:00:00" [3] "2012-01-06 00:00:00 <-> 2012-01-07 00:00:00" [4] "2012-01-07 00:00:00 <-> 2012-01-08 00:00:00" [5] "2012-01-08 00:00:00 <-> 2012-01-09 00:00:00" > start(tidf) [1] "2012-01-04 UTC" "2012-01-05 UTC" "2012-01-06 UTC" "2012-01-07 UTC" [5] "2012-01-08 UTC" > end(tidf) [1] "2012-01-05 UTC" "2012-01-06 UTC" "2012-01-07 UTC" "2012-01-08 UTC" [5] "2012-01-09 UTC" > > tidf <- TimeIntervalDataFrame(as.POSIXct(sprintf('2012-01-%02i', 4:9), 'CET'), + timezone='UTC', data=data.frame(un=1:5, two=6:10)) > tidf start end un two 1 2012-01-03 23:00:00 UTC 2012-01-04 23:00:00 UTC 1 6 2 2012-01-04 23:00:00 UTC 2012-01-05 23:00:00 UTC 2 7 3 2012-01-05 23:00:00 UTC 2012-01-06 23:00:00 UTC 3 8 4 2012-01-06 23:00:00 UTC 2012-01-07 23:00:00 UTC 4 9 5 2012-01-07 23:00:00 UTC 2012-01-08 23:00:00 UTC 5 10 > timezone(tidf) <- 'CET' > tidf start end un two 1 2012-01-04 CET 2012-01-05 CET 1 6 2 2012-01-05 CET 2012-01-06 CET 2 7 3 2012-01-06 CET 2012-01-07 CET 3 8 4 2012-01-07 CET 2012-01-08 CET 4 9 5 2012-01-08 CET 2012-01-09 CET 5 10 > tidf[3:4,'two'] start end two 3 2012-01-06 CET 2012-01-07 CET 8 4 2012-01-07 CET 2012-01-08 CET 9 > when(tidf) [1] "2012-01-04 00:00:00 <-> 2012-01-05 00:00:00" [2] "2012-01-05 00:00:00 <-> 2012-01-06 00:00:00" [3] "2012-01-06 00:00:00 <-> 2012-01-07 00:00:00" [4] "2012-01-07 00:00:00 <-> 2012-01-08 00:00:00" [5] "2012-01-08 00:00:00 <-> 2012-01-09 00:00:00" > start(tidf) [1] "2012-01-04 CET" "2012-01-05 CET" "2012-01-06 CET" "2012-01-07 CET" [5] "2012-01-08 CET" > end(tidf) [1] "2012-01-05 CET" "2012-01-06 CET" "2012-01-07 CET" "2012-01-08 CET" [5] "2012-01-09 CET" > > > proc.time() user system elapsed 0.43 0.10 0.53