| 64578 |
ripley |
1 |
### Tests of often platform-dependent features of the POSIX[cl]t implementation.
|
|
|
2 |
|
|
|
3 |
### Expect differences, especially with 32-bit time_t
|
|
|
4 |
|
|
|
5 |
z <- ISOdate(1890:1912, 1, 10, tz="UTC")
|
|
|
6 |
## Rome changed to CET for 1894
|
|
|
7 |
as.POSIXlt(z, tz="Europe/Rome")
|
|
|
8 |
## Paris changed to PMT for 1892, WET for 1912
|
|
|
9 |
(zz <- as.POSIXlt(z, tz="Europe/Paris"))
|
|
|
10 |
strftime(zz, "%Y-%m-%d %H:%M:%S %Z")
|
|
|
11 |
## The offset was really 00:09:21 until 1911, then 00:00
|
|
|
12 |
## Many platforms will give the current offset, +0100
|
|
|
13 |
strftime(zz, "%Y-%m-%d %H:%M:%S %z")
|
|
|
14 |
|
|
|
15 |
## Some platforms give details of the latest conversion.
|
|
|
16 |
z <- ISOdate(c(seq(1890, 1940, 5), 1941:1946, 1950), 1, 10, tz="UTC")
|
|
|
17 |
as.POSIXlt(z, tz="Europe/Paris")
|
|
|
18 |
for(i in seq_along(z)) print(as.POSIXlt(z[i], tz="Europe/Paris"))
|
|
|
19 |
for(i in seq_along(z))
|
|
|
20 |
print(strftime(as.POSIXlt(z[i], tz="Europe/Paris"), "%Y-%m-%d %H:%M:%S %z"))
|
|
|
21 |
|
|
|
22 |
strptime("1920-12-27 08:18:23", "%Y-%m-%d %H:%M:%S", tz="Europe/Paris")
|
| 64585 |
ripley |
23 |
|
|
|
24 |
## check %V etc
|
|
|
25 |
|
|
|
26 |
d <- expand.grid(day = 1:7, year = 2000:2010)
|
|
|
27 |
z1 <- with(d, ISOdate(year, 1, day))
|
|
|
28 |
d <- expand.grid(day = 25:31, year = 2000:2010)
|
|
|
29 |
z2 <- with(d, ISOdate(year, 12, day))
|
|
|
30 |
z <- sort(c(z1, z2))
|
|
|
31 |
strftime(z, "%G %g %W %U %u %V %W %w")
|
| 64596 |
ripley |
32 |
|
|
|
33 |
## tests of earlier years. Default format is OS-dependent, so don't test it.
|
| 64625 |
ripley |
34 |
## ISOdate only accepts positive years.
|
| 64596 |
ripley |
35 |
z <- as.Date(ISOdate(c(0, 8, 9, 10, 11, 20, 110, 1010), 1, 10)) - 3630
|
| 64625 |
ripley |
36 |
strftime(z, "%04Y-%m-%d") # with leading zero(s)
|
|
|
37 |
strftime(z, "%_4Y-%m-%d") # with leading space(s)
|
|
|
38 |
strftime(z, "%0Y-%m-%d") # without
|
| 64607 |
ripley |
39 |
|
|
|
40 |
|
|
|
41 |
## more test of strftime
|
|
|
42 |
x <- ISOdate(2014, 3, 10, c(7, 13))
|
|
|
43 |
fmts <- c("%Y-%m-%d %H:%M:%S", "%F", "%A %a %b %h %e %I %j",
|
|
|
44 |
## locale-dependent ones
|
|
|
45 |
"%X", # but the same in all English locales
|
|
|
46 |
"%c", "%x", "%p", "%r")
|
|
|
47 |
for (f in fmts) print(format(x, f))
|