Closed Bug 1046213 Opened 7 years ago Closed 7 years ago

datetime_from() generates wrong dates if year < 1901


(Bugzilla :: Bugzilla-General, defect)

Not set



Bugzilla 4.4


(Reporter: LpSolit, Assigned: LpSolit)



(1 file)

Attached patch patch, v1Splinter Review
While investigating why datetime_from("1900-12-31") takes 5.74 seconds on my machine and datetime_from("1901-01-01") takes 0.10 second, I realized that datetime_from() was passing incorrect data to DateTime->new() if the date was older than 1901 (which can happen as we have date and datetime custom fields). That's because strptime() returns the full year if older than 1901. So datetime_from() was incorrectly converting year 1900 into year 3800, making DateTime() terribly slow.
Attachment #8464767 - Flags: review?(sgreen)
Given that Date::Parse (which uses Date::Local) is known to be buggy (see, wouldn't a better solution to be using something like DateTime::Format::Strptime ( ), especially considering we turn it into a DateTime object anyway?
Flags: needinfo?(LpSolit)
(In reply to sgreen from comment #1)

That's an idea, but the problem is that DateTime::Format::Strptime::new() requires the pattern to be provided, i.e. you must know which format is used for the input datetime string, while Date::Parse::strptime() runs several regexps to guess which format is used. As datetime_from() is called from many places, it's hard to determine the pattern for sure, unless we run our own regexps first.
Flags: needinfo?(LpSolit)
Attachment #8464767 - Flags: review?(sgreen) → review+
Flags: approval?
Flags: approval4.4?
Flags: approval?
Flags: approval4.4?
Flags: approval4.4+
Flags: approval+
To ssh://
   ace2e1a..fc4350a  master -> master

To ssh://
   e74616b..76b3203  4.4 -> 4.4
Closed: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.