ged4py.calendar¶
Module for parsing and representing calendar dates in gedcom format.
Classes
|
Interface for calendar date representation. |
Interface for implementation of Visitor pattern for |
|
|
Namespace for constants defining names of calendars. |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
-
class
ged4py.calendar.CalendarType(value)[source]¶ Bases:
enum.EnumNamespace for constants defining names of calendars.
Note that it does not define constants for
ROMANcalendar which is declared in GEDCOM standard as a placeholder for future definition, orUNKNOWNcalendar which is not supported by this library.The constants defined in this namespace are used for the values of the
CalendarDate.calendarattribute. Each separate class implementingCalendarDateinterface uses distinct value for that attribute, and this value can be used to deduce actual type of theCalendarDateinstance.-
GREGORIAN= 'GREGORIAN'¶ This is the value assigned to
GregorianDate.calendarattribute.
-
JULIAN= 'JULIAN'¶ This is the value assigned to
JulianDate.calendarattribute.
-
HEBREW= 'HEBREW'¶ This is the value assigned to
HebrewDate.calendarattribute.
-
FRENCH_R= 'FRENCH R'¶ This is the value assigned to
FrenchDate.calendarattribute.
-
-
class
ged4py.calendar.CalendarDate(year, month=None, day=None, bc=False, original=None)[source]¶ Bases:
objectInterface for calendar date representation.
- Parameters
- year
int Calendar year number. If
bcparameter isTruethen this year is before “epoch” of that calendar.- month
str Name of the month. Optional, but if day is given then month cannot be None.
- day
int Day in a month, optional.
- bc
bool Trueif year has “B.C.”- original
str Original string representation of this date as it was specified in GEDCOM file, could be
None.
- year
Notes
This class defines attributes and methods that are common for all calendars defined in GEDCOM (though the meaning and representation can be different in different calendars). In GEDCOM date consists of year, month, and day; day and month are optional (either day or day+month), year must be present. Day is a number, month is month name in a given calendar. Year is a number optionally followed by
B.C.or/NUMBER(latter is defined for Gregorian calendar only).Implementation for different calendars are provided by subclasses which can implement additional attributes or methods. All subclasses need to implement
key()method to support ordering of the dates from different calendars. There are presently four implementations defined in this module:GregorianDatefor “GREGORIAN” calendarJulianDatefor “JULIAN” calendarHebrewDatefor “HEBREW” calendarFrenchDatefor “FRENCH R” calendar
To implement type-specific code on client side one can use one of these approaches:
dispatch based on the value of
calendarattribute, it has one of the values defined inCalendarTypeenum, the value maps uniquely to an implementation class;dispatch based on the type of the instance using
isinstancemethod to check the type (e.g.isinstance(date, GregorianDate));double dispatch (visitor pattern) by implementing
CalendarDateVisitorinterface.
- Attributes
calendarCalendar used for this date, one of the
CalendarTypeenumsyear_strCalendar year in string representation, this can include dual year and/or B.C.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
months()Ordered list of month names (in GEDCOM format) defined in calendar.
parse(datestr)Parse
<DATE>string and makeCalendarDatefrom it.-
year¶ Calendar year number (
int)
-
month¶ Month name or
None(str)
-
day¶ Day number or
None(int)
-
bc¶ Flag which is
Trueif year has a “B.C” suffix (bool).
-
original¶ Original string representation of this date as it was specified in GEDCOM file, could be
None(str).
-
month_num¶ Integer month number (1-based) or
Noneif month name is not given or unknown (int).
-
abstract classmethod
months()[source]¶ Ordered list of month names (in GEDCOM format) defined in calendar.
-
abstract
key()[source]¶ Return ordering key for this instance.
Returned key is a tuple with two numbers (jd, flag).
jdis the Julian Day number as floating point,flagis an integer flag. If month or day is not known then last month or last day should be returned in its place (in corresponding calendar, and converted to JD) andflagshould be set to 1. If date and month are known then flag should be set to 0.
-
property
year_str¶ Calendar year in string representation, this can include dual year and/or B.C. suffix (
str)
-
abstract property
calendar¶ Calendar used for this date, one of the
CalendarTypeenums (CalendarType)
-
abstract
accept(visitor)[source]¶ Implementation of visitor pattern.
Each concrete sub-class will implement this method by dispatching the call to corresponding visitor method.
- Parameters
- visitor
CalendarDateVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
classmethod
parse(datestr)[source]¶ Parse
<DATE>string and makeCalendarDatefrom it.- Parameters
- datestr
str String with GEDCOM date.
- datestr
- Returns
- date
CalendarDate Date instance.
- date
- Raises
- ValueError
Raised if parsing fails.
-
class
ged4py.calendar.FrenchDate(year, month=None, day=None, bc=False, original=None)[source]¶ Bases:
ged4py.calendar.CalendarDateImplementation of
CalendarDatefor French Republican calendar.All parameters have the same meaning as in
CalendarDateclass.- Attributes
calendarCalendar used for this date, one of the
CalendarTypeenumsyear_strCalendar year in string representation, this can include dual year and/or B.C.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
months()Ordered list of month names (in GEDCOM format) defined in calendar.
parse(datestr)Parse
<DATE>string and makeCalendarDatefrom it.-
property
calendar¶ Calendar used for this date, one of the
CalendarTypeenums (CalendarType)
-
accept(visitor)[source]¶ Implementation of visitor pattern.
Each concrete sub-class will implement this method by dispatching the call to corresponding visitor method.
- Parameters
- visitor
CalendarDateVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.calendar.GregorianDate(year, month=None, day=None, bc=False, original=None, dual_year=None)[source]¶ Bases:
ged4py.calendar.CalendarDateImplementation of
CalendarDatefor Gregorian calendar.Parameter
dual_year(and corresponding attribute) is used for dual year. Other parameters have the same meaning as inCalendarDateclass.- Parameters
- dual_year
int, optional Dual year number or
None. Actual year should be given, not just two last digits.
- dual_year
Notes
In GEDCOM Gregorian calendar dates are allowed to specify year in the form YEAR1/YEAR2 (a.k.a.) dual-dating. Second number is used to specify year as if calendar year starts in January, while the first number is used for actual calendar year which starts at different date. Note that GEDCOM specifies that dual year uses just two last digits in the dual year number, though some implementations use 4 digits. This class expects actual year number (e.g. as if it was specified as “1699/1700”).
- Attributes
calendarCalendar used for this date, one of the
CalendarTypeenumsyear_strCalendar year in string representation, this can include dual year and/or B.C.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
months()Ordered list of month names (in GEDCOM format) defined in calendar.
parse(datestr)Parse
<DATE>string and makeCalendarDatefrom it.-
dual_year¶ If not
Nonethen this number represent year in a calendar with year starting on January 1st (int).
-
property
calendar¶ Calendar used for this date, one of the
CalendarTypeenums (CalendarType)
-
property
year_str¶ Calendar year in string representation, this can include dual year and/or B.C. suffix (
str)
-
accept(visitor)[source]¶ Implementation of visitor pattern.
Each concrete sub-class will implement this method by dispatching the call to corresponding visitor method.
- Parameters
- visitor
CalendarDateVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.calendar.HebrewDate(year, month=None, day=None, bc=False, original=None)[source]¶ Bases:
ged4py.calendar.CalendarDateImplementation of
CalendarDatefor Hebrew calendar.All parameters have the same meaning as in
CalendarDateclass.- Attributes
calendarCalendar used for this date, one of the
CalendarTypeenumsyear_strCalendar year in string representation, this can include dual year and/or B.C.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
months()Ordered list of month names (in GEDCOM format) defined in calendar.
parse(datestr)Parse
<DATE>string and makeCalendarDatefrom it.-
property
calendar¶ Calendar used for this date, one of the
CalendarTypeenums (CalendarType)
-
accept(visitor)[source]¶ Implementation of visitor pattern.
Each concrete sub-class will implement this method by dispatching the call to corresponding visitor method.
- Parameters
- visitor
CalendarDateVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.calendar.JulianDate(year, month=None, day=None, bc=False, original=None)[source]¶ Bases:
ged4py.calendar.CalendarDateImplementation of
CalendarDatefor Julian calendar.All parameters have the same meaning as in
CalendarDateclass.- Attributes
calendarCalendar used for this date, one of the
CalendarTypeenumsyear_strCalendar year in string representation, this can include dual year and/or B.C.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
months()Ordered list of month names (in GEDCOM format) defined in calendar.
parse(datestr)Parse
<DATE>string and makeCalendarDatefrom it.-
property
calendar¶ Calendar used for this date, one of the
CalendarTypeenums (CalendarType)
-
accept(visitor)[source]¶ Implementation of visitor pattern.
Each concrete sub-class will implement this method by dispatching the call to corresponding visitor method.
- Parameters
- visitor
CalendarDateVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.calendar.CalendarDateVisitor[source]¶ Bases:
objectInterface for implementation of Visitor pattern for
CalendarDateclasses.One can easily extend behavior of the
CalendarDateclass hierarchy without modifying classes themselves. Clients need to implement new behavior by sub-classingCalendarDateVisitorand callingCalendarDate.accept()method, e.g.:class FormatterVisitor(CalendarDateVisitor): def visitGregorian(self, date): return "Gregorian date:" + str(date) # and so on for each date type visitor = FormatterVisitor() date = CalendarDate.parse(date_string) formatted = date.accept(visitor)
Methods
visitFrench(date)Visit an instance of
FrenchDatetype.visitGregorian(date)Visit an instance of
GregorianDatetype.visitHebrew(date)Visit an instance of
HebrewDatetype.visitJulian(date)Visit an instance of
JulianDatetype.-
abstract
visitGregorian(date)[source]¶ Visit an instance of
GregorianDatetype.- Parameters
- date
GregorianDate Date instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
CalendarDate.accept()method.
- value
-
abstract
visitJulian(date)[source]¶ Visit an instance of
JulianDatetype.- Parameters
- date
JulianDate Date instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
CalendarDate.accept()method.
- value
-
abstract
visitHebrew(date)[source]¶ Visit an instance of
HebrewDatetype.- Parameters
- date
HebrewDate Date instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
CalendarDate.accept()method.
- value
-
abstract
visitFrench(date)[source]¶ Visit an instance of
FrenchDatetype.- Parameters
- date
FrenchDate Date instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
CalendarDate.accept()method.
- value
-
abstract