@@ -27,41 +27,3 @@ for (f in c("P", "k", "l", "s")) {
2727# # week numbers
2828dt2 <- as.POSIXlt(sprintf(" %d-01-01 09:03;04" , 2015 : 2018 ))
2929cat(format(dt2 , " %Y: %U %V %W" ), sep = " \n " )
30-
31-
32- # # fractional seconds print(<POSIXct>) --> format.POSIXlt() -- PR#17350 (and rdev day #83)
33- # # Original PR#17350 example (Vitalie Spinu):
34- op <- options(digits.secs = 6 , scipen = 20 , digits = 15 )
35- # # what we'd desire for print()ing etc:
36- chx <- paste0(" 2009-08-03 12:01:59" , c(" " , paste0(" ." ,1 : 3 )))
37- print(chx , width = 40 )
38- xl <- as.POSIXlt(chx )
39- stopifnot(identical(xl $ sec , 59 + 0 : 3 / 10 )) # POSIXlt keeping full precision (always did)
40- # # (but all arithmetic with POSIX*t currently happens via POSIXct, losing precision)
41- fxl <- format(xl ) # is perfect {with getOption("digits.secs") > 0 !}
42- stopifnot(identical(sub(" .*:59" , ' ' , fxl ), paste0(" ." , 0 : 3 )))
43- x <- as.POSIXct(" 2009-08-03 12:01:59" ) + 0 : 3 / 10 # using POSIXct looses prec
44- x. <- structure(x , tzone = " " ) # # == Vitalie's explicit original ex.
45- identical(x , x. ) # FALSE : x. contains `tzone = ""`
46- print(x , width = 40 ) # now .000000 .099999 2.00000 2.999999 (as digits.secs = 6 !)
47- fx <- format(x )
48- stopifnot(identical(fx , format(x. ))) # *are* the same (for a while now)
49- # # The %OS and %OS<d> formats have been fine "always":
50- fD.OS <- function (d ) format(x , format = paste0(" %Y-%m-%d %H:%M:%OS" , if (d == " _" ) " " else d ))
51- f.OSss <- vapply(c(" _" ,0 : 6 ), fD.OS , character (length(x )))
52- t(f.OSss ) | > print(width = 111 , quote = FALSE ) # shows 'trunc()' instead of 'round()'
53- stopifnot(identical(f.OSss [," _" ], f.OSss [," 6" ])) # by option digits.secs
54- (secDig <- sub(" .*:59" , ' ' , f.OSss )) # # [,"1"] is *.0 *.0 *.2 *.2 - "bad" from using trunc() by design
55- # # ___________ ___ __ __ "factory fresh" default
56- options(digits.secs = NULL , scipen = 0 , digits = 7 )
57- f.OSssD <- vapply(c(" _" ,0 : 6 ), fD.OS , character (length(x ))) # same call but different "digits.secs" option
58- # # digits = <d> now works "the same":
59- fdig <- vapply(c(" _" ,0 : 6 ), \(d ) format(x , digits = if (d != " _" ) d ), character (length(x )))
60- stopifnot(exprs = {
61- nchar(t(secDig )) == c(7L , 0L , 2 : 7 ) # as always
62- identical(f.OSssD [, 1 ], f.OSssD [," 0" ]) # "" <--> "0"
63- identical(f.OSss [,- 1 ], f.OSssD [, - 1 ]) # only meaning of `empty' "%OS" changes with "digits.secs" option
64- identical(fdig , f.OSssD )
65- })
66- options(op )
67- # # Number of digits used differed in several cases in R <= 4.4.z
0 commit comments