Sonins commented on a change in pull request #20508:
URL: https://github.com/apache/airflow/pull/20508#discussion_r782623943



##########
File path: airflow/utils/dates.py
##########
@@ -257,7 +257,9 @@ 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 = timezone.utcnow().replace(hour=hour, minute=minute, second=second, 
microsecond=microsecond)
+    today = datetime.now(timezone.TIMEZONE).replace(
+        hour=hour, minute=minute, second=second, microsecond=microsecond
+    )

Review comment:
       `date.today()` returns today in UTC. So e.g. when it is `2021-01-12 
00:00` in UTC, date.today() returns `2021-01-12` even though it is still 
`2021-01-11` in Los Angeles time. `today()` is classmethod and does not take 
any other argument, so we can just use `datetime.now()` for date parameter in 
`datetime.combine()`.
   
   ```python
   def days_ago(n, hour=0, minute=0, second=0, microsecond=0):
       return datetime.combine(
           datetime.now(timezone.TIMEZONE) - timedelta(days=n),
           time(hour, minute, second, microsecond, tzinfo=timezone.TIMEZONE),
       )
   ```




-- 
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]


Reply via email to