Bug in as.POSIXct regarding AM/PM

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in as.POSIXct regarding AM/PM

Ted Zeng
Dear All,

I encounted in a problem with as.POSIXct() function.

> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] NA
> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
[1] NA

I have tried this in the R version 2.11.1,  R version 2.10.1  and R version 2.9.2 . They all does not work. The operation system is win7.

Thanks

Ted
Reply | Threaded
Open this post in threaded view
|

Re: Bug in as.POSIXct regarding AM/PM

David Winsemius

On Oct 8, 2010, at 5:54 AM, Ted Zeng (曾振兴) wrote:

>
> Dear All,
>
> I encounted in a problem with as.POSIXct() function.
>
>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>
> I have tried this in the R version 2.11.1,  R version 2.10.1  and R  
> version
> 2.9.2 . They all does not work. The operation system is win7.
>

Cannot reproduce on R 2.11.1 Mac OSX 10/5/8
R version 2.11.1 Patched (2010-06-14 r52281)
 > as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 01:00:00 EDT"
 > as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 14:00:00 EDT"

Is this a "daylight savings" time switch in your locale? Those  
switches generally occur at night (suggested by your 1AM NA and not by  
the 2PM value) but my experience is limited to the US so I don't know  
all possibilities.

You have not included the at a minimum information requested in the  
Posting Guide:

?sessionInfo

This seems likely due to your setup or possibly some sort of encoding  
issue that might be easier to reproduce with the results of sessionInfo.


--
David Winsemius, MD
West Hartford, CT

 > sessionInfo()
R version 2.11.1 Patched (2010-06-14 r52281)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in as.POSIXct regarding AM/PM

Gabor Grothendieck
In reply to this post by Ted Zeng
On Fri, Oct 8, 2010 at 5:54 AM, Ted Zeng (曾振兴) <[hidden email]> wrote:

>
> Dear All,
>
> I encounted in a problem with as.POSIXct() function.
>
>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>
> I have tried this in the R version 2.11.1,  R version 2.10.1  and R version
> 2.9.2 . They all does not work. The operation system is win7.


I can reproduce this on Windows Vista if I set the locale of LC_Time
to Chinese.  If its set to English then it works ok:

> Sys.setlocale("LC_TIME", "Chinese")
[1] "Chinese (Simplified)_People's Republic of China.936"
>
> Sys.getlocale("LC_TIME")
[1] "Chinese (Simplified)_People's Republic of China.936"
>
> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] NA
>
>
> Sys.setlocale("LC_TIME", "English")
[1] "English_United States.1252"
>
> Sys.getlocale("LC_TIME") # check it
[1] "English_United States.1252"
>
> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 01:00:00 EDT"
>
>
> R.version.string
[1] "R version 2.11.1 Patched (2010-05-31 r52167)"
> win.version()
[1] "Windows Vista (build 6002) Service Pack 2"


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in as.POSIXct regarding AM/PM

Brian Ripley
In reply to this post by David Winsemius
On Fri, 8 Oct 2010, David Winsemius wrote:

>
> On Oct 8, 2010, at 5:54 AM, Ted Zeng (曾振兴) wrote:
>
>>
>> Dear All,
>>
>> I encounted in a problem with as.POSIXct() function.
>>
>>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
>> [1] NA
>>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
>> [1] NA
>>
>> I have tried this in the R version 2.11.1,  R version 2.10.1  and R version
>> 2.9.2 . They all does not work. The operation system is win7.
At least one did work, as you showed output.

> Cannot reproduce on R 2.11.1 Mac OSX 10/5/8
> R version 2.11.1 Patched (2010-06-14 r52281)
>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] "2009-03-26 01:00:00 EDT"
>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] "2009-03-26 14:00:00 EDT"
>
> Is this a "daylight savings" time switch in your locale? Those switches
> generally occur at night (suggested by your 1AM NA and not by the 2PM value)
> but my experience is limited to the US so I don't know all possibilities.
As far as I am aware all recent DST transitions are on a Sunday in all
the timezones I have had cause to look at (quite a few over the
years).

> You have not included the at a minimum information requested in the Posting
> Guide:
>
> ?sessionInfo
>
> This seems likely due to your setup or possibly some sort of encoding issue
> that might be easier to reproduce with the results of sessionInfo.

Most likely AM/PM is not supported in the unstated locale.  See
?strptime, which does say

      ‘%p’ AM/PM indicator in the locale.  Used in conjunction with ‘%I’
           and *not* with ‘%H’.  An empty string in some locales.
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



>
>
> --
> David Winsemius, MD
> West Hartford, CT
>
>> sessionInfo()
> R version 2.11.1 Patched (2010-06-14 r52281)
> x86_64-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Brian D. Ripley,                  [hidden email]
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
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in as.POSIXct regarding AM/PM

Ei-ji Nakama
In reply to this post by Ted Zeng
Hi,

> Sys.setenv(TZ="PRC")
> Sys.setlocale("LC_TIME", "Chinese")
[1] "Chinese (Simplified)_People's Republic of China.936"
> as.POSIXct("2009/03/26 01:00:00 上午" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 01:00:00 CST"
> as.POSIXct("2009/03/26 01:00:00 下午" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 13:00:00 CST"
>  Sys.setlocale("LC_TIME", "American")
[1] "English_United States.1252"
> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 01:00:00 CST"
>

2010/10/8 Ted Zeng (曾振兴) <[hidden email]>:

>
> Dear All,
>
> I encounted in a problem with as.POSIXct() function.
>
>> as.POSIXct("2009/03/26 01:00:00 AM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>> as.POSIXct("2009/03/26 02:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
> [1] NA
>
> I have tried this in the R version 2.11.1,  R version 2.10.1  and R version
> 2.9.2 . They all does not work. The operation system is win7.
>
> Thanks
>
> Ted
> --
> View this message in context: http://r.789695.n4.nabble.com/Bug-in-as-POSIXct-regarding-AM-PM-tp2968076p2968076.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>



--
EI-JI Nakama  <nakama (a) ki.rim.or.jp>
"\u4e2d\u9593\u6804\u6cbb"  <nakama (a) ki.rim.or.jp>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bug in as.POSIXct regarding AM/PM

Ted Zeng
In reply to this post by Ted Zeng
My locale information is as follows:
> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-pc-mingw32

locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936  
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C                                                  
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] JGR_1.7-2    iplots_1.1-3 JavaGD_0.5-3 rJava_0.8-5

loaded via a namespace (and not attached):
[1] tools_2.11.1



However, as Gabor said, If I set the locale time to "English". It works.

> Sys.setlocale("LC_TIME", "English")
[1] "English_United States.1252"
> Sys.getlocale("LC_TIME")
[1] "English_United States.1252"
> as.POSIXct("2009/03/26 01:00:00 PM" , format="%Y/%m/%d %I:%M:%S %p")
[1] "2009-03-26 13:00:00 CST"


SO, What is the Problem? How to solve this problem.