-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ivandiaz-tomtom/master
Update datetime to always follow the same format
- Loading branch information
Showing
3 changed files
with
13 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
from datetime import datetime, timedelta | ||
import numpy as np | ||
from os import environ | ||
|
||
def get_process_date(): | ||
date_format = '%Y-%m-%d' | ||
if environ.get('LAST_PROCESSED_DATE'): | ||
return np.datetime64(datetime.strptime(environ.get('LAST_PROCESSED_DATE'), date_format).date()) | ||
return get_first_day_previous_month() | ||
|
||
def get_first_day_current_month(): | ||
input_dt = datetime.today().date() | ||
day_num = input_dt.strftime("%d") | ||
result = input_dt - timedelta(days=int(day_num) - 1) | ||
return np.datetime64(result) | ||
return np.datetime64(datetime.today().replace(day=1).date()) | ||
|
||
def get_first_day_previous_month(): | ||
input_dt = datetime.today().date() | ||
result = (input_dt - timedelta(days=input_dt.day)).replace(day=1) | ||
return np.datetime64(result) | ||
last_day_previous_month = datetime.today().replace(day=1) - timedelta(days=1) | ||
return np.datetime64(last_day_previous_month.replace(day=1).date()) |