ged4py.date¶
Module for parsing and representing dates in gedcom format.
Classes
|
Representation of the <DATE_VALUE>, can be exact date, range, period, etc. |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Implementation of |
|
Namespace for constants defining types of date values. |
Interface for implementation of Visitor pattern for |
-
class
ged4py.date.DateValueTypes(value)[source]¶ Bases:
enum.EnumNamespace for constants defining types of date values.
The constants defined in this namespace are used for the values of the
DateValue.kindattribute. Each separate class implementingDateValueinterface uses distinct value for that attribute, and this value can be used to deduce actual type of the dateDateValueinstance.-
SIMPLE= 'SIMPLE'¶ Date value consists of a single CalendarDate, corresponding implementation class is
DateValueSimple.
-
FROM= 'FROM'¶ Period of dates starting at specified date, end date is unknown, corresponding implementation class is
DateValueFrom
-
TO= 'TO'¶ Period of dates ending at specified date, start date is unknown, corresponding implementation class is
DateValueTo.
-
PERIOD= 'PERIOD'¶ Period of dates starting at one date and ending at another, corresponding implementation class is
DateValuePeriod.
-
BEFORE= 'BEFORE'¶ Date value for an event known to happen before given date, corresponding implementation class is
DateValueBefore.
-
AFTER= 'AFTER'¶ Date value for an event known to happen after given date, corresponding implementation class is
DateValueAfter.
-
RANGE= 'RANGE'¶ Date value for an event known to happen between given dates, corresponding implementation class is
DateValueRange.
-
ABOUT= 'ABOUT'¶ Date value for an event known to happen at approximate date, corresponding implementation class is
DateValueAbout.
-
CALCULATED= 'CALCULATED'¶ Date value for an event calculated from other known information, corresponding implementation class is
DateValueCalculated.
-
ESTIMATED= 'ESTIMATED'¶ Date value for an event estimated from other known information, corresponding implementation class is
DateValueEstimated.
-
INTERPRETED= 'INTERPRETED'¶ Date value for an event interpreted from a specified phrase, corresponding implementation class is
DateValueInterpreted.
-
PHRASE= 'PHRASE'¶ Date value for an event is a phrase, corresponding implementation class is
DateValuePhrase.
-
-
class
ged4py.date.DateValue(key)[source]¶ Bases:
objectRepresentation of the <DATE_VALUE>, can be exact date, range, period, etc.
- Parameters
- key
object Object that is used for ordering, usually it is a pair of
CalendarDateinstances but can beNone.
- key
Notes
DateValueis an abstract base class, for each separate kind of GEDCOM date there is a separate concrete class. Class methodparseis used to parse a date string and return an instance of corresponding sub-class ofDateValuetype.There are presently 12 concrete classes implementing this interface (e.g.
DateValueSimple,DateValueRange, etc.) Different types have somewhat different set of attributes, to implement type-specific code on client side one can use one of these approaches:dispatch based on the value of
kindattribute, it has one of the values defined inDateValueTypesnamespace, and that value maps uniquely to a corresponding sub-class ofDateValue;dispatch based on the type of the instance using
isinstancemethod to check the type (e.g.isinstance(date, DateValueRange));double dispatch (visitor pattern) by implementing
DateValueVisitorinterface.
- Attributes
kindThe type of GEDCOM date, one of the
DateValueTypesenums (DateValueTypes).
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
classmethod
parse(datestr)[source]¶ Parse string <DATE_VALUE> string and make
DateValueinstance out of it.- Parameters
- datestr
str String with GEDCOM date, range, period, etc.
- datestr
- Returns
- date_value
DateValue Object representing the date value.
- date_value
-
abstract property
kind¶ The type of GEDCOM date, one of the
DateValueTypesenums (DateValueTypes).
-
key()[source]¶ Return ordering key for this instance.
If this instance has a range of dates associated with it then this method returns the range as pair of dates. If this instance has a single date associated with it then this method returns pair which includes the date twice. For other dates (
PHRASEis the only instance without date) it returns a a pair of fixed but arbitrary dates in the future.- Returns
- key
tuple[CalendarDate] Key used for ordering.
- key
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueAbout(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for ABT date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueAbout class this is always
DateValueTypes.ABOUT.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueAbout class this is always
DateValueTypes.ABOUT.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueAfter(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for AFT date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueAfter class this is always
DateValueTypes.AFTER.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueAfter class this is always
DateValueTypes.AFTER.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueBefore(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for BEF date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueBefore class this is always
DateValueTypes.BEFORE.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueBefore class this is always
DateValueTypes.BEFORE.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueCalculated(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for CAL date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueCalculated class this is always
DateValueTypes.CALCULATED.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueCalculated class this is always
DateValueTypes.CALCULATED.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueEstimated(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for EST date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueEstimated class this is always
DateValueTypes.ESTIMATED.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueEstimated class this is always
DateValueTypes.ESTIMATED.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueFrom(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for FROM date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueFrom class this is always
DateValueTypes.FROM.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueFrom class this is always
DateValueTypes.FROM.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueInterpreted(date, phrase)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for INT date.- Parameters
- date
CalendarDate Corresponding date.
- phrase
str Phrase string associated with this date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueInterpreted class this is always
DateValueTypes.INTERPRETED.phrasePhrase associated with this date (
str)
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueInterpreted class this is always
DateValueTypes.INTERPRETED.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
property
phrase¶ Phrase associated with this date (
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValuePeriod(date1, date2)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for FROM … TO date.- Parameters
- date1
CalendarDate FROM date.
- date2
CalendarDate TO date.
- date1
- Attributes
date1First Calendar date corresponding to this instance (
CalendarDate)date2Second Calendar date corresponding to this instance (
CalendarDate)kindFor DateValuePeriod class this is always
DateValueTypes.PERIOD.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValuePeriod class this is always
DateValueTypes.PERIOD.
-
property
date1¶ First Calendar date corresponding to this instance (
CalendarDate)
-
property
date2¶ Second Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValuePhrase(phrase)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for phrase-date.- Parameters
- phrase
str Phrase string associated with this date.
- phrase
- Attributes
kindFor DateValuePhrase class this is always
DateValueTypes.PHRASE.phrasePhrase associated with this date (
str)
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValuePhrase class this is always
DateValueTypes.PHRASE.
-
property
phrase¶ Phrase associated with this date (
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueRange(date1, date2)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for BET … AND … date.- Parameters
- date1
CalendarDate First date.
- date2
CalendarDate Second date.
- date1
- Attributes
date1First Calendar date corresponding to this instance (
CalendarDate)date2Second Calendar date corresponding to this instance (
CalendarDate)kindFor DateValueRange class this is always
DateValueTypes.RANGE.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueRange class this is always
DateValueTypes.RANGE.
-
property
date1¶ First Calendar date corresponding to this instance (
CalendarDate)
-
property
date2¶ Second Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueSimple(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for simple single-value DATE.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueSimple class this is always
DateValueTypes.SIMPLE.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueSimple class this is always
DateValueTypes.SIMPLE.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueTo(date)[source]¶ Bases:
ged4py.date.DateValueImplementation of
DateValueinterface for TO date.- Parameters
- date
CalendarDate Corresponding date.
- date
- Attributes
dateCalendar date corresponding to this instance (
CalendarDate)kindFor DateValueTo class this is always
DateValueTypes.TO.
Methods
accept(visitor)Implementation of visitor pattern.
key()Return ordering key for this instance.
parse(datestr)Parse string <DATE_VALUE> string and make
DateValueinstance out of it.-
property
kind¶ For DateValueTo class this is always
DateValueTypes.TO.
-
property
date¶ Calendar date corresponding to this instance (
CalendarDate)
-
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
DateValueVisitor Visitor instance.
- visitor
- Returns
- value
object Value returned from a visitor method.
- value
-
class
ged4py.date.DateValueVisitor[source]¶ Bases:
objectInterface for implementation of Visitor pattern for
DateValueclasses.One can easily extend behavior of the
DateValueclass hierarchy without modifying classes themselves. Clients need to implement new behavior by sub-classingDateValueVisitorand callingDateValue.acceptmethod, e.g.:class FormatterVisitor(DateValueVisitor): def visitSimple(self, date): return "Simple date: " + str(date.date) # and so on for each date type visitor = FormatterVisitor() date = DateValue.parse(date_string) formatted = date.accept(visitor)
Methods
visitAbout(date)Visit an instance of
DateValueAbouttype.visitAfter(date)Visit an instance of
DateValueAftertype.visitBefore(date)Visit an instance of
DateValueBeforetype.visitCalculated(date)Visit an instance of
DateValueCalculatedtype.visitEstimated(date)Visit an instance of
DateValueEstimatedtype.visitFrom(date)Visit an instance of
DateValueFromtype.visitInterpreted(date)Visit an instance of
DateValueInterpretedtype.visitPeriod(date)Visit an instance of
DateValuePeriodtype.visitPhrase(date)Visit an instance of
DateValuePhrasetype.visitRange(date)Visit an instance of
DateValueRangetype.visitSimple(date)Visit an instance of
DateValueSimpletype.visitTo(date)Visit an instance of
DateValueTotype.-
abstract
visitSimple(date)[source]¶ Visit an instance of
DateValueSimpletype.- Parameters
- date
DateValueSimple Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitPeriod(date)[source]¶ Visit an instance of
DateValuePeriodtype.- Parameters
- date
DateValuePeriod Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitFrom(date)[source]¶ Visit an instance of
DateValueFromtype.- Parameters
- date
DateValueFrom Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitTo(date)[source]¶ Visit an instance of
DateValueTotype.- Parameters
- date
DateValueTo Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitRange(date)[source]¶ Visit an instance of
DateValueRangetype.- Parameters
- date
DateValueRange Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitBefore(date)[source]¶ Visit an instance of
DateValueBeforetype.- Parameters
- date
DateValueBefore Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitAfter(date)[source]¶ Visit an instance of
DateValueAftertype.- Parameters
- date
DateValueAfter Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitAbout(date)[source]¶ Visit an instance of
DateValueAbouttype.- Parameters
- date
DateValueAbout Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitCalculated(date)[source]¶ Visit an instance of
DateValueCalculatedtype.- Parameters
- date
DateValueCalculated Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitEstimated(date)[source]¶ Visit an instance of
DateValueEstimatedtype.- Parameters
- date
DateValueEstimated Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitInterpreted(date)[source]¶ Visit an instance of
DateValueInterpretedtype.- Parameters
- date
DateValueInterpreted Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract
visitPhrase(date)[source]¶ Visit an instance of
DateValuePhrasetype.- Parameters
- date
DateValuePhrase Date value instance.
- date
- Returns
- value
object Implementation of this method can return anything, value will be returned from
DateValue.accept()method.
- value
-
abstract