-
Notifications
You must be signed in to change notification settings - Fork 7
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 #112 from igorkramaric/add-current-date-functions
Add current date functions
- Loading branch information
Showing
7 changed files
with
140 additions
and
29 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
Empty file.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from datetime import datetime, timezone, timedelta | ||
from random import randint | ||
|
||
|
||
now = datetime.now().replace(tzinfo=timezone.utc) | ||
day_start = now.replace(hour=0, minute=0, second=0, microsecond=0).replace(tzinfo=timezone.utc) | ||
|
||
|
||
def random_until_now(start): | ||
return randint(int(start.timestamp()), int(now.timestamp())) | ||
|
||
|
||
def days_ago_ts(days): | ||
return (now - timedelta(days=days)).timestamp() | ||
|
||
|
||
days_ago_0 = random_until_now(day_start) | ||
days_ago_3 = days_ago_ts(3) | ||
|
||
weeks_ago_0 = random_until_now( | ||
(day_start - timedelta(days=day_start.weekday())) | ||
) | ||
weeks_ago_5 = days_ago_ts(7 * 5) | ||
|
||
months_ago_0 = random_until_now(day_start.replace(day=1)) | ||
months_ago_7 = days_ago_ts(7 * 30) | ||
|
||
years_ago_0 = random_until_now(day_start.replace(month=1, day=1)) | ||
years_ago_2 = days_ago_ts(2 * 365) |
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