[R] Difference between times

David Winsemius dwinsemius at comcast.net
Sun Apr 20 20:35:50 CEST 2014

On Apr 20, 2014, at 2:16 AM, Prof Brian Ripley wrote:

> On 20/04/2014 08:50, Prof Brian Ripley wrote:
>> On 18/04/2014 21:46, David Winsemius wrote:
>>> On Apr 18, 2014, at 12:59 PM, Prof Brian Ripley wrote:
>>>> On 18/04/2014 19:46, Rui Barradas wrote:
>>>>> Hello,
>>>>> The reason why is that you've misspelled CET (not CEST)
>>>> Neither CET nor CEST are portable time-zone names.  We have not been
>>>> given the 'at a minimum' information required by the posting guide,
>>>> so please read ?Sys.timezone on your system.
>>> Dear Prof;
>>> Thanks for the impetus to yet again read that page. Despite frequently
>>> reading help pages and in particular reading that one many times, I
>>> still was not getting the 'tz' arguments correct on a Mac. I do now
>>> see that I was spelling my TZ incorrectly (as "Americas/Los_Angeles"
>>> rather than "America/Los_Angeles".
>>> Fellow Mac users may face a problem when using the Finder unless they
>>> set it up to display hidden ('dot') files. The /usr/ folder is "greyed
>>> out" but it still does open. If I restore my Finder defaults to not
>>> show system files and folders, I no longer see that directory and
>>> would not have been able to resolve my spelling error on my own:
> You can always use the command-line or OlsonNames() in R.

I'm not finding an OlsonNames function on a Mac (but is that because I haven't updated?). Before seeing that the zone-checking feature had been added as a feature, I was building an OlsonNames function that extracts the sub-directories of the zoneinfo directory and appends the file names to them as well as extracting the non-OlsonNames entries in zoneinfo. My plan had been to make my own warnings in strptime, but that appears to be unnecessary.

OlsonNames <- function(onlyOlson=FALSE) { 
  MacOlsonDirs <- system('ls -p /usr/share/zoneinfo ', intern=TRUE)
  OlsonNames <- unlist( lapply( MacOlsonDirs[grep("/$", MacOlsonDirs)], 
                            function(dir) paste0( dir, 
                                           system( paste0('ls -p /usr/share/zoneinfo/', dir) , 
                                                   intern=TRUE) ) ) )
  nonOlsonNames <- MacOlsonDirs[grepl("^[A-Z]", MacOlsonDirs) & ! grepl("/$", MacOlsonDirs) ]
  if ( !onlyOlson){ c(OlsonNames, nonOlsonNames)} else {OlsonNames}

Yes. It is because I haven't updated. I now see this in the NEWS that was posted in this list 10 days ago.

There is more support to explore the system's idea of time-zone
    names.  Sys.timezone() tries to give the current system setting
    by name (and succeeds at least on Linux, OS X, Solaris and
    Windows), and OlsonNames() lists the names in the system's Olson
    database. Sys.timezone(location = FALSE) gives the previous
I guess I will have fun comparing my efforts with those of the masters.

>>>> dt2 = as.POSIXct("2014-04-18 09.00", format="%Y-%m-%d %H.%M", tz =
>>>> "America/New_York")
>>>>  dt1 = as.POSIXct("2014-04-18 09.00", format="%Y-%m-%d %H.%M", tz =
>>>> "America/Los_Angeles")
>>>>  dt1-dt2
>>> Time difference of 3 hours
>>> I don't suppose a warning could be issued by the as.POSIXct code when
>>> a "tz" argument is not found in the database to let people know that
>>> 'UTC' will be the default?
>> No, as the underlying POSIX function does not report this.  We could
>> perhaps do this on platforms which use --with-internal-tzcode but not
>> e.g. on Linux.
> In fact we already do: R 3.1.0 on a Mac shows

My apologies. And thank you to whomever added the feature and to you, Prof, for checking and letting us know. I was going to offer the code above as a patch but that seems not needed now. I have not yet updated to 3.1.0. The Mavericks/3.1.0 incompatibilities have been scaring me off from updating. Still on Lion/3.0.2.

> > as.POSIXct("2014-04-18 09.00", format="%Y-%m-%d %H.%M", tz = "Americas/New_York")
> [1] "2014-04-18 09:00:00 GMT"
> Warning messages:
> 1: In strptime(x, format, tz = tz) : unknown timezone 'Americas/New_York'
> 2: In as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...) :
>  unknown timezone 'Americas/New_York'
> 3: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'Americas/New_York'

Thank you, all of R-Core.

> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595

David Winsemius
Alameda, CA, USA

More information about the R-help mailing list