timkpaine commented on PR #35887:
URL: https://github.com/apache/airflow/pull/35887#issuecomment-1841473356

   Ok nvm! I think this is good, here is my test (adapted to Zurich):
   
   ```python
   import pendulum
   import datetime
   from airflow.models.dag import DAG
   from airflow.utils import timezone
   from airflow.timetables.interval import CronDataIntervalTimetable
   
   # Zurich (Switzerland) is chosen since it is +1/+2 DST, making it a bit 
easier
   # to get my head around the mental timezone conversion.
   # In 2023, DST entered on 26th Mar, 2am local clocks (1am UTC) were turned
   # forward to 3am. DST exited on 29th Oct, 3am local clocks (1am UTC) were
   # turned backward to 2am (making the 2:XX hour fold).
   
   # Interval cron
   cron_interval = CronDataIntervalTimetable("0 0,3 * * *", 
timezone=pendulum.timezone("Europe/Zurich"))
   # Fixed cron
   cron_fixed = CronDataIntervalTimetable("0 3 * * *", 
timezone=pendulum.timezone("Europe/Zurich"))
   
   # ENTERING
   # These two last executed at 00:00 today and 03:00 yesterday, respectively.
   # Both of them should next execute at 3am local time today
   last_run_interval = pendulum.datetime(2023, 3, 26, 0, 
tz="Europe/Zurich").in_timezone("UTC")
   last_run_fixed = pendulum.datetime(2023, 3, 25, 3, 
tz="Europe/Zurich").in_timezone("UTC")
   
   # these should be 2023-03-25T23:00:00+00:00 and 2023-03-24T23:00:00+00:00
   expected_last_run_interval_utc_iso = "2023-03-25T23:00:00+00:00"
   expected_last_run_fixed_utc_iso = "2023-03-25T02:00:00+00:00"
   print(last_run_interval.isoformat(), last_run_interval.isoformat() == 
expected_last_run_interval_utc_iso)
   print(last_run_fixed.isoformat(), last_run_fixed.isoformat() == 
expected_last_run_fixed_utc_iso)
   
   # these should be 2023-03-26T00:00:00+01:00 and 2023-03-25T00:00:00+01:00
   expected_last_run_interval_local_iso = "2023-03-26T00:00:00+01:00"
   expected_last_run_fixed_local_iso = "2023-03-25T03:00:00+01:00"
   print(last_run_interval.in_timezone("Europe/Zurich").isoformat(), 
last_run_interval.in_timezone("Europe/Zurich").isoformat() == 
expected_last_run_interval_local_iso)
   print(last_run_fixed.in_timezone("Europe/Zurich").isoformat(), 
last_run_fixed.in_timezone("Europe/Zurich").isoformat() == 
expected_last_run_fixed_local_iso)
   
   
   # Now do next run
   next_run_interval = cron_interval._get_next(last_run_interval)
   next_run_fixed = cron_fixed._get_next(last_run_fixed)
   
   # these should be 2023-03-26T01:00:00+00:00
   expected_next_run_interval_utc_iso = "2023-03-26T01:00:00+00:00"
   expected_next_run_fixed_utc_iso = "2023-03-26T01:00:00+00:00"
   print(next_run_interval.isoformat(), next_run_interval.isoformat() == 
expected_next_run_interval_utc_iso)
   print(next_run_fixed.isoformat(), next_run_fixed.isoformat() == 
expected_next_run_fixed_utc_iso)
   
   expected_next_run_interval_local_iso = "2023-03-26T03:00:00+02:00"
   expected_next_run_fixed_local_iso = "2023-03-26T03:00:00+02:00"
   print(next_run_interval.in_timezone("Europe/Zurich").isoformat(), 
next_run_interval.in_timezone("Europe/Zurich").isoformat() == 
expected_next_run_interval_local_iso)
   print(next_run_fixed.in_timezone("Europe/Zurich").isoformat(), 
next_run_fixed.in_timezone("Europe/Zurich").isoformat() == 
expected_next_run_fixed_local_iso)
   
   
   # LEAVING
   # These two last executed at 00:00 today and 03:00 yesterday, respectively.
   # Both of them should next execute at 3am local time today
   last_run_interval = pendulum.datetime(2023, 10, 29, 0, 
tz="Europe/Zurich").in_timezone("UTC")
   last_run_fixed = pendulum.datetime(2023, 10, 28, 3, 
tz="Europe/Zurich").in_timezone("UTC")
   
   # these should be 2023-10-28T22:00:00+00:00 and 2023-10-28T01:00:00+00:00
   expected_last_run_interval_utc_iso = "2023-10-28T22:00:00+00:00"
   expected_last_run_fixed_utc_iso = "2023-10-28T01:00:00+00:00"
   print(last_run_interval.isoformat(), last_run_interval.isoformat() == 
expected_last_run_interval_utc_iso)
   print(last_run_fixed.isoformat(), last_run_fixed.isoformat() == 
expected_last_run_fixed_utc_iso)
   
   # these should be 2023-10-29T00:00:00+02:00 and 2023-10-28T03:00:00+02:00
   expected_last_run_interval_local_iso = "2023-10-29T00:00:00+02:00"
   expected_last_run_fixed_local_iso = "2023-10-28T03:00:00+02:00"
   print(last_run_interval.in_timezone("Europe/Zurich").isoformat(), 
last_run_interval.in_timezone("Europe/Zurich").isoformat() == 
expected_last_run_interval_local_iso)
   print(last_run_fixed.in_timezone("Europe/Zurich").isoformat(), 
last_run_fixed.in_timezone("Europe/Zurich").isoformat() == 
expected_last_run_fixed_local_iso)
   
   
   # Now do next run
   next_run_interval = cron_interval._get_next(last_run_interval)
   next_run_fixed = cron_fixed._get_next(last_run_fixed)
   
   # these should be 2023-03-26T01:00:00+00:00
   expected_next_run_interval_utc_iso = "2023-10-29T02:00:00+00:00"
   expected_next_run_fixed_utc_iso = "2023-10-29T02:00:00+00:00"
   print(next_run_interval.isoformat(), next_run_interval.isoformat() == 
expected_next_run_interval_utc_iso)
   print(next_run_fixed.isoformat(), next_run_fixed.isoformat() == 
expected_next_run_fixed_utc_iso)
   
   expected_next_run_interval_local_iso = "2023-10-29T03:00:00+01:00"
   expected_next_run_fixed_local_iso = "2023-10-29T03:00:00+01:00"
   print(next_run_interval.in_timezone("Europe/Zurich").isoformat(), 
next_run_interval.in_timezone("Europe/Zurich").isoformat() == 
expected_next_run_interval_local_iso)
   print(next_run_fixed.in_timezone("Europe/Zurich").isoformat(), 
next_run_fixed.in_timezone("Europe/Zurich").isoformat() == 
expected_next_run_fixed_local_iso)
   ```
   
   Main: 
   ```
   2023-03-25T23:00:00+00:00 True
   2023-03-25T02:00:00+00:00 True
   2023-03-26T00:00:00+01:00 True
   2023-03-25T03:00:00+01:00 True
   2023-03-26T02:00:00+00:00 False
   2023-03-26T01:00:00+00:00 True
   2023-03-26T04:00:00+02:00 False
   2023-03-26T03:00:00+02:00 True
   2023-10-28T22:00:00+00:00 True
   2023-10-28T01:00:00+00:00 True
   2023-10-29T00:00:00+02:00 True
   2023-10-28T03:00:00+02:00 True
   2023-10-29T01:00:00+00:00 False
   2023-10-29T02:00:00+00:00 True
   2023-10-29T02:00:00+01:00 False
   2023-10-29T03:00:00+01:00 True
   ```
   
   ```
   2023-03-25T23:00:00+00:00 True
   2023-03-25T02:00:00+00:00 True
   2023-03-26T00:00:00+01:00 True
   2023-03-25T03:00:00+01:00 True
   2023-03-26T01:00:00+00:00 True
   2023-03-26T01:00:00+00:00 True
   2023-03-26T03:00:00+02:00 True
   2023-03-26T03:00:00+02:00 True
   2023-10-28T22:00:00+00:00 True
   2023-10-28T01:00:00+00:00 True
   2023-10-29T00:00:00+02:00 True
   2023-10-28T03:00:00+02:00 True
   2023-10-29T02:00:00+00:00 True
   2023-10-29T02:00:00+00:00 True
   2023-10-29T03:00:00+01:00 True
   2023-10-29T03:00:00+01:00 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to