Package RelLib :: Module _Date :: Class Date
[frames] | no frames]

Class Date

source code

The core date handling class for GRAMPs. Supports partial dates, compound dates and alternate calendars.

Instance Methods
 
__init__(self, source=None)
Creates a new Date instance.
source code
 
serialize(self, no_text_date=False)
Convert to a series of tuples for data storage
source code
 
unserialize(self, data)
Load from the format created by serialize
source code
 
copy(self, source)
Copy all the attributes of the given Date instance to the present instance, without creating a new object.
source code
 
__cmp__(self, other)
Comparison function.
source code
 
is_equal(self, other)
Return 1 if the given Date instance is the same as the present instance IN ALL REGARDS.
source code
 
__str__(self)
Produces a string representation of the Date object.
source code
 
get_sort_value(self)
Returns the sort value of Date object.
source code
 
get_modifier(self)
Returns an integer indicating the calendar selected.
source code
 
set_modifier(self, val)
Sets the modifier for the date.
source code
 
get_quality(self)
Returns an integer indicating the calendar selected.
source code
 
set_quality(self, val)
Sets the quality selected for the date.
source code
 
get_calendar(self)
Returns an integer indicating the calendar selected.
source code
 
set_calendar(self, val)
Sets the calendar selected for the date.
source code
 
get_start_date(self)
Returns a tuple representing the start date.
source code
 
get_stop_date(self)
Returns a tuple representing the second half of a compound date.
source code
 
get_year(self)
Returns the year associated with the date.
source code
 
set_year(self, year)
Sets the year value
source code
 
get_year_valid(self)
Returns true if the year is valid
source code
 
get_month(self)
Returns the month associated with the date.
source code
 
get_month_valid(self)
Returns true if the month is valid
source code
 
get_day(self)
Returns the day of the month associated with the date.
source code
 
get_day_valid(self)
Returns true if the day is valid
source code
 
get_valid(self)
Returns true if any part of the date is valid
source code
 
get_stop_year(self)
Returns the day of the year associated with the second part of a compound date.
source code
 
get_stop_month(self)
Returns the month of the month associated with the second part of a compound date.
source code
 
get_stop_day(self)
Returns the day of the month associated with the second part of a compound date.
source code
 
get_high_year(self)
Returns the high year estimate.
source code
 
get_text(self)
Returns the text value associated with an invalid date.
source code
 
set(self, quality, modifier, calendar, value, text=None)
Sets the date to the specified value.
source code
 
convert_calendar(self, calendar)
Converts the date from the current calendar to the specified calendar.
source code
 
set_as_text(self, text)
Sets the day to a text string, and assigns the sort value to zero.
source code
 
set_text_value(self, text)
Sets the text string to a given text.
source code
 
is_empty(self)
Returns True if the date contains no information (empty text).
source code
 
is_compound(self)
Returns True if the date is a date range or a date span.
source code
 
