r - POSIXct to numeric using different timezones -


i think must not understand how posixct works, or something. far understand, seconds since epoch, epoch being standard time 1970-01-01 gmt.

i take 2 posixct times 1 in est 1 in pst same absolute time. yet, when convert them numeric value, result different... point me doing wrong?

> pst = as.posixct('2011-01-10 06:45:00', tz = 'pst') > est = as.posixct('2011-01-10 09:45:00', tz = 'est') > as.numeric(pst)  [1] 1294641900 > as.numeric(est)  [1] 1294670700 

here session info:

> sessioninfo() r version 2.13.0 (2011-04-13) platform: x86_64-unknown-linux-gnu (64-bit)  locale:  [1] lc_ctype=en_us.utf-8       lc_numeric=c               lc_time=en_us.utf-8        lc_collate=en_us.utf-8     lc_monetary=c              lc_messages=en_us.utf-8    lc_paper=en_us.utf-8       lc_name=c\                   lc_address=c [10] lc_telephone=c             lc_measurement=en_us.utf-8 lc_identification=c  attached base packages: [1] grid      stats     graphics  grdevices utils     datasets  methods   base  other attached packages:  [1] rsqlite_0.9-4      snow_0.3-8         rmysql_0.8-0       dbi_0.2-5          gtools_2.6.2       reshape2_1.1       ggplot2_0.8.9      proto_0.3-9.2      reshape_0.8.4      ftrading_2100.76   fbasics_\ 2110.79    mass_7.3-12 [13] timeseries_2130.92 timedate_2131.00   plyr_1.7.1  loaded via namespace (and not attached): [1] stringr_0.4  tools_2.13.0 

timezone names not simple like. see http://en.wikipedia.org/wiki/tz_database background , http://en.wikipedia.org/wiki/list_of_tz_database_time_zones list of names used. far best thing use tz = 'country / city' notation , explicitly set time zone of local system.

so, here's script uses 2 different methods encode time zone:

sys.setenv(tz='gmt') pst.abr <- as.posixct('2011-01-10 06:45:00', tz = 'pst') est.abr <- as.posixct('2011-01-10 09:45:00', tz = 'est') pst.country.city <- as.posixct('2011-01-10 06:45:00', tz = 'america/los_angeles') est.country.city <- as.posixct('2011-01-10 09:45:00', tz = 'america/new_york') 

if @ posixct values have have been pst, see have 2 different values. starting abbreviation (tz ='pst'), this:

> pst.abr [1] "2011-01-10 06:45:00 utc" > as.numeric(pst.abr) [1] 1294641900 

you see data defined using tz='pst' isn't in pst timezone, has inherited system's timezone.

compare data defined using country\city:

> as.numeric(pst.country.city) [1] 1294670700 > pst.country.city [1] "2011-01-10 06:45:00 pst" 

so, data explicitly encode country/city information has correct timezone information.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -