Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime, timedelta
- def process_dates(date):
- """
- Process adjacent days to account for flights that
- have a different departure day than the day they were
- archived (which is the date contained in the filenames)
- """
- """
- Convert to datetime objects before processing
- This is done so the conversion is less error-prone by
- avoiding edge cases like 1st of Jan, 29th of Feb, y3k, etc
- """
- datetimes = []
- today = datetime.strptime(date, '%Y%m%d')
- """
- Compute the adjacent days, but keeping the order of the elements
- the following: today, yesterday, tomorrow, and the day after tomorrow.
- This is done because the looking up later on is done sequentially
- and the order reflects the probability of being the needed date
- (i.e. it's most probable the needed day is today, so it will stop before
- processing the other days)
- """
- [datetimes.append(today + timedelta(days=i)) for i in [0, -1, 1, 2]]
- return [datetime.strftime(j, '%y%m%d') for j in datetimes]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement