The R Project SVN R

Rev

Rev 90134 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 90134 Rev 90139
Line 1... Line 1...
1
### more date-time tests where the output is to be checked.
1
### more date-time tests where the output is to be checked.
2
 
2
 
3
## Expect differences, especially for platforms without tm_zone/tm_gmtoff.
3
## Expect differences, especially for platforms without tm_zone/tm_gmtoff.
4
## Please use the R-internal version for .Rout.save
4
## Please use the R-internal version for .Rout.save
-
 
5
## IGNORE_RDIFF_BEGIN
-
 
6
(tzCtype <- sessionInfo()[["tzcode_type"]])
-
 
7
## IGNORE_RDIFF_END
5
 
8
 
6
options(warn = 1L)
9
options(warn = 1L)
7
si <-  sessionInfo()
-
 
8
 
10
 
9
## tests of "POSIXlt" objects
11
## tests of "POSIXlt" objects
10
xU <- strptime("2022-01-01", "%Y-%m-%d", tz = "UTC")
12
xU <- strptime("2022-01-01", "%Y-%m-%d", tz = "UTC")
11
xU
13
xU
12
str(unclass(xU))
14
str(unclass(xU))
13
 
15
 
14
x0 <- strptime("2022-01-01", "%Y-%m-%d") # current time zone
16
x0 <- strptime("2022-01-01", "%Y-%m-%d") # current time zone
15
## IGNORE_RDIFF_BEGIN
17
## IGNORE_RDIFF_BEGIN
16
si # sessionInfo() incl "tzcode source" :
-
 
17
(tzCtype <- si[["tzcode_type"]])
-
 
18
x0
18
x0
19
str(unclass(x0))
19
str(unclass(x0))
20
## IGNORE_RDIFF_END
20
## IGNORE_RDIFF_END
21
 
21
 
22
x1 <- strptime("2022-07-01", "%Y-%m-%d", tz = "Europe/London")
22
x1 <- strptime("2022-07-01", "%Y-%m-%d", tz = "Europe/London")
Line 31... Line 31...
31
x3 <- strptime("2022-07-01 10:55:03 +0300", "%Y-%m-%d %H:%M:%S %z",
31
x3 <- strptime("2022-07-01 10:55:03 +0300", "%Y-%m-%d %H:%M:%S %z",
32
               tz = "Europe/Vienna")
32
               tz = "Europe/Vienna")
33
x3
33
x3
34
str(unclass(x3))
34
str(unclass(x3))
35
 
35
 
-
 
36
# Fiji tried DST in some previous years, but not since 2021
36
x4 <- strptime("2022-07-01", "%Y-%m-%d", tz ="Pacific/Fiji")
37
x4 <- strptime("2022-07-01", "%Y-%m-%d", tz ="Pacific/Fiji")
37
x4
38
x4
38
str(unclass(x4)) # abbreviations may be numbers.
39
str(unclass(x4)) # abbreviations may be numbers.
39
# Kiribati does/did not have DST, so second abbreviation may be repeat or empty
40
# Kiribati does/did not have DST, so second abbreviation may be repeat or empty
40
x5 <- strptime("2022-07-01", "%Y-%m-%d", tz ="Pacific/Kiritimati")
41
x5 <- strptime("2022-07-01", "%Y-%m-%d", tz ="Pacific/Kiritimati")
41
x5
42
x5
42
## IGNORE_RDIFF_BEGIN
43
## IGNORE_RDIFF_BEGIN
43
str(unclass(x5)) # does not have DST, hence no DST abbreviation except on glibc
44
attr(x5, "tzone") # does not have DST, hence no DST abbreviation except on glibc
44
## IGNORE_RDIFF_END
45
## IGNORE_RDIFF_END
45
u5 <- unclass(x5)
-
 
46
u5_ <- `attr<-`(u5, "tzone", NULL)
-
 
47
stopifnot(exprs = {
46
stopifnot(identical(
48
    identical(attr(u5, "tzone"),
47
    attr(x5, "tzone") |> trimws(), # ignore "   " (internal) vs. "" (musl)
49
              c("Pacific/Kiritimati", "+14", if(grepl("glibc", tzCtype)) "+14" else "   "))
48
    c("Pacific/Kiritimati", "+14", if(grepl("glibc", tzCtype)) "+14" else "")
50
    identical(u5_, structure(
-
 
51
                  list(sec = 0, min = 0L, hour = 0L, mday = 1L, mon = 6L, year = 122L,
-
 
52
                       wday = 5L, yday = 181L, isdst = 0L, zone = "+14", gmtoff = NA_integer_),
-
 
53
                  balanced = TRUE))
-
 
54
})
49
))
-
 
50
str(unclass(`attr<-`(x5, "tzone", NULL)))
55
 
51
 
56
 
52
 
57
## edge of range and out of range offsets
53
## edge of range and out of range offsets
58
strptime("2022-01-01 +1400", "%Y-%m-%d %z", tz = "UTC")
54
strptime("2022-01-01 +1400", "%Y-%m-%d %z", tz = "UTC")
59
strptime("2022-01-01 -1400", "%Y-%m-%d %z", tz = "UTC")
55
strptime("2022-01-01 -1400", "%Y-%m-%d %z", tz = "UTC")