Fix date parsing error: prevent negative days by using timedelta (#264)

subtracting extracted "days" from label with current day causes negative days
datetime class rejects negative day association
Use timedelta for proper date limitation

Co-authored-by: NIKHIL S <nikhil_s@nikhilMac.local>
main
Nikhil Sasi 2025-03-28 08:28:42 +05:30 committed by GitHub
parent d4d52d05f5
commit f1602eca70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -3,7 +3,7 @@ from __future__ import annotations
import math import math
import random import random
import time import time
from datetime import datetime, date from datetime import datetime, date, timedelta
from typing import Optional from typing import Optional
import regex as re import regex as re
@ -277,7 +277,7 @@ class Naukri(Scraper):
match = re.search(r"(\d+)\s*day", label) match = re.search(r"(\d+)\s*day", label)
if match: if match:
days = int(match.group(1)) days = int(match.group(1))
parsed_date = today.replace(day=today.day - days).date() parsed_date = (today - timedelta(days = days)).date()
log.debug(f"Date parsed: {days} days ago -> {parsed_date}") log.debug(f"Date parsed: {days} days ago -> {parsed_date}")
return parsed_date return parsed_date
elif created_date: elif created_date: