Package gen :: Package lib :: 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, **kwargs)
Create 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)
Compare two dates.
source code
 
__add__(self, other)
Date arithmetic: Date() + years, or Date() + (years, [months, [days]]).
source code
 
__radd__(self, other)
Add a number + Date() or (years, months, days) + Date().
source code
 
__sub__(self, other)
Date arithmetic: Date() - years, Date - (y,m,d), or Date() - Date().
source code
 
__lt__(self, other) source code
 
__gt__(self, other) 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
 
get_start_stop_range(self)
Return the minimal start_date, and a maximal stop_date corresponding to this date, given in Gregorian calendar.
source code
 
match(self, other_date, comparison='=')
Compare two dates using sophisticated techniques looking for any match between two possible dates, date spans and qualities.
source code
 
__str__(self)
Produce a string representation of the Date object.
source code
 
get_sort_value(self)
Return the sort value of Date object.
source code
 
get_modifier(self)
Return an integer indicating the calendar selected.
source code
 
set_modifier(self, val)
Set the modifier for the date.
source code
 
get_quality(self)
Return an integer indicating the calendar selected.
source code
 
set_quality(self, val)
Set the quality selected for the date.
source code
 
get_calendar(self)
Return an integer indicating the calendar selected.
source code
 
set_calendar(self, val)
Set the calendar selected for the date.
source code
 
get_start_date(self)
Return a tuple representing the start date.
source code
 
get_stop_date(self)
Return a tuple representing the second half of a compound date.
source code
 
get_year(self)
Return the year associated with the date.
source code
 
set_yr_mon_day(self, year, month, day)
Set the year, month, and day values.
source code
 
set_yr_mon_day_offset(self, year=0, month=0, day=0)
Set the year, month, and day values by offset.
source code
 
copy_offset_ymd(self, year=0, month=0, day=0)
Return a Date copy based on year, month, and day offset.
source code
 
copy_ymd(self, year=0, month=0, day=0)
Return a Date copy with year, month, and day set.
source code
 
set_year(self, year)
Set the year value.
source code
 
get_year_valid(self)
Return true if the year is valid.
source code
 
get_month(self)
Return the month associated with the date.
source code
 
get_month_valid(self)
Return true if the month is valid
source code
 
get_day(self)
Return the day of the month associated with the date.
source code
 
get_day_valid(self)
Return true if the day is valid.
source code
 
get_valid(self)
Return true if any part of the date is valid.
source code
 
get_stop_year(self)
Return the day of the year associated with the second part of a compound date.
source code
 
get_stop_month(self)
Return the month of the month associated with the second part of a compound date.
source code
 
get_stop_day(self)
Return the day of the month associated with the second part of a compound date.
source code
 
get_high_year(self)
Return the high year estimate.
source code
 
get_text(self)
Return the text value associated with an invalid date.
source code
 
set(self, quality, modifier, calendar, value, text=None)
Set the date to the specified value.
source code
 
convert_calendar(self, calendar)
Convert the date from the current calendar to the specified calendar.
source code
 
set_as_text(self, text)
Set the day to a text string, and assign the sort value to zero.
source code
 
set_text_value(self, text)
Set the text string to a given text.
source code
 
is_empty(self)
Return True if the date contains no information (empty text).
source code
 
is_compound(self)
Return True if the date is a date range or a date span.
source code
 
is_regular(self)
Return True if the date is a regular date.
source code
 
get_ymd(self)
Return (year, month, day).
source code
 
offset(self, value)
Return (year, month, day) of this date +- value.
source code
 
offset_date(self, value)
Return (year, month, day) of this date +- value.
source code
 
lookup_calendar(self, calendar)
Lookup calendar name in the list of known calendars, even if translated.
source code
 
lookup_quality(self, quality)
Lookup date quality keyword, even if translated.
source code
 
lookup_modifier(self, modifier)
Lookup date modifier keyword, even if translated.
source code
 
to_calendar(self, calendar_name)
Return a new Date object in the calendar calendar_name.
source code
 
get_slash(self)
Return true if the date is a slash-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 

Compare two dates.

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.

get_start_stop_range(self)

source code 

Return the minimal start_date, and a maximal stop_date corresponding to this date, given in Gregorian calendar.

Useful in doing range overlap comparisons between different dates.

Note that we stay in (YR,MON,DAY)

match(self, other_date, comparison='=')

source code 

Compare two dates using sophisticated techniques looking for any match 
between two possible dates, date spans and qualities.

The other comparisons for Date (is_equal() and __cmp() don't actually 
look for anything other than a straight match, or a simple comparison 
of the sortval.

comparison =,== :
    Returns True if any part of other_date matches any part of self
comparison < :
    Returns True if any part of other_date < any part of self
comparison << :
    Returns True if all parts of other_date < all parts of self
comparison > :
    Returns True if any part of other_date > any part of self
comparison >> :
    Returns True if all parts of other_date > all parts of self

__str__(self)
(Informal representation operator)

source code 

Produce 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 

Return 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. The sortval is the integer number of days that have elapsed since Monday, January 1, 4713 BC in the proleptic Julian calendar. See http://en.wikipedia.org/wiki/Julian_day

get_modifier(self)

source code 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Return 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 

Set 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 

Return 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.

to_calendar(self, calendar_name)

source code 

Return a new Date object in the calendar calendar_name.

>>> Date("Jan 1 1591").to_calendar("julian")
1590-12-22 (Julian)

Class Variable Details

calendar_names

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

ui_calendar_names

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