Skip to content

Commit

Permalink
Fix - schedule single event (#791)
Browse files Browse the repository at this point in the history
* Fix editing single event setting the correct date

Signed-off-by: angatupyry <[email protected]>

* Add toIsoFormat

Signed-off-by: angatupyry <[email protected]>

* format date to isoFormat

Signed-off-by: angatupyry <[email protected]>

* Format to isoFormat

Signed-off-by: angatupyry <[email protected]>

* Revert to exceptDateref insted of the schedule request time

Signed-off-by: angatupyry <[email protected]>

---------

Signed-off-by: angatupyry <[email protected]>
  • Loading branch information
Angatupyry authored Oct 6, 2023
1 parent 4e4e336 commit c9c4570
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
18 changes: 6 additions & 12 deletions packages/api-server/api_server/routes/tasks/scheduled_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ class PostScheduledTaskRequest(BaseModel):
schedules: list[ttm.ScheduledTaskSchedulePydantic]


def datetime_to_date_format(date: datetime) -> str:
# input 09/08/2023
formatted_date = date.date().strftime("%m/%d/%Y").lstrip("0")
parts = formatted_date.split("/")
parts[1] = parts[1].lstrip("0")
# output 9/8/2023
return "/".join(parts)


async def schedule_task(task: ttm.ScheduledTask, task_repo: TaskRepository):
await task.fetch_related("schedules")
jobs: list[tuple[ttm.ScheduledTaskSchedule, schedule.Job]] = []
Expand All @@ -59,7 +50,8 @@ async def run():

def do():
logger.info(f"starting task {task.pk}")
if datetime_to_date_format(datetime.now()) in task.except_dates:
datetime_to_iso = datetime.now().isoformat()
if datetime_to_iso[:10] in task.except_dates:
return
asyncio.get_event_loop().create_task(run())

Expand Down Expand Up @@ -151,7 +143,8 @@ async def del_scheduled_tasks_event(
if task is None:
raise HTTPException(404)

task.except_dates.append(datetime_to_date_format(event_date))
event_date_str = event_date.isoformat()
task.except_dates.append(event_date_str[:10])
await task.save()

for sche in task.schedules:
Expand Down Expand Up @@ -181,7 +174,8 @@ async def update_schedule_task(

async with tortoise.transactions.in_transaction():
if except_date:
task.except_dates.append(datetime_to_date_format(except_date))
event_date_str = except_date.isoformat()
task.except_dates.append(event_date_str[:10])
await task.save()

for sche in task.schedules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ export const scheduleToEvents = (
(scheStartFrom == null || scheStartFrom <= cur) &&
(scheUntil == null || scheUntil >= cur)
) {
if (!task.except_dates.includes(cur.toLocaleDateString())) {
const curToIso = cur.toISOString();
const curFormatted = `${curToIso.slice(0, 10)}`;
if (!task.except_dates.includes(curFormatted)) {
events.push({
start: cur,
end: addMinutes(cur, 45),
Expand Down

0 comments on commit c9c4570

Please sign in to comment.