calendar Module

The calendar module provides standardised date management functionality based on a calendar subgraph:

from py2neo import neo4j
from py2neo.calendar import GregorianCalendar

graph_db = neo4j.GraphDatabaseService()
time_index = graph_db.get_or_create_index(neo4j.Node, "TIME")
calendar = GregorianCalendar(time_index)

graph_db.create(
    {"name": "Alice"},
    (0, "BORN", calendar.day(1800, 1, 1)),
    (0, "DIED", calendar.day(1900, 12, 31)),
)

The root calendar node is held within a dedicated node index which needs to be supplied to the calendar constructor.

All dates managed by the GregorianCalendar class adhere to a hierarchy such as:

(CALENDAR)-[:YEAR]->(2000)-[:MONTH]->(12)-[:DAY]->(25)
class py2neo.calendar.GregorianCalendar(index)[source]

Bases: object

class Date(year, month=None, day=None)[source]

Bases: object

get_node(calendar)[source]
class GregorianCalendar.DateRange(start_date=None, end_date=None)[source]

Bases: object

GregorianCalendar.calendar()[source]
GregorianCalendar.date(date)[source]
GregorianCalendar.date_range(start_date=None, end_date=None)[source]

Fetch the calendar node representing the date range defined by start_date and end_date. If either are unspecified, this defines an open-ended range. Either start_date or end_date must be specified.

GregorianCalendar.day(year, month, day)[source]

Fetch the calendar node representing the day specified by year, month and day.

GregorianCalendar.month(year, month)[source]

Fetch the calendar node representing the month specified by year and month.

GregorianCalendar.quarter(year, quarter)[source]
GregorianCalendar.year(year)[source]

Fetch the calendar node representing the year specified by year.

Previous topic

rest Module

Next topic

admin Module

This Page