R version 4.1.0 Patched (2021-06-17 r80511) -- "Camp Pontanezen" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) 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. > ### Tests of often platform-dependent features of the POSIX[cl]t implementation. > > ### Expect differences, especially with 32-bit time_t > > z <- ISOdate(1890:1912, 1, 10, tz="UTC") > ## Rome changed to CET for 1894 > as.POSIXlt(z, tz="Europe/Rome") [1] "1890-01-10 12:49:56 RMT" "1891-01-10 12:49:56 RMT" [3] "1892-01-10 12:49:56 RMT" "1893-01-10 12:49:56 RMT" [5] "1894-01-10 13:00:00 CET" "1895-01-10 13:00:00 CET" [7] "1896-01-10 13:00:00 CET" "1897-01-10 13:00:00 CET" [9] "1898-01-10 13:00:00 CET" "1899-01-10 13:00:00 CET" [11] "1900-01-10 13:00:00 CET" "1901-01-10 13:00:00 CET" [13] "1902-01-10 13:00:00 CET" "1903-01-10 13:00:00 CET" [15] "1904-01-10 13:00:00 CET" "1905-01-10 13:00:00 CET" [17] "1906-01-10 13:00:00 CET" "1907-01-10 13:00:00 CET" [19] "1908-01-10 13:00:00 CET" "1909-01-10 13:00:00 CET" [21] "1910-01-10 13:00:00 CET" "1911-01-10 13:00:00 CET" [23] "1912-01-10 13:00:00 CET" > ## Paris changed to PMT for 1892, WET for 1912 > (zz <- as.POSIXlt(z, tz="Europe/Paris")) [1] "1890-01-10 12:09:21 LMT" "1891-01-10 12:09:21 LMT" [3] "1892-01-10 12:09:21 PMT" "1893-01-10 12:09:21 PMT" [5] "1894-01-10 12:09:21 PMT" "1895-01-10 12:09:21 PMT" [7] "1896-01-10 12:09:21 PMT" "1897-01-10 12:09:21 PMT" [9] "1898-01-10 12:09:21 PMT" "1899-01-10 12:09:21 PMT" [11] "1900-01-10 12:09:21 PMT" "1901-01-10 12:09:21 PMT" [13] "1902-01-10 12:09:21 PMT" "1903-01-10 12:09:21 PMT" [15] "1904-01-10 12:09:21 PMT" "1905-01-10 12:09:21 PMT" [17] "1906-01-10 12:09:21 PMT" "1907-01-10 12:09:21 PMT" [19] "1908-01-10 12:09:21 PMT" "1909-01-10 12:09:21 PMT" [21] "1910-01-10 12:09:21 PMT" "1911-01-10 12:09:21 PMT" [23] "1912-01-10 12:00:00 WET" > strftime(zz, "%Y-%m-%d %H:%M:%S %Z") [1] "1890-01-10 12:09:21 LMT" "1891-01-10 12:09:21 LMT" [3] "1892-01-10 12:09:21 PMT" "1893-01-10 12:09:21 PMT" [5] "1894-01-10 12:09:21 PMT" "1895-01-10 12:09:21 PMT" [7] "1896-01-10 12:09:21 PMT" "1897-01-10 12:09:21 PMT" [9] "1898-01-10 12:09:21 PMT" "1899-01-10 12:09:21 PMT" [11] "1900-01-10 12:09:21 PMT" "1901-01-10 12:09:21 PMT" [13] "1902-01-10 12:09:21 PMT" "1903-01-10 12:09:21 PMT" [15] "1904-01-10 12:09:21 PMT" "1905-01-10 12:09:21 PMT" [17] "1906-01-10 12:09:21 PMT" "1907-01-10 12:09:21 PMT" [19] "1908-01-10 12:09:21 PMT" "1909-01-10 12:09:21 PMT" [21] "1910-01-10 12:09:21 PMT" "1911-01-10 12:09:21 PMT" [23] "1912-01-10 12:00:00 WET" > ## The offset was really 00:09:21 until 1911, then 00:00 > ## Many platforms will give the current offset, +0100 > strftime(zz, "%Y-%m-%d %H:%M:%S %z") [1] "1890-01-10 12:09:21 +0009" "1891-01-10 12:09:21 +0009" [3] "1892-01-10 12:09:21 +0009" "1893-01-10 12:09:21 +0009" [5] "1894-01-10 12:09:21 +0009" "1895-01-10 12:09:21 +0009" [7] "1896-01-10 12:09:21 +0009" "1897-01-10 12:09:21 +0009" [9] "1898-01-10 12:09:21 +0009" "1899-01-10 12:09:21 +0009" [11] "1900-01-10 12:09:21 +0009" "1901-01-10 12:09:21 +0009" [13] "1902-01-10 12:09:21 +0009" "1903-01-10 12:09:21 +0009" [15] "1904-01-10 12:09:21 +0009" "1905-01-10 12:09:21 +0009" [17] "1906-01-10 12:09:21 +0009" "1907-01-10 12:09:21 +0009" [19] "1908-01-10 12:09:21 +0009" "1909-01-10 12:09:21 +0009" [21] "1910-01-10 12:09:21 +0009" "1911-01-10 12:09:21 +0009" [23] "1912-01-10 12:00:00 +0000" > > ## Some platforms give details of the latest conversion. > z <- ISOdate(c(seq(1890, 1940, 5), 1941:1946, 1950), 1, 10, tz="UTC") > as.POSIXlt(z, tz="Europe/Paris") [1] "1890-01-10 12:09:21 LMT" "1895-01-10 12:09:21 PMT" [3] "1900-01-10 12:09:21 PMT" "1905-01-10 12:09:21 PMT" [5] "1910-01-10 12:09:21 PMT" "1915-01-10 12:00:00 WET" [7] "1920-01-10 12:00:00 WET" "1925-01-10 12:00:00 WET" [9] "1930-01-10 12:00:00 WET" "1935-01-10 12:00:00 WET" [11] "1940-01-10 12:00:00 WET" "1941-01-10 14:00:00 CEST" [13] "1942-01-10 14:00:00 CEST" "1943-01-10 13:00:00 CET" [15] "1944-01-10 13:00:00 CET" "1945-01-10 13:00:00 WEST" [17] "1946-01-10 13:00:00 CET" "1950-01-10 13:00:00 CET" > for(i in seq_along(z)) print(as.POSIXlt(z[i], tz="Europe/Paris")) [1] "1890-01-10 12:09:21 LMT" [1] "1895-01-10 12:09:21 PMT" [1] "1900-01-10 12:09:21 PMT" [1] "1905-01-10 12:09:21 PMT" [1] "1910-01-10 12:09:21 PMT" [1] "1915-01-10 12:00:00 WET" [1] "1920-01-10 12:00:00 WET" [1] "1925-01-10 12:00:00 WET" [1] "1930-01-10 12:00:00 WET" [1] "1935-01-10 12:00:00 WET" [1] "1940-01-10 12:00:00 WET" [1] "1941-01-10 14:00:00 CEST" [1] "1942-01-10 14:00:00 CEST" [1] "1943-01-10 13:00:00 CET" [1] "1944-01-10 13:00:00 CET" [1] "1945-01-10 13:00:00 WEST" [1] "1946-01-10 13:00:00 CET" [1] "1950-01-10 13:00:00 CET" > for(i in seq_along(z)) + print(strftime(as.POSIXlt(z[i], tz="Europe/Paris"), "%Y-%m-%d %H:%M:%S %z")) [1] "1890-01-10 12:09:21 +0009" [1] "1895-01-10 12:09:21 +0009" [1] "1900-01-10 12:09:21 +0009" [1] "1905-01-10 12:09:21 +0009" [1] "1910-01-10 12:09:21 +0009" [1] "1915-01-10 12:00:00 +0000" [1] "1920-01-10 12:00:00 +0000" [1] "1925-01-10 12:00:00 +0000" [1] "1930-01-10 12:00:00 +0000" [1] "1935-01-10 12:00:00 +0000" [1] "1940-01-10 12:00:00 +0000" [1] "1941-01-10 14:00:00 +0200" [1] "1942-01-10 14:00:00 +0200" [1] "1943-01-10 13:00:00 +0100" [1] "1944-01-10 13:00:00 +0100" [1] "1945-01-10 13:00:00 +0100" [1] "1946-01-10 13:00:00 +0100" [1] "1950-01-10 13:00:00 +0100" > > strptime("1920-12-27 08:18:23", "%Y-%m-%d %H:%M:%S", tz="Europe/Paris") [1] "1920-12-27 08:18:23 WET" > > ## check %V etc > > d <- expand.grid(day = 1:7, year = 2000:2010) > z1 <- with(d, ISOdate(year, 1, day)) > d <- expand.grid(day = 25:31, year = 2000:2010) > z2 <- with(d, ISOdate(year, 12, day)) > z <- sort(c(z1, z2)) > strftime(z, "%G %g %W %U %u %V %W %w", tz="Europe/Paris") [1] "1999 99 00 00 6 52 00 6" "1999 99 00 01 7 52 00 0" [3] "2000 00 01 01 1 01 01 1" "2000 00 01 01 2 01 01 2" [5] "2000 00 01 01 3 01 01 3" "2000 00 01 01 4 01 01 4" [7] "2000 00 01 01 5 01 01 5" "2000 00 52 52 1 52 52 1" [9] "2000 00 52 52 2 52 52 2" "2000 00 52 52 3 52 52 3" [11] "2000 00 52 52 4 52 52 4" "2000 00 52 52 5 52 52 5" [13] "2000 00 52 52 6 52 52 6" "2000 00 52 53 7 52 52 0" [15] "2001 01 01 00 1 01 01 1" "2001 01 01 00 2 01 01 2" [17] "2001 01 01 00 3 01 01 3" "2001 01 01 00 4 01 01 4" [19] "2001 01 01 00 5 01 01 5" "2001 01 01 00 6 01 01 6" [21] "2001 01 01 01 7 01 01 0" "2001 01 52 51 2 52 52 2" [23] "2001 01 52 51 3 52 52 3" "2001 01 52 51 4 52 52 4" [25] "2001 01 52 51 5 52 52 5" "2001 01 52 51 6 52 52 6" [27] "2001 01 52 52 7 52 52 0" "2002 02 53 52 1 01 53 1" [29] "2002 02 00 00 2 01 00 2" "2002 02 00 00 3 01 00 3" [31] "2002 02 00 00 4 01 00 4" "2002 02 00 00 5 01 00 5" [33] "2002 02 00 00 6 01 00 6" "2002 02 00 01 7 01 00 0" [35] "2002 02 01 01 1 02 01 1" "2002 02 51 51 3 52 51 3" [37] "2002 02 51 51 4 52 51 4" "2002 02 51 51 5 52 51 5" [39] "2002 02 51 51 6 52 51 6" "2002 02 51 52 7 52 51 0" [41] "2003 03 52 52 1 01 52 1" "2003 03 52 52 2 01 52 2" [43] "2003 03 00 00 3 01 00 3" "2003 03 00 00 4 01 00 4" [45] "2003 03 00 00 5 01 00 5" "2003 03 00 00 6 01 00 6" [47] "2003 03 00 01 7 01 00 0" "2003 03 01 01 1 02 01 1" [49] "2003 03 01 01 2 02 01 2" "2003 03 51 51 4 52 51 4" [51] "2003 03 51 51 5 52 51 5" "2003 03 51 51 6 52 51 6" [53] "2003 03 51 52 7 52 51 0" "2004 04 52 52 1 01 52 1" [55] "2004 04 52 52 2 01 52 2" "2004 04 52 52 3 01 52 3" [57] "2004 04 00 00 4 01 00 4" "2004 04 00 00 5 01 00 5" [59] "2004 04 00 00 6 01 00 6" "2004 04 00 01 7 01 00 0" [61] "2004 04 01 01 1 02 01 1" "2004 04 01 01 2 02 01 2" [63] "2004 04 01 01 3 02 01 3" "2004 04 51 51 6 52 51 6" [65] "2004 04 51 52 7 52 51 0" "2004 04 52 52 1 53 52 1" [67] "2004 04 52 52 2 53 52 2" "2004 04 52 52 3 53 52 3" [69] "2004 04 52 52 4 53 52 4" "2004 04 52 52 5 53 52 5" [71] "2004 04 00 00 6 53 00 6" "2004 04 00 01 7 53 00 0" [73] "2005 05 01 01 1 01 01 1" "2005 05 01 01 2 01 01 2" [75] "2005 05 01 01 3 01 01 3" "2005 05 01 01 4 01 01 4" [77] "2005 05 01 01 5 01 01 5" "2005 05 51 52 7 51 51 0" [79] "2005 05 52 52 1 52 52 1" "2005 05 52 52 2 52 52 2" [81] "2005 05 52 52 3 52 52 3" "2005 05 52 52 4 52 52 4" [83] "2005 05 52 52 5 52 52 5" "2005 05 52 52 6 52 52 6" [85] "2005 05 00 01 7 52 00 0" "2006 06 01 01 1 01 01 1" [87] "2006 06 01 01 2 01 01 2" "2006 06 01 01 3 01 01 3" [89] "2006 06 01 01 4 01 01 4" "2006 06 01 01 5 01 01 5" [91] "2006 06 01 01 6 01 01 6" "2006 06 52 52 1 52 52 1" [93] "2006 06 52 52 2 52 52 2" "2006 06 52 52 3 52 52 3" [95] "2006 06 52 52 4 52 52 4" "2006 06 52 52 5 52 52 5" [97] "2006 06 52 52 6 52 52 6" "2006 06 52 53 7 52 52 0" [99] "2007 07 01 00 1 01 01 1" "2007 07 01 00 2 01 01 2" [101] "2007 07 01 00 3 01 01 3" "2007 07 01 00 4 01 01 4" [103] "2007 07 01 00 5 01 01 5" "2007 07 01 00 6 01 01 6" [105] "2007 07 01 01 7 01 01 0" "2007 07 52 51 2 52 52 2" [107] "2007 07 52 51 3 52 52 3" "2007 07 52 51 4 52 52 4" [109] "2007 07 52 51 5 52 52 5" "2007 07 52 51 6 52 52 6" [111] "2007 07 52 52 7 52 52 0" "2008 08 53 52 1 01 53 1" [113] "2008 08 00 00 2 01 00 2" "2008 08 00 00 3 01 00 3" [115] "2008 08 00 00 4 01 00 4" "2008 08 00 00 5 01 00 5" [117] "2008 08 00 00 6 01 00 6" "2008 08 00 01 7 01 00 0" [119] "2008 08 01 01 1 02 01 1" "2008 08 51 51 4 52 51 4" [121] "2008 08 51 51 5 52 51 5" "2008 08 51 51 6 52 51 6" [123] "2008 08 51 52 7 52 51 0" "2009 09 52 52 1 01 52 1" [125] "2009 09 52 52 2 01 52 2" "2009 09 52 52 3 01 52 3" [127] "2009 09 00 00 4 01 00 4" "2009 09 00 00 5 01 00 5" [129] "2009 09 00 00 6 01 00 6" "2009 09 00 01 7 01 00 0" [131] "2009 09 01 01 1 02 01 1" "2009 09 01 01 2 02 01 2" [133] "2009 09 01 01 3 02 01 3" "2009 09 51 51 5 52 51 5" [135] "2009 09 51 51 6 52 51 6" "2009 09 51 52 7 52 51 0" [137] "2009 09 52 52 1 53 52 1" "2009 09 52 52 2 53 52 2" [139] "2009 09 52 52 3 53 52 3" "2009 09 52 52 4 53 52 4" [141] "2009 09 00 00 5 53 00 5" "2009 09 00 00 6 53 00 6" [143] "2009 09 00 01 7 53 00 0" "2010 10 01 01 1 01 01 1" [145] "2010 10 01 01 2 01 01 2" "2010 10 01 01 3 01 01 3" [147] "2010 10 01 01 4 01 01 4" "2010 10 51 51 6 51 51 6" [149] "2010 10 51 52 7 51 51 0" "2010 10 52 52 1 52 52 1" [151] "2010 10 52 52 2 52 52 2" "2010 10 52 52 3 52 52 3" [153] "2010 10 52 52 4 52 52 4" "2010 10 52 52 5 52 52 5" > > ## tests of earlier years. Default format is OS-dependent, so don't test it. > ## ISOdate only accepts positive years. > z <- as.Date(ISOdate(c(0, 8, 9, 10, 11, 20, 110, 1010), 1, 10)) - 3630 > strftime(z, "%04Y-%m-%d") # with leading zero(s) [1] "-010-02-01" "-002-02-01" "-001-02-02" "0000-02-02" "0001-02-01" [6] "0010-02-01" "0100-02-01" "1000-02-01" > strftime(z, "%_4Y-%m-%d") # with leading space(s) [1] " -10-02-01" " -2-02-01" " -1-02-02" " 0-02-02" " 1-02-01" [6] " 10-02-01" " 100-02-01" "1000-02-01" > strftime(z, "%0Y-%m-%d") # without [1] "-10-02-01" "-2-02-01" "-1-02-02" "0-02-02" "1-02-01" [6] "10-02-01" "100-02-01" "1000-02-01" > > > ## more test of strftime > x <- ISOdate(2014, 3, 10, c(7, 13)) > fmts <- c("%Y-%m-%d %H:%M:%S", "%F", "%A %a %b %h %e %I %j", + ## locale-dependent ones + "%X", # but the same in all English locales + "%c", "%x", "%p", "%r") > for (f in fmts) print(format(x, f)) [1] "2014-03-10 07:00:00" "2014-03-10 13:00:00" [1] "2014-03-10" "2014-03-10" [1] "Monday Mon Mar Mar 10 07 069" "Monday Mon Mar Mar 10 01 069" [1] "07:00:00" "13:00:00" [1] "Mon Mar 10 07:00:00 2014" "Mon Mar 10 13:00:00 2014" [1] "03/10/14" "03/10/14" [1] "AM" "PM" [1] "07:00:00 AM" "01:00:00 PM" >