as-cle-bert commited on
Commit
168921c
1 Parent(s): e6e2a19

Create date.py

Browse files
Files changed (1) hide show
  1. date.py +22 -0
date.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime, timedelta
2
+ import pytz
3
+
4
+ utc=pytz.UTC
5
+
6
+ def date_is_within_one_year(date):
7
+ """
8
+ Finds dates within one year from the reference date.
9
+
10
+ :param date: A datetime object to check.
11
+ :return: True if the date is within one year, False if not.
12
+ """
13
+ reference_date = datetime.today()
14
+ reference_date = reference_date.replace(tzinfo=utc)
15
+ date = date.replace(tzinfo=utc)
16
+ one_year_ago = reference_date - timedelta(days=365)
17
+ one_year_ago = one_year_ago.replace(tzinfo=utc)
18
+
19
+ if one_year_ago <= date <= reference_date:
20
+ return True
21
+ return False
22
+