The R Project SVN R

Rev

Rev 75083 | Rev 77978 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 75083 Rev 75087
Line 276... Line 276...
276
  They conventionally have the opposite sign from time-zone
276
  They conventionally have the opposite sign from time-zone
277
  specifications (see \code{\link{Sys.timezone}}): positive values are
277
  specifications (see \code{\link{Sys.timezone}}): positive values are
278
  East of the meridian.  Although there have been time zones with
278
  East of the meridian.  Although there have been time zones with
279
  offsets like 00:09:21 (Paris in 1900), and 00:44:30 (Liberia until
279
  offsets like 00:09:21 (Paris in 1900), and 00:44:30 (Liberia until
280
  1972), offsets are usually treated as whole numbers of minutes, and
280
  1972), offsets are usually treated as whole numbers of minutes, and
281
  are most often seen in RFC 822 email headers in forms like
281
  are most often seen in RFC 5322 email headers in forms like
282
  \code{-0800} (e.g., used on the Pacific coast of the US in winter).
282
  \code{-0800} (e.g., used on the Pacific coast of the USA in winter).
283
  
283
  
284
  Format \code{\%z} can be used for input or output: it is a character
284
  Format \code{\%z} can be used for input or output: it is a character
285
  string, conventionally plus or minus followed by two digits for
285
  string, conventionally plus or minus followed by two digits for
286
  hours and two for minutes: the standards say that an empty string
286
  hours and two for minutes: the standards say that an empty string
287
  should be output if the offset is unknown, but some systems use the
287
  should be output if the offset is unknown, but some systems use the
Line 318... Line 318...
318
  \code{"\%a \%b \%e \%H:\%M:\%S \%Y"}.  As Windows does not comply (and
318
  \code{"\%a \%b \%e \%H:\%M:\%S \%Y"}.  As Windows does not comply (and
319
  uses a date format not understood outside N. America), that format is
319
  uses a date format not understood outside N. America), that format is
320
  used by \R on Windows in all locales.
320
  used by \R on Windows in all locales.
321
}
321
}
322
 
322
 
-
 
323
\section{Sources}{
-
 
324
  Input uses the POSIX function \code{strptime} and output the C99
-
 
325
  function \code{strftime}.
-
 
326
 
-
 
327
  However, not all OSes (notably Windows) provided \code{strptime} and
-
 
328
  many issues were found for those which did, so since 2000 \R has used
-
 
329
  a fork of code from \samp{glibc}.  The forked code uses the
-
 
330
  system's \code{strftime} to find the locale-specific day and month
-
 
331
  names and any AM/PM indicator.
-
 
332
 
-
 
333
  On some platforms (including Windows and by default on macOS) the
-
 
334
  system's \code{strftime} is replaced (along with most of the rest of
-
 
335
  the C-level datetime code) by code modified from IANA's \samp{tzcode}
-
 
336
  distribution (\url{https://www.iana.org/time-zones}).
-
 
337
}
-
 
338
 
323
\references{
339
\references{
324
  International Organization for Standardization (2004, 2000, \dots)
340
  International Organization for Standardization (2004, 2000, \dots)
325
  \emph{ISO 8601.  Data elements and interchange formats --
341
  \emph{ISO 8601.  Data elements and interchange formats --
326
    Information interchange -- Representation of dates and times.}
342
    Information interchange -- Representation of dates and times.}
327
  For links to versions available on-line see (at the time of writing)
343
  For links to versions available on-line see (at the time of writing)
Line 345... Line 361...
345
 
361
 
346
## time to sub-second accuracy (if supported by the OS)
362
## time to sub-second accuracy (if supported by the OS)
347
format(Sys.time(), "\%H:\%M:\%OS3")
363
format(Sys.time(), "\%H:\%M:\%OS3")
348
 
364
 
349
## read in date info in format 'ddmmmyyyy'
365
## read in date info in format 'ddmmmyyyy'
350
## This will give NA(s) in some locales; setting the C locale
366
## This will give NA(s) in some non-English locales; setting the C locale
351
## as in the commented lines will overcome this on most systems.
367
## as in the commented lines will overcome this on most systems.
352
## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
368
## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
353
x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
369
x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
354
z <- strptime(x, "\%d\%b\%Y")
370
z <- strptime(x, "\%d\%b\%Y")
355
## Sys.setlocale("LC_TIME", lct)
371
## Sys.setlocale("LC_TIME", lct)
Line 366... Line 382...
366
z # prints without fractional seconds
382
z # prints without fractional seconds
367
op <- options(digits.secs = 3)
383
op <- options(digits.secs = 3)
368
z
384
z
369
options(op)
385
options(op)
370
 
386
 
371
## time zones name are not portable, but 'EST5EDT' comes pretty close.
387
## time zone names are not portable, but 'EST5EDT' comes pretty close.
372
(x <- strptime(c("2006-01-08 10:07:52", "2006-08-07 19:33:02"),
388
(x <- strptime(c("2006-01-08 10:07:52", "2006-08-07 19:33:02"),
373
               "\%Y-\%m-\%d \%H:\%M:\%S", tz = "EST5EDT"))
389
               "\%Y-\%m-\%d \%H:\%M:\%S", tz = "EST5EDT"))
374
attr(x, "tzone")
390
attr(x, "tzone")
375
 
391
 
376
## An RFC 5322 header (Eastern Canada, during DST)
392
## An RFC 5322 header (Eastern Canada, during DST)