Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 50580
Status: resolved
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: geoff [...] laxan.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.50
Fixed in: 0.51



Subject: Simplify dow maths in _rd2ymd [PATCH]
There's some slightly overcomplicated code in DateTime.xs with a comment about the author being a "math gimp". This patch replaces it with something slightly less mysterious which should always produce the same result, and which passes all the same tests. Being a math gimp myself I can't actually prove that this is correct, but I'm fairly sure it is.
Subject: datetime-math-gimp.patch
--- DateTime.xs.orig 2009-10-17 00:03:13.000000000 +0100 +++ DateTime.xs 2009-10-17 00:04:46.000000000 +0100 @@ -59,9 +59,6 @@ 305, 335 }; - -const IV neg_dow[] = { 1, 7, 6, 5, 4, 3, 2 }; - IV _real_is_leap_year(IV y) { /* See http://www.perlmonks.org/?node_id=274247 for where this @@ -123,17 +120,9 @@ if (extra) { quarter = ( ( 1.0 / 3.1 ) * m ) + 1; - dow = ((rd_days + 6) % 7); - - if (rd_days < -6) { - /* if the left side of the modulus was negative we now - have a bogus answer. This fixes it, though it ccould - probably be done more elegantly if I wasn't such a math - gimp. */ - - dow = neg_dow[ abs(dow) ]; - } else { - dow++; + dow = rd_days % 7; + if (dow <= 0) { + dow += 7; } PUSHs(sv_2mortal(newSViv(dow)));