Skip to content

Commit 8fd8f16

Browse files
committed
Weekday support
1 parent b617efa commit 8fd8f16

1 file changed

Lines changed: 79 additions & 0 deletions

File tree

terminusdb_client/woqlquery/woql_query.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,85 @@ def day_before(self, date, previous):
25762576
self._cursor["previous"] = self._clean_object(previous)
25772577
return self
25782578

2579+
def weekday(self, date, weekday):
2580+
"""Computes the ISO 8601 weekday number (Monday=1, Sunday=7) for a date.
2581+
Accepts xsd:date or xsd:dateTime. Date must be ground.
2582+
2583+
Parameters
2584+
----------
2585+
date : str or dict
2586+
the input date or dateTime
2587+
weekday : str or int
2588+
the ISO weekday number (1=Monday, 7=Sunday)
2589+
2590+
Returns
2591+
-------
2592+
WOQLQuery object
2593+
query object that can be chained and/or execute
2594+
"""
2595+
if date is None or weekday is None:
2596+
raise ValueError("Weekday takes two parameters")
2597+
if self._cursor.get("@type"):
2598+
self._wrap_cursor_with_and()
2599+
self._cursor["@type"] = "Weekday"
2600+
self._cursor["date"] = self._clean_object(date)
2601+
self._cursor["weekday"] = self._clean_object(weekday)
2602+
return self
2603+
2604+
def weekday_sunday_start(self, date, weekday):
2605+
"""Computes the US-convention weekday number (Sunday=1, Saturday=7) for a date.
2606+
Accepts xsd:date or xsd:dateTime. Date must be ground.
2607+
2608+
Parameters
2609+
----------
2610+
date : str or dict
2611+
the input date or dateTime
2612+
weekday : str or int
2613+
the US weekday number (1=Sunday, 7=Saturday)
2614+
2615+
Returns
2616+
-------
2617+
WOQLQuery object
2618+
query object that can be chained and/or execute
2619+
"""
2620+
if date is None or weekday is None:
2621+
raise ValueError("WeekdaySundayStart takes two parameters")
2622+
if self._cursor.get("@type"):
2623+
self._wrap_cursor_with_and()
2624+
self._cursor["@type"] = "WeekdaySundayStart"
2625+
self._cursor["date"] = self._clean_object(date)
2626+
self._cursor["weekday"] = self._clean_object(weekday)
2627+
return self
2628+
2629+
def iso_week(self, date, year, week):
2630+
"""Computes the ISO 8601 week-numbering year and week number for a date.
2631+
Accepts xsd:date or xsd:dateTime. Date must be ground.
2632+
The ISO year may differ from the calendar year at year boundaries.
2633+
2634+
Parameters
2635+
----------
2636+
date : str or dict
2637+
the input date or dateTime
2638+
year : str or int
2639+
the ISO week-numbering year
2640+
week : str or int
2641+
the ISO week number (1-53)
2642+
2643+
Returns
2644+
-------
2645+
WOQLQuery object
2646+
query object that can be chained and/or execute
2647+
"""
2648+
if date is None or year is None or week is None:
2649+
raise ValueError("IsoWeek takes three parameters")
2650+
if self._cursor.get("@type"):
2651+
self._wrap_cursor_with_and()
2652+
self._cursor["@type"] = "IsoWeek"
2653+
self._cursor["date"] = self._clean_object(date)
2654+
self._cursor["year"] = self._clean_object(year)
2655+
self._cursor["week"] = self._clean_object(week)
2656+
return self
2657+
25792658
def opt(self, query=None):
25802659
"""The Query in the Optional argument is specified as optional
25812660

0 commit comments

Comments
 (0)