[R] Strange result for strptime with %p

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Wed Oct 3 01:23:44 CEST 2018


> On Oct 2, 2018, at 10:11 AM, David Winsemius <dwinsemius using comcast.net> wrote:
> 
> 
>> On Oct 2, 2018, at 6:30 AM, Marc Girondot via R-help <r-help using r-project.org> wrote:
>> 
>> Dear members... are these results normal ?
>> 
>> For the first one, no problem. I expected this:
>> 
>>> strptime("05/01/18 01:00:00 AM", format = ("%m/%d/%y %I:%M:%S %p"), tz="Asia/Jayapura")
>> [1] "2018-05-01 01:00:00 WIT"
>> 
>> For this one, it is ok also:
>> 
>>> strptime("05/01/18 01:00:00 AM", format = ("%m/%d/%y %I:%M:%S %p"), tz="Asia/Jayapura")-1
>> [1] "2018-05-01 00:59:59 WIT"
>> 
>> But how to explain this ???
>> 
>>> strptime("05/01/18 00:59:59 AM", format = ("%m/%d/%y %I:%M:%S %p"), tz="Asia/Jayapura")
>> [1] NA
> 
> I'm afraid this is "as documented":
> 
> %I
> Hours as decimal number (01–12).
> 
> I see no reason not to use "%H"

If you need to use %I and %p then you may need to pre-process with sub(" 00", " 12", object_name)

 strptime("05/01/18 12:59:59 AM", format = ("%m/%d/%y %I:%M:%S %p"), tz="Asia/Jayapura")
[1] "2018-05-01 00:59:59 WIT"


> 
> -- 
> David.
>> 
>> Thanks for your advices
>> Marc
>> ______________________
>> 
>> R 3.5.1 on MacOS 10.14
>> 
>>> version
>>               _
>> platform       x86_64-apple-darwin15.6.0
>> arch           x86_64
>> os             darwin15.6.0
>> system         x86_64, darwin15.6.0
>> status
>> major          3
>> minor          5.1
>> year           2018
>> month          07
>> day            02
>> svn rev        74947
>> language       R
>> version.string R version 3.5.1 (2018-07-02)
>> nickname       Feather Spray
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
> 
> David Winsemius
> Alameda, CA, USA
> 
> 'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law




More information about the R-help mailing list