Skip to content

Commit aef5726

Browse files
author
maechler
committed
mv new strict checks from *5 to *3
git-svn-id: https://svn.r-project.org/R/trunk@87357 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 079a1fa commit aef5726

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

tests/datetime3.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,44 @@ stopifnot(exprs = {
601601
})
602602

603603

604+
## fractional seconds print(<POSIXct>) --> format.POSIXlt() -- PR#17350 (and rdev day #83)
605+
## Original PR#17350 example (Vitalie Spinu):
606+
op <- options(digits.secs = 6, scipen = 20, digits = 15)
607+
## what we'd desire for print()ing etc:
608+
chx <- paste0("2009-08-03 12:01:59", c("", paste0(".",1:3)))
609+
print(chx, width = 40)
610+
xl <- as.POSIXlt(chx)
611+
stopifnot(identical(xl$sec, 59 + 0:3/10)) # POSIXlt keeping full precision (always did)
612+
## (but all arithmetic with POSIX*t currently happens via POSIXct, losing precision)
613+
fxl <- format(xl) # is perfect {with getOption("digits.secs") > 0 !}
614+
stopifnot(identical(sub(".*:59", '', fxl), paste0(".", 0:3)))
615+
x <- as.POSIXct("2009-08-03 12:01:59") + 0:3/10 # using POSIXct looses prec
616+
x. <- structure(x, tzone = "") ## == Vitalie's explicit original ex.
617+
identical(x, x.) # FALSE : x. contains `tzone = ""`
618+
print(x, width = 40) # now .000000 .099999 2.00000 2.999999 (as digits.secs = 6 !)
619+
fx <- format(x)
620+
stopifnot(identical(fx, format(x.))) # *are* the same (for a while now)
621+
## The %OS and %OS<d> formats have been fine "always":
622+
fD.OS <- function(d) format(x, format = paste0("%Y-%m-%d %H:%M:%OS", if(d=="_") "" else d))
623+
f.OSss <- vapply(c("_",0:6), fD.OS, character(length(x)))
624+
t(f.OSss) |> print(width=111, quote=FALSE) # shows 'trunc()' instead of 'round()'
625+
stopifnot(identical(f.OSss[,"_"], f.OSss[,"6"])) # by option digits.secs
626+
(secDig <- sub(".*:59", '', f.OSss)) ## [,"1"] is *.0 *.0 *.2 *.2 - "bad" from using trunc() by design
627+
## ___________ ___ __ __ "factory fresh" default
628+
options(digits.secs = NULL, scipen = 0, digits = 7)
629+
f.OSssD <- vapply(c("_",0:6), fD.OS, character(length(x))) # same call but different "digits.secs" option
630+
## digits = <d> now works "the same":
631+
fdig <- vapply(c("_",0:6), \(d) format(x, digits = if(d != "_") d), character(length(x)))
632+
stopifnot(exprs = {
633+
nchar(t(secDig)) == c(7L, 0L, 2:7) # as always
634+
identical(f.OSssD[, 1], f.OSssD[,"0"]) # "" <--> "0"
635+
identical(f.OSss [,-1], f.OSssD[, -1]) # only meaning of `empty' "%OS" changes with "digits.secs" option
636+
identical(fdig, f.OSssD)
637+
})
638+
options(op)
639+
## Number of digits used differed in several cases in R <= 4.4.z
640+
641+
604642

605643
## keep at end
606644
rbind(last = proc.time() - .pt,

tests/datetime5.R

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,3 @@ for (f in c("P", "k", "l", "s")) {
2727
## week numbers
2828
dt2 <- as.POSIXlt(sprintf("%d-01-01 09:03;04", 2015:2018))
2929
cat(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

Comments
 (0)