is_regular(self)
Returns True if the date is a regular date.
source code
Class Variables
  MOD_NONE = 0
  MOD_BEFORE = 1
  MOD_AFTER = 2
  MOD_ABOUT = 3
  MOD_RANGE = 4
  MOD_SPAN = 5
  MOD_TEXTONLY = 6
  QUAL_NONE = 0
  QUAL_ESTIMATED = 1
  QUAL_CALCULATED = 2
  CAL_GREGORIAN = 0
  CAL_JULIAN = 1
  CAL_HEBREW = 2
  CAL_FRENCH = 3
  CAL_PERSIAN = 4
  CAL_ISLAMIC = 5
  EMPTY = (0, 0, 0, False)
  calendar_names = ['Gregorian', 'Julian', 'Hebrew', 'French Rep...
  ui_calendar_names = ['Gregorian', 'Julian', 'Hebrew', 'French ...
Method Details

__cmp__(self, other)
(Comparison operator)

source code 
Comparison function. Allows the usage of equality tests. This allows you do run statements like 'date1 <= date2'

is_equal(self, other)

source code 
Return 1 if the given Date instance is the same as the present instance IN ALL REGARDS. Needed, because the __cmp__ only looks at the sorting value, and ignores the modifiers/comments.

__str__(self)
(Informal representation operator)

source code 
Produces a string representation of the Date object. If the date is not valid, the text representation is displayed. If the date is a range or a span, a string in the form of 'YYYY-MM-DD - YYYY-MM-DD' is returned. Otherwise, a string in the form of 'YYYY-MM-DD' is returned.

get_sort_value(self)

source code 

Returns the sort value of Date object. If the value is a text string, 0 is returned. Otherwise, the calculated sort date is returned. The sort date is rebuilt on every assignment.

The sort value is an integer representing the value. A date of March 5, 1990 would have the value of 19900305.

get_modifier(self)

source code 
Returns an integer indicating the calendar selected. The valid values are:
  MOD_NONE       = no modifier (default)
  MOD_BEFORE     = before
  MOD_AFTER      = after
  MOD_ABOUT      = about
  MOD_RANGE      = date range
  MOD_SPAN       = date span
  MOD_TEXTONLY   = text only

get_quality(self)

source code 
Returns an integer indicating the calendar selected. The valid values are:
  QUAL_NONE       = normal (default)
  QUAL_ESTIMATED  = estimated
  QUAL_CALCULATED = calculated

get_calendar(self)

source code 
Returns an integer indicating the calendar selected. The valid values are:
  CAL_GREGORIAN  - Gregorian calendar
  CAL_JULIAN     - Julian calendar
  CAL_HEBREW     - Hebrew (Jewish) calendar
  CAL_FRENCH     - French Republican calendar
  CAL_PERSIAN    - Persian calendar
  CAL_ISLAMIC    - Islamic calendar

get_start_date(self)

source code 
Returns a tuple representing the start date. If the date is a compound date (range or a span), it is the first part of the compound date. If the date is a text string, a tuple of (0, 0, 0, False) is returned. Otherwise, a date of (DD, MM, YY, slash) is returned. If slash is True, then the date is in the form of 1530/1.

get_stop_date(self)

source code 
Returns a tuple representing the second half of a compound date. If the date is not a compound date, (including text strings) a tuple of (0, 0, 0, False) is returned. Otherwise, a date of (DD, MM, YY, slash) is returned. If slash is True, then the date is in the form of 1530/1.

get_year(self)

source code 
Returns the year associated with the date. If the year is not defined, a zero is returned. If the date is a compound date, the lower date year is returned.

get_month(self)

source code 
Returns the month associated with the date. If the month is not defined, a zero is returned. If the date is a compound date, the lower date month is returned.

get_day(self)

source code 
Returns the day of the month associated with the date. If the day is not defined, a zero is returned. If the date is a compound date, the lower date day is returned.

get_stop_year(self)

source code 
Returns the day of the year associated with the second part of a compound date. If the year is not defined, a zero is returned.

get_stop_month(self)

source code 
Returns the month of the month associated with the second part of a compound date. If the month is not defined, a zero is returned.

get_stop_day(self)

source code 
Returns the day of the month associated with the second part of a compound date. If the day is not defined, a zero is returned.

get_high_year(self)

source code 
Returns the high year estimate. For compound dates with non-zero stop year, the stop year is returned. Otherwise, the start year is returned.

set(self, quality, modifier, calendar, value, text=None)

source code 
Sets the date to the specified value. Parameters are:
 quality  - The date quality for the date (see get_quality
            for more information)
 modified - The date modifier for the date (see get_modifier
            for more information)
 calendar - The calendar associated with the date (see
            get_calendar for more information).
 value    - A tuple representing the date information. For a
            non-compound date, the format is (DD, MM, YY, slash)
            and for a compound date the tuple stores data as
            (DD, MM, YY, slash1, DD, MM, YY, slash2)
 text     - A text string holding either the verbatim user input
            or a comment relating to the date.
The sort value is recalculated.

is_regular(self)

source code 

Returns True if the date is a regular date.

The regular date is a single exact date, i.e. not text-only, not a range or a span, not estimated/calculated, not about/before/after date, and having year, month, and day all non-zero.

Class Variable Details

calendar_names

Value:
['Gregorian',
 'Julian',
 'Hebrew',
 'French Republican',
 'Persian',
 'Islamic']

ui_calendar_names

Value:
['Gregorian',
 'Julian',
 'Hebrew',
 'French Republican',
 'Persian',
 'Islamic']