A library that computes the ephemerides.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

33 wiersze
862 B

  1. #!/usr/bin/env python3
  2. from datetime import datetime, timezone, timedelta
  3. def translate_to_timezone(date: datetime, to_tz: int, from_tz: int = None):
  4. if from_tz is not None:
  5. source_tz = timezone(timedelta(hours=from_tz))
  6. else:
  7. source_tz = timezone.utc
  8. return date.replace(tzinfo=source_tz).astimezone(
  9. tz=timezone(timedelta(hours=to_tz))
  10. )
  11. def normalize_datetime(date: datetime) -> datetime:
  12. """Round the seconds in the given datetime
  13. >>> normalize_datetime(datetime(2021, 6, 9, 2, 30, 29))
  14. datetime.datetime(2021, 6, 9, 2, 30)
  15. >>> normalize_datetime(datetime(2021, 6, 9, 2, 30, 30))
  16. datetime.datetime(2021, 6, 9, 2, 31)
  17. """
  18. return datetime(
  19. date.year,
  20. date.month,
  21. date.day,
  22. date.hour,
  23. date.minute if date.second < 30 else date.minute + 1,
  24. )