ged4py.date

Module for parsing and representing dates in gedcom format.

Classes

DateValue(key)

Representation of the <DATE_VALUE>, can be exact date, range, period, etc.

DateValueAbout(date)

Implementation of DateValue interface for ABT date.

DateValueAfter(date)

Implementation of DateValue interface for AFT date.

DateValueBefore(date)

Implementation of DateValue interface for BEF date.

DateValueCalculated(date)

Implementation of DateValue interface for CAL date.

DateValueEstimated(date)

Implementation of DateValue interface for EST date.

DateValueFrom(date)

Implementation of DateValue interface for FROM date.

DateValueInterpreted(date, phrase)

Implementation of DateValue interface for INT date.

DateValuePeriod(date1, date2)

Implementation of DateValue interface for FROM .

DateValuePhrase(phrase)

Implementation of DateValue interface for phrase-date.

DateValueRange(date1, date2)

Implementation of DateValue interface for BET .

DateValueSimple(date)

Implementation of DateValue interface for simple single-value DATE.

DateValueTo(date)

Implementation of DateValue interface for TO date.

DateValueTypes(value)

Namespace for constants defining types of date values.

DateValueVisitor()

Interface for implementation of Visitor pattern for DateValue classes.

class ged4py.date.DateValueTypes(value)[source]

Bases: enum.Enum

Namespace for constants defining types of date values.

The constants defined in this namespace are used for the values of the DateValue.kind attribute. Each separate class implementing DateValue interface uses distinct value for that attribute, and this value can be used to deduce actual type of the date DateValue instance.

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: object

Representation of the <DATE_VALUE>, can be exact date, range, period, etc.

Parameters
keyobject

Object that is used for ordering, usually it is a pair of CalendarDate instances but can be None.

Notes

DateValue is an abstract base class, for each separate kind of GEDCOM date there is a separate concrete class. Class method parse is used to parse a date string and return an instance of corresponding sub-class of DateValue type.

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 kind attribute, it has one of the values defined in DateValueTypes namespace, and that value maps uniquely to a corresponding sub-class of DateValue;

  • dispatch based on the type of the instance using isinstance method to check the type (e.g. isinstance(date, DateValueRange));

  • double dispatch (visitor pattern) by implementing DateValueVisitor interface.

Attributes
kind

The type of GEDCOM date, one of the DateValueTypes enums (DateValueTypes).

Methods

accept(visitor)

Implementation of visitor pattern.

key()

Return ordering key for this instance.

parse(datestr)

Parse string <DATE_VALUE> string and make DateValue instance out of it.

classmethod parse(datestr)[source]

Parse string <DATE_VALUE> string and make DateValue instance out of it.

Parameters
datestrstr

String with GEDCOM date, range, period, etc.

Returns
date_valueDateValue

Object representing the date value.

abstract property kind

The type of GEDCOM date, one of the DateValueTypes enums (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 (PHRASE is the only instance without date) it returns a a pair of fixed but arbitrary dates in the future.

Returns
keytuple [ CalendarDate ]

Key used for ordering.

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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueAbout(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for ABT date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueAfter(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for AFT date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueBefore(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for BEF date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueCalculated(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for CAL date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueEstimated(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for EST date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueFrom(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for FROM date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueInterpreted(date, phrase)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for INT date.

Parameters
dateCalendarDate

Corresponding date.

phrasestr

Phrase string associated with this date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For DateValueInterpreted class this is always DateValueTypes.INTERPRETED.

phrase

Phrase 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValuePeriod(date1, date2)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for FROM … TO date.

Parameters
date1CalendarDate

FROM date.

date2CalendarDate

TO date.

Attributes
date1

First Calendar date corresponding to this instance (CalendarDate)

date2

Second Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValuePhrase(phrase)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for phrase-date.

Parameters
phrasestr

Phrase string associated with this date.

Attributes
kind

For DateValuePhrase class this is always DateValueTypes.PHRASE.

phrase

Phrase 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueRange(date1, date2)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for BET … AND … date.

Parameters
date1CalendarDate

First date.

date2CalendarDate

Second date.

Attributes
date1

First Calendar date corresponding to this instance (CalendarDate)

date2

Second Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueSimple(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for simple single-value DATE.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueTo(date)[source]

Bases: ged4py.date.DateValue

Implementation of DateValue interface for TO date.

Parameters
dateCalendarDate

Corresponding date.

Attributes
date

Calendar date corresponding to this instance (CalendarDate)

kind

For 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 DateValue instance 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
visitorDateValueVisitor

Visitor instance.

Returns
valueobject

Value returned from a visitor method.

class ged4py.date.DateValueVisitor[source]

Bases: object

Interface for implementation of Visitor pattern for DateValue classes.

One can easily extend behavior of the DateValue class hierarchy without modifying classes themselves. Clients need to implement new behavior by sub-classing DateValueVisitor and calling DateValue.accept method, 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 DateValueAbout type.

visitAfter(date)

Visit an instance of DateValueAfter type.

visitBefore(date)

Visit an instance of DateValueBefore type.

visitCalculated(date)

Visit an instance of DateValueCalculated type.

visitEstimated(date)

Visit an instance of DateValueEstimated type.

visitFrom(date)

Visit an instance of DateValueFrom type.

visitInterpreted(date)

Visit an instance of DateValueInterpreted type.

visitPeriod(date)

Visit an instance of DateValuePeriod type.

visitPhrase(date)

Visit an instance of DateValuePhrase type.

visitRange(date)

Visit an instance of DateValueRange type.

visitSimple(date)

Visit an instance of DateValueSimple type.

visitTo(date)

Visit an instance of DateValueTo type.

abstract visitSimple(date)[source]

Visit an instance of DateValueSimple type.

Parameters
dateDateValueSimple

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitPeriod(date)[source]

Visit an instance of DateValuePeriod type.

Parameters
dateDateValuePeriod

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitFrom(date)[source]

Visit an instance of DateValueFrom type.

Parameters
dateDateValueFrom

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitTo(date)[source]

Visit an instance of DateValueTo type.

Parameters
dateDateValueTo

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitRange(date)[source]

Visit an instance of DateValueRange type.

Parameters
dateDateValueRange

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitBefore(date)[source]

Visit an instance of DateValueBefore type.

Parameters
dateDateValueBefore

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitAfter(date)[source]

Visit an instance of DateValueAfter type.

Parameters
dateDateValueAfter

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitAbout(date)[source]

Visit an instance of DateValueAbout type.

Parameters
dateDateValueAbout

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitCalculated(date)[source]

Visit an instance of DateValueCalculated type.

Parameters
dateDateValueCalculated

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitEstimated(date)[source]

Visit an instance of DateValueEstimated type.

Parameters
dateDateValueEstimated

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitInterpreted(date)[source]

Visit an instance of DateValueInterpreted type.

Parameters
dateDateValueInterpreted

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.

abstract visitPhrase(date)[source]

Visit an instance of DateValuePhrase type.

Parameters
dateDateValuePhrase

Date value instance.

Returns
valueobject

Implementation of this method can return anything, value will be returned from DateValue.accept() method.