Ruby Time.strptime vs Date.strptime

When analyzing "some dates" (in Ruby), c Time.strptimeand Date.strptimehave a different behavior.

For example, if we try to convert “February 30” (a date that does not exist), we have:

Time.strptime('30 Feb 2015', '%d %b %Y') # will result in this date: 2015-03-02
Date.strptime('30 Feb 2015', '%d %b %Y') # ArgumentError: invalid date

At the same time, an attempt to analyze February 32 leads to an error for both classes.

Time.strptime('32 Feb 2015', '%d %b %Y') # ArgumentError: invalid strptime format - `%d %b %Y'
Date.strptime('32 Feb 2015', '%d %b %Y') # ArgumentError: invalid date

What is the reason for the different behavior? Why is Time "trying to set" an invalid date?

+4
source share
1 answer

Well, I did a little work and found a couple of "problems" that were presented on this topic: https://bugs.ruby-lang.org/issues/9549 and the main one: https://bugs.ruby-lang.org/issues / 10588

, Time - . :

/ . , : , , , , .

Time /////.

, Time " " . : Time.strptime('29 Mar 2015 3:30:00 +02000', '%d %b %Y %T %z') 2015-03-29 04:30:00 +0300 (3:30 - 29 2015 - , 3:00 4:00)

0

All Articles