[#107430] [Ruby master Feature#18566] Merge `io-wait` gem into core IO — "byroot (Jean Boussier)" <noreply@...>
Issue #18566 has been reported by byroot (Jean Boussier).
22 messages
2022/02/02
[ruby-core:107427] [Ruby master Bug#18565] strptime reports invalid date when string is "130AM" and format string is '%I:%M%p'
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2022-02-02 02:22:10 UTC
List:
ruby-core #107427
Issue #18565 has been updated by jeremyevans0 (Jeremy Evans).
Status changed from Open to Rejected
I don't think this is a bug. `strptime` is supposed to be the inverse of `strftime`:
```ruby
DateTime.now.strftime('%I%M%p')
# => "0617PM"
DateTime.now.strftime('%l%M%p')
# => " 617PM"
```
If you pass the same formats to `strptime`, it will work correctly:
```ruby
DateTime.strptime("0130PM", '%I%M%p')
# => #<DateTime: 2022-02-01T13:30:00+00:00 ((2459612j,48600s,0n),+0s,2299161j)>
DateTime.strptime(" 130PM", '%l%M%p')
# => #<DateTime: 2022-02-01T13:30:00+00:00 ((2459612j,48600s,0n),+0s,2299161j)>
```
The fact that `1:` works with the `%I`/`%l` formats is due to implementation details, not by design, and should not be relied on.
----------------------------------------
Bug #18565: strptime reports invalid date when string is "130AM" and format string is '%I:%M%p'
https://bugs.ruby-lang.org/issues/18565#change-96326
* Author: CaryInVictoria (Cary Swoveland)
* Status: Rejected
* Priority: Normal
* ruby -v: 2.7.1
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`DateTime.strptime("1:30PM", '%I:%M%p')` and `DateTime.strptime("1:30PM", '%l:%M%p')` both return
`#<DateTime: 2022-02-01T13:30:00+00:00 ((2459612j,48600s,0n),+0s,2299161j)>`
`DateTime.strptime("130PM", '%I%M%p')` and `DateTime.strptime("130PM", '%l%M%p')`
both raise the exception `Date::Error: invalid date`
I don't understand why an exception should be raised when the string is `"130PM"`. Is this a bug?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>