R Under development (unstable) (2023-03-21 r84017) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: aarch64-apple-darwin22.1.0 (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 and platforms > ### without tm_zone/tm_gmtoff. > > 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" > ## use pf %z needs tm_gmtoff > 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), where supported [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), where supported [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" > > ## Moved from reg-tests-1d.R > ## as.POSIXlt() gave integer overflow > ## and needed C-level change for 32-bit time_t. > .Machine$sizeof.time_t [1] 8 > (z <- .Date(2^31 + 10)) [1] "5881580-07-22" > as.POSIXlt(z)$year == 5879680L [1] TRUE > ## year was negative in R <= 4.2.1, even for 64-bit time_t > > > ## ------------- Tests of far-distant dates ----------- > Sys.setenv(TZ = "Europe/London") > ## the pre-1902 POSIXct values wil be 75s out on platdorm that do not > ## know about UK changes prior to 1902 (in fact in 1847-12-01: see below). > as.POSIXct("4000-07-01") [1] "4000-07-01 BST" > as.Date("4000-07-01") [1] "4000-07-01" > zz <- z <- as.POSIXlt("2000-07-01") > unclass(z) $sec [1] 0 $min [1] 0 $hour [1] 0 $mday [1] 1 $mon [1] 6 $year [1] 100 $wday [1] 6 $yday [1] 182 $isdst [1] 1 $zone [1] "BST" $gmtoff [1] NA attr(,"tzone") [1] "Europe/London" "GMT" "BST" attr(,"balanced") [1] TRUE > > years <- c(-1e6, -1e5, -1e4, seq(-1000, 4000, by = 100), 1e4, 1e5, 1e6) > y <- character(length(years)) > for(i in seq_along(years)) { + zz$year = years[i] - 1900 + y[i] <- strftime(zz) + } > ## IGNORE_RDIFF_BEGIN > y [1] "-1000000-07-01" "-100000-07-01" "-10000-07-01" "-1000-07-01" [5] "-900-07-01" "-800-07-01" "-700-07-01" "-600-07-01" [9] "-500-07-01" "-400-07-01" "-300-07-01" "-200-07-01" [13] "-100-07-01" "0000-07-01" "0100-07-01" "0200-07-01" [17] "0300-07-01" "0400-07-01" "0500-07-01" "0600-07-01" [21] "0700-07-01" "0800-07-01" "0900-07-01" "1000-07-01" [25] "1100-07-01" "1200-07-01" "1300-07-01" "1400-07-01" [29] "1500-07-01" "1600-07-01" "1700-07-01" "1800-07-01" [33] "1900-07-01" "2000-07-01" "2100-07-01" "2200-07-01" [37] "2300-07-01" "2400-07-01" "2500-07-01" "2600-07-01" [41] "2700-07-01" "2800-07-01" "2900-07-01" "3000-07-01" [45] "3100-07-01" "3200-07-01" "3300-07-01" "3400-07-01" [49] "3500-07-01" "3600-07-01" "3700-07-01" "3800-07-01" [53] "3900-07-01" "4000-07-01" "10000-07-01" "100000-07-01" [57] "1000000-07-01" > ## IGNORE_RDIFF_END > > y <- double(length(years)) > for(i in seq_along(years)) { + zz$year = years[i] - 1900 + zz$isdst <- -1 # some are DST, some not so let the code decide + y[i] <- as.POSIXct(zz) + } > print(y, digits=14) [1] -31619103494325 -3217846694325 -377721014325 -93708489525 [5] -90552815925 -87397055925 -84241382325 -81085708725 [9] -77930035125 -74774275125 -71618601525 -68462927925 [13] -65307254325 -62151494325 -58995820725 -55840147125 [17] -52684473525 -49528713525 -46373039925 -43217366325 [21] -40061692725 -36905932725 -33750259125 -30594585525 [25] -27438911925 -24283151925 -21127478325 -17971804725 [29] -14816131125 -11660371125 -8504697525 -5349023925 [33] -2193350400 962406000 4118079600 7273753200 [37] 10429426800 13585186800 16740860400 19896534000 [41] 23052207600 26207967600 29363641200 32519314800 [45] 35674988400 38830748400 41986422000 45142095600 [49] 48297769200 51453529200 54609202800 57764876400 [53] 60920550000 64076310000 253418022000 3093543702000 [57] 31494800502000 > y <- .POSIXct(y) > ## IGNORE_RDIFF_BEGIN > (y1 <- strftime(y)) # leading zeros or spaces is platform-dependant [1] "-1000000-07-01" "-100000-07-01" "-10000-07-01" "-1000-07-01" [5] "-900-07-01" "-800-07-01" "-700-07-01" "-600-07-01" [9] "-500-07-01" "-400-07-01" "-300-07-01" "-200-07-01" [13] "-100-07-01" "0000-07-01" "0100-07-01" "0200-07-01" [17] "0300-07-01" "0400-07-01" "0500-07-01" "0600-07-01" [21] "0700-07-01" "0800-07-01" "0900-07-01" "1000-07-01" [25] "1100-07-01" "1200-07-01" "1300-07-01" "1400-07-01" [29] "1500-07-01" "1600-07-01" "1700-07-01" "1800-07-01" [33] "1900-07-01" "2000-07-01" "2100-07-01" "2200-07-01" [37] "2300-07-01" "2400-07-01" "2500-07-01" "2600-07-01" [41] "2700-07-01" "2800-07-01" "2900-07-01" "3000-07-01" [45] "3100-07-01" "3200-07-01" "3300-07-01" "3400-07-01" [49] "3500-07-01" "3600-07-01" "3700-07-01" "3800-07-01" [53] "3900-07-01" "4000-07-01" "10000-07-01" "100000-07-01" [57] "1000000-07-01" > ## IGNORE_RDIFF_END > y2 <- strftime(y, "%_4Y-%m-%d") # not all platforms interpret this > if(y2[1] != "4Y-07-01") print(y2) else message('format "%_4Y" unsupported') [1] "-1000000-07-01" "-100000-07-01" "-10000-07-01" "-1000-07-01" [5] "-900-07-01" "-800-07-01" "-700-07-01" "-600-07-01" [9] "-500-07-01" "-400-07-01" "-300-07-01" "-200-07-01" [13] "-100-07-01" " 0-07-01" " 100-07-01" " 200-07-01" [17] " 300-07-01" " 400-07-01" " 500-07-01" " 600-07-01" [21] " 700-07-01" " 800-07-01" " 900-07-01" "1000-07-01" [25] "1100-07-01" "1200-07-01" "1300-07-01" "1400-07-01" [29] "1500-07-01" "1600-07-01" "1700-07-01" "1800-07-01" [33] "1900-07-01" "2000-07-01" "2100-07-01" "2200-07-01" [37] "2300-07-01" "2400-07-01" "2500-07-01" "2600-07-01" [41] "2700-07-01" "2800-07-01" "2900-07-01" "3000-07-01" [45] "3100-07-01" "3200-07-01" "3300-07-01" "3400-07-01" [49] "3500-07-01" "3600-07-01" "3700-07-01" "3800-07-01" [53] "3900-07-01" "4000-07-01" "10000-07-01" "100000-07-01" [57] "1000000-07-01" > > y <- double(length(years)) > for(i in seq_along(years)) { + zz$year = years[i] - 1900 + zz$isdst <- -1 + y[i] <- as.Date(zz) + } > y [1] -365961846 -37243596 -4371771 -1084589 -1048065 -1011540 [7] -975016 -938492 -901968 -865443 -828919 -792395 [13] -755871 -719346 -682822 -646298 -609774 -573249 [19] -536725 -500201 -463677 -427152 -390628 -354104 [25] -317580 -281055 -244531 -208007 -171483 -134958 [31] -98434 -61910 -25386 11139 47663 84187 [37] 120711 157236 193760 230284 266808 303333 [43] 339857 376381 412905 449430 485954 522478 [49] 559002 595527 632051 668575 705099 741624 [55] 2933079 35804904 364523154 > class(y) <- "Date" > ## IGNORE_RDIFF_BEGIN > (y3 <- strftime(y)) [1] "-1000000-07-01" "-100000-07-01" "-10000-07-01" "-1000-07-01" [5] "-900-07-01" "-800-07-01" "-700-07-01" "-600-07-01" [9] "-500-07-01" "-400-07-01" "-300-07-01" "-200-07-01" [13] "-100-07-01" "0000-07-01" "0100-07-01" "0200-07-01" [17] "0300-07-01" "0400-07-01" "0500-07-01" "0600-07-01" [21] "0700-07-01" "0800-07-01" "0900-07-01" "1000-07-01" [25] "1100-07-01" "1200-07-01" "1300-07-01" "1400-07-01" [29] "1500-07-01" "1600-07-01" "1700-07-01" "1800-07-01" [33] "1900-07-01" "2000-07-01" "2100-07-01" "2200-07-01" [37] "2300-07-01" "2400-07-01" "2500-07-01" "2600-07-01" [41] "2700-07-01" "2800-07-01" "2900-07-01" "3000-07-01" [45] "3100-07-01" "3200-07-01" "3300-07-01" "3400-07-01" [49] "3500-07-01" "3600-07-01" "3700-07-01" "3800-07-01" [53] "3900-07-01" "4000-07-01" "10000-07-01" "100000-07-01" [57] "1000000-07-01" > ## IGNORE_RDIFF_END > y4 <- strftime(y, "%_4Y-%m-%d") > stopifnot(identical(y3, y1)) > > zz <- as.POSIXlt("1900-07-01") > years <- c(1800, 1847:1848, 1899:1902) > y <- double(length(years)) > for(i in seq_along(years)) { + zz$year = years[i] - 1900 + zz$isdst <- -1 # some are DST, some not so let the code decide + y[i] <- as.POSIXct(zz) + } > print(y, digits=14) [1] -5349023925 -3865881525 -3834259200 -2224886400 -2193350400 -2161814400 [7] -2130278400 > .POSIXct(y) [1] "1800-07-01 LMT" "1847-07-01 LMT" "1848-07-01 GMT" "1899-07-01 GMT" [5] "1900-07-01 GMT" "1901-07-01 GMT" "1902-07-01 GMT" > > ## change of 75s in 1847 > seq(as.POSIXlt("1847-11-24"), as.POSIXlt("1847-12-07"), by ="day") [1] "1847-11-24 00:00:00 LMT" "1847-11-25 00:00:00 LMT" [3] "1847-11-26 00:00:00 LMT" "1847-11-27 00:00:00 LMT" [5] "1847-11-28 00:00:00 LMT" "1847-11-29 00:00:00 LMT" [7] "1847-11-30 00:00:00 LMT" "1847-12-01 00:01:15 GMT" [9] "1847-12-02 00:01:15 GMT" "1847-12-03 00:01:15 GMT" [11] "1847-12-04 00:01:15 GMT" "1847-12-05 00:01:15 GMT" [13] "1847-12-06 00:01:15 GMT" > > ## end of ------------- Tests of far-distant dates ----------- > > ## Tests of %z and %Z for output. > ## Use pf %z needs tm_gmtoff so offsets will otherwise be +0000 > x1 <- strptime("2022-07-01", "%Y-%m-%d", tz = "UTC") > x2 <- strptime("2022-07-01", "%Y-%m-%d", tz = "Europe/Rome") > x1 [1] "2022-07-01 UTC" > x2 [1] "2022-07-01 CEST" > # RFC5322 format > format(x1, "%a, %d %b %Y %H:%M:%S %z") [1] "Fri, 01 Jul 2022 00:00:00 +0000" > # offset may not not determined: +0200 is correct > format(x2, "%a, %d %b %Y %H:%M:%S %z") [1] "Fri, 01 Jul 2022 00:00:00 +0200" > format(as.POSIXct(x2), "%a, %d %b %Y %H:%M:%S %z") # usually correct [1] "Fri, 01 Jul 2022 00:00:00 +0200" > format(x1, "%a, %d %b %Y %H:%M:%S %Z") [1] "Fri, 01 Jul 2022 00:00:00 UTC" > format(x2, "%a, %d %b %Y %H:%M:%S %Z") [1] "Fri, 01 Jul 2022 00:00:00 CEST" > > ## offsets not in whole hours: > x3 <- strptime("2022-01-01", "%Y-%m-%d", tz = "Australia/Adelaide") > format(as.POSIXct(x3), "%a, %d %b %Y %H:%M:%S %z") # +10h30m [1] "Sat, 01 Jan 2022 00:00:00 +1030" > # macOS' strftime prints the next two wrong. > # Liberia does/did not have DST, so second abbreviation may be repeat or empty > x4 <- strptime("1971-01-01", "%Y-%m-%d", tz = "Africa/Monrovia") > y4 <- as.POSIXct(x4) > str(unclass(as.POSIXlt(y4))) # correct gmtoff, printed wrong on macOS List of 11 $ sec : num 0 $ min : int 0 $ hour : int 0 $ mday : int 1 $ mon : int 0 $ year : int 71 $ wday : int 5 $ yday : int 0 $ isdst : int 0 $ zone : chr "MMT" $ gmtoff: int -2670 - attr(*, "tzone")= chr [1:3] "Africa/Monrovia" "GMT" " " - attr(*, "balanced")= logi TRUE > format(y4, "%a, %d %b %Y %H:%M:%S %z") # -44m, should be -00:44:30 [1] "Fri, 01 Jan 1971 00:00:00 -0044" > ## timezones in 1900 might not be supported > x5 <- strptime("1900-03-01", "%Y-%m-%d", tz = "Europe/Paris") > y5 <- as.POSIXct(x5) > str(unclass(as.POSIXlt(y5))) # ditto List of 11 $ sec : num 0 $ min : int 0 $ hour : int 0 $ mday : int 1 $ mon : int 2 $ year : int 0 $ wday : int 4 $ yday : int 59 $ isdst : int 0 $ zone : chr "PMT" $ gmtoff: int 561 - attr(*, "tzone")= chr [1:3] "Europe/Paris" "CET" "CEST" - attr(*, "balanced")= logi TRUE > format(y5, "%a, %d %b %Y %H:%M:%S %z") [1] "Thu, 01 Mar 1900 00:00:00 +0009" >