Sonins commented on a change in pull request #20508:
URL: https://github.com/apache/airflow/pull/20508#discussion_r776548184
##########
File path: tests/utils/test_dates.py
##########
@@ -29,8 +29,10 @@
class TestDates(unittest.TestCase):
Review comment:
Instead of using `datetime.utcnow()`, I just replace it with
`datetime.now(timezone.TIMEZONE)`
So dates.days_ago code will be like below.
```python
def days_ago(n, hour=0, minute=0, second=0, microsecond=0):
"""
Get a datetime object representing `n` days ago. By default the time is
set to midnight.
"""
today = datetime.now(timezone.TIMEZONE).replace(
hour=hour, minute=minute, second=second, microsecond=microsecond
)
return today - timedelta(days=n)
```
For DST offset problem, I tested it with several condition and it looks fine
with timedelta substraction.
test code:
```python
from datetime import datetime, timedelta
import pendulum
after_dst_end = "2021-11-08"
dst_timezone = pendulum.tz.timezone("America/Los_Angeles")
dt = datetime.fromisoformat(after_dst_end).replace(tzinfo=dst_timezone)
print(dt)
print(dt - timedelta(days=1))
print(dt - timedelta(days=2))
print(dt - timedelta(days=260))
```
result:
```
2021-11-08 00:00:00-08:00 # dt
2021-11-07 00:00:00-07:00 # dt - 1
2021-11-06 00:00:00-07:00 # dt - 2
2021-02-21 00:00:00-08:00 # dt - 260
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]