Ticket #2911: moon.patch

File moon.patch, 5.2 KB (added by mgv, 11 years ago)

A patch that should solve this issue

  • moon.py

    From ae94ce35c7b2612fce8b6ab0006e4349611ef2eb Mon Sep 17 00:00:00 2001
    From: Marius Gavrilescu <marius@ieval.ro>
    Date: Tue, 27 Nov 2012 12:28:49 -0800
    Subject: [PATCH] Show next lunar / solar eclipse type
    
    ---
     moon.py | 26 ++++++++++++++++++--------
     1 file changed, 18 insertions(+), 8 deletions(-)
    
    diff --git a/moon.py b/moon.py
    index 4ab5840..850343c 100755
    a b except ImportError: 
    5555
    5656IMAGE_SIZE = 726
    5757HALF_SIZE = IMAGE_SIZE / 2
     58ECLIPSE_TYPES = {
     59    'T' : _('Total'),
     60    'A' : _('Annular'),
     61    'H' : _('Hybrid'),
     62    'P' : _('Partial'),
     63    't' : _('Total'),
     64    'p' : _('Partial'),
     65    'n' : _('Penumbral')
     66}
    5867
    5968# TRANS: Date format for next full/new moon and next solar/lunar eclipse
    6069LOCALE_DATE_FORMAT = _("%c")
    class MoonActivity(activity.Activity): 
    289298        information_string = _(u"Selenographic Terminator Longitude:\n%(deg).1f\u00b0%(westOrEast)s (%(riseOrSet)s)\n\n") % {'deg':self.data_model.selenographic_deg, 'westOrEast':self.data_model.west_or_east, 'riseOrSet':self.data_model.rise_or_set}
    290299        information_string += _("Next Full Moon:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_full_moon_date)), 'days':self.data_model.days_until_full_moon}
    291300        information_string += _("Next New Moon:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_new_moon_date)), 'days':self.data_model.days_until_new_moon}
    292         information_string += _("Next Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_lunar_eclipse_date)), 'days':self.data_model.days_until_lunar_eclipse}
    293         information_string += _("Next Solar eclipse:\n%(date)s in %(days).0f days\n\n")[:-2] % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_solar_eclipse_date)), 'days':self.data_model.days_until_solar_eclipse}
     301        information_string += _("Next [ %(eclipse_type)s ] Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_lunar_eclipse_date)), 'days':self.data_model.days_until_lunar_eclipse, 'eclipse_type':ECLIPSE_TYPES[self.data_model.next_lunar_eclipse_type]}
     302        information_string += _("Next [ %(eclipse_type)s ] Solar eclipse:\n%(date)s in %(days).0f days\n\n")[:-2] % {'date':time.strftime(LOCALE_DATE_FORMAT, time.localtime(self.data_model.next_solar_eclipse_date)), 'days':self.data_model.days_until_solar_eclipse, 'eclipse_type':ECLIPSE_TYPES[self.data_model.next_solar_eclipse_type]}
    294303        self.info2.set_markup(information_string)
    295304
    296305        # Calculate time to next minute cusp and set a new timer
    class DataModel(): 
    532541        self.next_full_moon_date = the_date + next_full_moon_sec - self.correct_for_tz_and_dst(the_date + next_full_moon_sec)
    533542       
    534543        # Eclipse information
    535         self.next_lunar_eclipse_sec = self.next_lunar_eclipse_sec_at_time(the_date)
    536         self.next_solar_eclipse_sec = self.next_solar_eclipse_sec_at_time(the_date)
    537         self.last_lunar_eclipse_sec = self.last_lunar_eclipse_sec_at_time(the_date)
     544        self.next_lunar_eclipse_sec, self.next_lunar_eclipse_type = self.next_lunar_eclipse_sec_at_time(the_date)
     545        self.next_solar_eclipse_sec, self.next_solar_eclipse_type = self.next_solar_eclipse_sec_at_time(the_date)
     546        self.last_lunar_eclipse_sec, self.last_lunar_eclipse_type = self.last_lunar_eclipse_sec_at_time(the_date)
    538547        self.days_until_lunar_eclipse = self.next_lunar_eclipse_sec / SECONDS_PER_DAY
    539548        self.next_lunar_eclipse_date = the_date + self.next_lunar_eclipse_sec - self.correct_for_tz_and_dst(the_date + self.next_lunar_eclipse_sec)
    540549        self.days_until_solar_eclipse = self.next_solar_eclipse_sec / SECONDS_PER_DAY
    class DataModel(): 
    679688            if date_string[-1:] != "_":
    680689                next = time.mktime(time.strptime(date_string[:-1], self.date_format))
    681690                if next >= now:
    682                     return next - now
     691                    return next - now, date_string[-1:]
    683692        return -1
    684693
    685694    def last_lunar_eclipse_sec_at_time(self, now):
    class DataModel(): 
    688697        last = -1
    689698        for date_string in self.full_moon_array:
    690699            if date_string[-1:] != "_":
     700                eclipse_type = date_string[-1:]
    691701                then = time.mktime(time.strptime(date_string[:-1], self.date_format))
    692702                if then >= now:
    693703                    break
    class DataModel(): 
    695705        if last == -1:
    696706            return -1
    697707        else:
    698             return now - last
     708            return now - last, type
    699709
    700710    def next_solar_eclipse_sec_at_time(self, now):
    701711        """Return (positive) seconds to the next Solar eclipe or -1.
    class DataModel(): 
    704714            if date_string[-1:] != "_":
    705715                next = time.mktime(time.strptime(date_string[:-1], self.date_format))
    706716                if next >= now:
    707                     return next - now
     717                    return next - now, date_string[-1:]
    708718        return -1