From da749a3fbc0f5fd72d8e6c4652ec3bd952927967 Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Sat, 14 Sep 2013 19:42:59 +0000 Subject: [PATCH] 7066: fallback to buggy PyICU if sdn unavailable svn: r23128 --- gramps/gen/lib/calendar.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/gramps/gen/lib/calendar.py b/gramps/gen/lib/calendar.py index bb0fd8ff1..e50850438 100644 --- a/gramps/gen/lib/calendar.py +++ b/gramps/gen/lib/calendar.py @@ -580,7 +580,26 @@ try: hebrew_ymd = sdn.SdnToJewish # Fix bug# 7066 hebrew_sdn = sdn.JewishToSdn #TODO maybe alias the other local invented wheels to Calendar convertors + except ImportError: - import sys - print("No sdn module. Install Calendar with pypi." - "hebrew_sdn has a known bug# 7066!!!", file=sys.stderr) + try: + from icu import Locale, GregorianCalendar, Calendar + _hcal = Calendar.createInstance( + Locale.createFromName('@calendar=hebrew')) + def hebrew_ymd(sdn): + y,m,d = gregorian_ymd(sdn) + gcal = GregorianCalendar() + gcal.set(y,m,d) + _hcal.setTime( gcal.getTime() ) + return (_hcal.get(Calendar.YEAR), + _hcal.get(Calendar.MONTH), + _hcal.get(Calendar.DAY_OF_YEAR)) + # Not much better than our version... fails on 1789-11-4(hebrew), + # unlike sdn! + + except ImportError: + import sys + print("Neither sdn nor ICU available.\n" + "Install Calendar with pypi or PyICU with your package manager." + "WARNING: hebrew_sdn has a known bug# 7066 without them!", + file=sys.stderr)