Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't compare datetime.datetime to datetime.date #17

Open
cadu-leite opened this issue Mar 6, 2021 · 1 comment
Open

TypeError: can't compare datetime.datetime to datetime.date #17

cadu-leite opened this issue Mar 6, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@cadu-leite
Copy link
Owner

File "python3.9/site-packages/networkdays/networkdays.py", line 82, in
lambda d: self.date_end >= d >= self.date_start,
TypeError: can't compare datetime.datetime to datetime.date

@cadu-leite cadu-leite added the bug Something isn't working label Mar 6, 2021
@cadu-leite
Copy link
Owner Author

changing the type of self.date_start and self.date_start to datetime.datetime seem to solve the problem.

        if isinstance(self.date_start, datetime.date):
            self.date_start = datetime.datetime(self.date_start.year, self.date_start.month, self.date_start.day, 0, 0)
        if isinstance(self.date_end, datetime.date):
            self.date_end = datetime.datetime(self.date_end.year, self.date_end.month, self.date_end.day, 0, 0)


        return sorted(list(
            # filter(
            #     lambda d: self.date_end >= d.date() >= self.date_start,self.holidays_set
            # )
            
            filter(
                lambda d: self.date_end >= d >= self.date_start,self.holidays_set
            )

Possible solutions ...

  1. to have a setter and this make sure the datestart property and date_end property are set as datetime.
  2. use the example code above (this will deny to the user to use a date type as input)

@cadu-leite cadu-leite added enhancement New feature or request and removed bug Something isn't working labels Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant