Hi R Devel, I just ran into a corner case with 'strptime'. Recall that the "%OS" conversion accepts fractional seconds:> strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec[1] 14.01234 Unfortunately for my application it seems to be "greedy", in that it tries to parse a decimal point which might belong to the rest of the format:> strptime("17_35_14.mp3","%H_%M_%OS.mp3")[1] NA If I use "_" instead of ".", then it works:> strptime("17_35_14_mp3","%H_%M_%OS_mp3")[1] "2017-01-10 17:35:14 PST" Perhaps a low priority, but seems like a bug to me... Thanks, Frederick
On 10 January 2017 at 17:48, frederik at ofb.net wrote: | Hi R Devel, | | I just ran into a corner case with 'strptime'. Recall that the "%OS" | conversion accepts fractional seconds: | | > strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec | [1] 14.01234 | | Unfortunately for my application it seems to be "greedy", in that it | tries to parse a decimal point which might belong to the rest of the | format: | | > strptime("17_35_14.mp3","%H_%M_%OS.mp3") | [1] NA Maybe just don't use the optional O: R> strptime("17_35_14.mp3","%H_%M_%S.mp3")$sec [1] 14 R> R> strptime("17_35_14.mp3","%H_%M_%S.mp3") [1] "2017-01-10 17:35:14 CST" R> Dirk | If I use "_" instead of ".", then it works: | | > strptime("17_35_14_mp3","%H_%M_%OS_mp3") | [1] "2017-01-10 17:35:14 PST" | | Perhaps a low priority, but seems like a bug to me... | | Thanks, | | Frederick | | ______________________________________________ | R-devel at r-project.org mailing list | https://stat.ethz.ch/mailman/listinfo/r-devel -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
On Tue, Jan 10, 2017 at 08:13:21PM -0600, Dirk Eddelbuettel wrote:> > On 10 January 2017 at 17:48, frederik at ofb.net wrote: > | Hi R Devel, > | > | I just ran into a corner case with 'strptime'. Recall that the "%OS" > | conversion accepts fractional seconds: > | > | > strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec > | [1] 14.01234 > | > | Unfortunately for my application it seems to be "greedy", in that it > | tries to parse a decimal point which might belong to the rest of the > | format: > | > | > strptime("17_35_14.mp3","%H_%M_%OS.mp3") > | [1] NA > > Maybe just don't use the optional O: > > R> strptime("17_35_14.mp3","%H_%M_%S.mp3")$sec > [1] 14 > R> > R> strptime("17_35_14.mp3","%H_%M_%S.mp3") > [1] "2017-01-10 17:35:14 CST" > R>For my application I wanted to be able to accept both formats, "14.mp3" and "14.01234.mp3". Since "14" and "14.01234" both parse as numbers, I thought "%OS" should accept both. Yes, I can work around it fairly easily. Frederick
Hi R Devel, I wrote some code which depends on 'strptime' being able to parse an incomplete date, like this:> base::strptime("2016","%Y")[1] "2016-01-14 PST" The above works - although it's odd that it gives the month and day for Sys.time(). I might expect it to set them both to zero as the GNU libc strptime does on my system, or to use January 1 which would also be reasonable. When I specify the month, however, I get NA:> base::strptime("2016-12","%Y-%m")[1] NA> base::strptime("1", "%m")[1] NA Any reason for this to be the case? I reported a bug here: https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17212 but I don't think I'm getting emails from Bugzilla so maybe best to ping me if anyone replies there instead. I've just written a simple reimplementation of 'strptime' for my own use; I hope this bug report may be useful to others. Thank you, Frederick
Hi Frederik, On Mon, 2017-01-16 at 18:20 -0800, frederik at ofb.net wrote:> Hi R Devel, > > I wrote some code which depends on 'strptime' being able to parse an > incomplete date, like this: > > > > > base::strptime("2016","%Y") > [1] "2016-01-14 PST" > > The above works - although it's odd that it gives the month and day > for Sys.time(). I might expect it to set them both to zero as the GNU > libc strptime does on my system, or to use January 1 which would also > be reasonable.From the help page for strptime: "For ?strptime? the input string need not specify the date completely: it is assumed that unspecified seconds, minutes or hours are zero, and an unspecified year, month or day is the current one." ?> When I specify the month, however, I get NA: > > > > > base::strptime("2016-12","%Y-%m") > [1] NA > > > > base::strptime("1", "%m") > [1] NA > > Any reason for this to be the case?Also from the help page: "(However, if a month is specified, the day of that month has to be specified by ?%d? or ?%e? since the current day of the month need not be valid for the specified month.)" If strptime("2016-2", "%Y-%m") just filled in the current day then it would give valid output when called on the 1st to the 28th of each month, but would give either invalid output or fail when called on the 29th to the 31st of any month. This would be a nightmare to debug. The current behaviour lets you know there is a logical problem with your input.> I reported a bug here: > > https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17212 > > but I don't think I'm getting emails from Bugzilla so maybe best to > ping me if anyone replies there instead.See the general guidance on submitting bug reports: "Code doing something unexpected is not necessarily a bug - make sure to carefully review the documentation for the function you are calling to see if the behaviour it exhibits is what it was designed to do, even if it?s not what you want." https://www.r-project.org/bugs.html Martyn> I've just written a simple reimplementation of 'strptime' for my own > use; I hope this bug report may be useful to others. > > Thank you, > > Frederick > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel