Some code [Software]

posted by Helmut Homepage – Vienna, Austria, 2019-03-22 17:58 (1718 d 16:27 ago) – Posting: # 20068
Views: 7,698

Hi Dr Anonymous :-D

❝ I agree, patience is the key :), I use R studio predominantly and have a GitHub account (need to be more active though).

So you are an advanced RUser!

❝ ❝ ....This is the number of seconds since midnight, January 1, 1960…

❝ Woah, thanks for the explanation.

Welcome. Didn’t know it until yesterday either.

❝ […] I believed ISO8601 was majorly the standard time format

In many countries. In Austria it is not just a norm but legally binding. Rarely used in daily life.

❝ Thanks for working it out, I tried replicating this and this looks promising for me to try it out further.

I was curious myself. My latest code:

library(lubridate) # Makes job easier but has large footprint. See also:
# For a list of abbreviated locations / time zones: OlsonNames()
# or
# I recommend to give the location; if applicable it will observe
# local daylight time switches. In case you are lost, retrieve the location
# R is running in: Sys.timezone()

lct       <- Sys.getlocale("LC_TIME") # Save original locale.
invisible(Sys.setlocale("LC_TIME", "C"))
my_tz     <- 'Europe/Vienna'
my_time   <- now(tzone=my_tz)
IBM_tz    <- 'US/Eastern'
IBM_time  <- with_tz(my_time, IBM_tz)
your_tz   <- 'Asia/Kolkata'
your_time <- with_tz(my_time, your_tz)
NZ_tz     <- 'Pacific/Auckland'
NZ_time   <- with_tz(my_time, NZ_tz)
tz        <- c(my_tz, IBM_tz, your_tz, NZ_tz)
dt        <- c(as.character(my_time), as.character(IBM_time),
               as.character(your_time), as.character(NZ_time))
UTC.dt    <- offset <- rep(NA, length(dt))
for (j in seq_along(dt)) { # Cannot be vectorized!
  dt[j]     <- format(as.POSIXct(dt[j], tz=tz[j]), tz=tz[j], usetz=TRUE)
  UTC.dt[j] <- format(as.POSIXct(dt[j], tz=tz[j]), tz='UTC', usetz=TRUE)
  x         <- as.numeric(difftime(dt[j], UTC.dt[j], units="hours"))
  offset[j] <- sprintf("%+02d:%02d", x %/% 1, (x - x %/% 1)*60)
df <- data.frame(location=tz, local.datetime=dt, offset, UTC.datetime=UTC.dt,
                  format='%F %T')), format='%d%b%y:%H:%M:%S'),
                   format='%F %T')), format='%d%b%y:%H:%M:%S'),
                 row.names=NULL, stringsAsFactors=FALSE)
invisible(Sys.setlocale("LC_TIME", lct)) # Restore original locale.
print(df, row.names=FALSE)               # Here we are.

Which gave on my machine:

         location           local.datetime offset            UTC.datetime loc.SAS.datetime UTC.SAS.datetime
    Europe/Vienna  2019-03-22 18:32:57 CET  +1:00 2019-03-22 17:32:57 UTC 22Mar19:18:32:57 22Mar19:17:32:57
       US/Eastern  2019-03-22 13:32:57 EDT  -4:00 2019-03-22 17:32:57 UTC 22Mar19:13:32:57 22Mar19:17:32:57
     Asia/Kolkata  2019-03-22 23:02:57 IST  +5:30 2019-03-22 17:32:57 UTC 22Mar19:23:02:57 22Mar19:17:32:57
 Pacific/Auckland 2019-03-23 06:32:57 NZDT +13:00 2019-03-22 17:32:57 UTC 23Mar19:06:32:57 22Mar19:17:32:57

Note the different local times: Poughkeepsie changed EST ↑ EDT on March 10th, Austria will change CET ↑ CEST on March 31th, and New Zealand will change NZDT ↓ NZT on April 7th.
See this funny story.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes

Complete thread:

UA Flag
 Admin contact
22,811 posts in 4,783 threads, 1,639 registered users;
31 visitors (0 registered, 31 guests [including 8 identified bots]).
Forum time: 10:25 CET (Europe/Vienna)

I have never in my life learned anything
from any man who agreed with me.    Dudley Field Malone

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz