From: jerome <rom...@ya...> - 2013-09-28 07:52:26
|
Note, there is also an option for some reports or views.see #4397 [1] http://www.gramps-project.org/bugs/view.php?id=4397 ________________________________ De : Vassilii Khachaturov <vas...@ta...> À : GRAMPS <gra...@li...> Envoyé le : Samedi 28 septembre 2013 2h25 Objet : [Gramps-devel] reminder: a Date object is not always gregorian! A long time ago (in 3.2) I committed one of my first non-translation patches to gramps, to fix bug #4550. Yesterday, I was bitten by a similar bug in WebCal (see bug #7089), and was then surprised to see how often we have code working with Date object assuming a particular calendar in effect (mostly Gregorian). The code then happily does things like (simplified): if birth_date.is_valid: year = birth_date.get_year() month = birth_date.get_month() day = ... ... and considers the person born on year/month/day disregarding the birth_day.get_calendar() value -- which sometimes is NOT gregorian, and so the result is totally unsuitable to be pinned as is on a Gregorian web calendar report. For the most common case, I have created a tiny accessory function in gen.lib.date, called gregorian --- it takes a single argument, date, and returns either the same object if it is gregorian already, or a copy of the same date, with the calendar converted to Gregorian. So the code above only needs to be patched as follows: if birth_date.is_valid: + birth_date = gregorian(birth_date) year = birth_date.get_year() I have fixed the reports that I have discovered with this problem in the scope of bug #7089, but maybe you have written some other code like that that you'd like to patch? Best bet is to keep dates in the Date object, and compare them using Date comparison operators --- in this case comparison will regard the actual SDN referred to, and not the representation under a particular calendar. But whenever you need to compare with externally supplied y/m/d, or give y/m/d to somebody else --- remember to convert to the correct calendar. Date.convert_calendar() is your friend! It should be used when our calendar reports support non-Gregorian output calendars... V. ------------------------------------------------------------------------------ October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk _______________________________________________ Gramps-devel mailing list Gra...@li... https://lists.sourceforge.net/lists/listinfo/gramps-devel |