Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. from datetime import datetime, timedelta
  2.  
  3. def process_dates(date):
  4. """
  5. Process adjacent days to account for flights that
  6. have a different departure day than the day they were
  7. archived (which is the date contained in the filenames)
  8. """
  9.  
  10. """
  11. Convert to datetime objects before processing
  12. This is done so the conversion is less error-prone by
  13. avoiding edge cases like 1st of Jan, 29th of Feb, y3k, etc
  14. """
  15. datetimes = []
  16. today = datetime.strptime(date, '%Y%m%d')
  17.  
  18. """
  19. Compute the adjacent days, but keeping the order of the elements
  20. the following: today, yesterday, tomorrow, and the day after tomorrow.
  21. This is done because the looking up later on is done sequentially
  22. and the order reflects the probability of being the needed date
  23. (i.e. it's most probable the needed day is today, so it will stop before
  24. processing the other days)
  25. """
  26. [datetimes.append(today + timedelta(days=i)) for i in [0, -1, 1, 2]]
  27. return [datetime.strftime(j, '%y%m%d') for j in datetimes]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement