connector date range filtering fixed

This commit is contained in:
Aditya Vaish 2025-10-16 01:00:31 +05:30
parent 62ffec9678
commit c044d42012
2 changed files with 22 additions and 6 deletions

View file

@ -5,6 +5,7 @@ A module for retrieving data from ClickUp.
Allows fetching tasks from workspaces and lists.
"""
from datetime import datetime
from typing import Any
import requests
@ -168,13 +169,28 @@ class ClickUpConnector:
Tuple containing (tasks list, error message or None)
"""
try:
# TODO : Include date range in api request
# Convert date strings to Unix timestamps (milliseconds)
start_datetime = datetime.strptime(start_date, "%Y-%m-%d")
end_datetime = datetime.strptime(end_date, "%Y-%m-%d")
# Set time to start and end of day for complete coverage
start_datetime = start_datetime.replace(hour=0, minute=0, second=0, microsecond=0)
end_datetime = end_datetime.replace(hour=23, minute=59, second=59, microsecond=999999)
start_timestamp = int(start_datetime.timestamp() * 1000)
end_timestamp = int(end_datetime.timestamp() * 1000)
params = {
"page": 0,
"order_by": "created",
"reverse": "true",
"subtasks": "true",
"include_closed": str(include_closed).lower(),
# Date filtering - filter by both created and updated dates
"date_created_gt": start_timestamp,
"date_created_lt": end_timestamp,
"date_updated_gt": start_timestamp,
"date_updated_lt": end_timestamp,
}
all_tasks = []

View file

@ -222,14 +222,14 @@ class JiraConnector:
# Build JQL query for date range
# Query issues that were either created OR updated within the date range
date_filter = (
f"(createdDate >= '{start_date}' AND createdDate <= '{end_date}')"
f"(createdDate >= '{start_date}' AND createdDate <= '{end_date}') "
f"OR (updatedDate >= '{start_date}' AND updatedDate <= '{end_date}')"
)
# TODO : This JQL needs some improvement to work as expected
_jql = f"{date_filter}"
_jql = f"{date_filter} ORDER BY created DESC"
if project_key:
_jql = (
f'project = "{project_key}" AND {date_filter} ORDER BY created DESC'
f'project = "{project_key}" AND ({date_filter}) ORDER BY created DESC'
)
# Define fields to retrieve
@ -250,7 +250,7 @@ class JiraConnector:
fields.append("comment")
params = {
# "jql": "", TODO : Add a JQL query to filter from a date range
"jql": _jql,
"fields": ",".join(fields),
"maxResults": 100,
"startAt": 0,