You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/02/17 18:17:28 UTC

[GitHub] [airflow] Sonins edited a comment on pull request #20508: Fix dates.days_ago to respect localized timezone configuration.

Sonins edited a comment on pull request #20508:
URL: https://github.com/apache/airflow/pull/20508#issuecomment-1043262523


   > If we change the timezone of `days_ago`, does that mean we will change the timezone of any dag that is using it, and therefore we'll change the time of day all those dags run? (assuming that they have changed default timezone to be non-UTC)
   
   For this, how about adding `days_ago` boolean option like below for backward compatibility?
   
   ```python
   def days_ago(n, hour=0, minute=0, second=0, microsecond=0, local=False):
       """
       Get a datetime object representing `n` days ago. By default the time is
       set to midnight.
       """
       if local:
           return datetime.combine(
               datetime.now(timezone.TIMEZONE) - timedelta(days=n),
               time(hour, minute, second, microsecond, tzinfo=timezone.TIMEZONE),
           )
       else:
          return datetime.combine(
               datetime.utcnow() - timedelta(days=n),
               time(hour, minute, second, microsecond),
          )
   ```
   It will be user's choice to change `days_ago` timezone in that way, adding new option `local=True` like below.
   
   ```python
   days_ago(7, local=True)
   ```
   
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org