File size: 1,690 Bytes
622387b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
diff --git a/timefhuman/main.py b/timefhuman/main.py
index 448a4e2..58b7faa 100644
--- a/timefhuman/main.py
+++ b/timefhuman/main.py
@@ -1,8 +1,8 @@
-from datetime import timedelta
-import datetime
+from datetime import datetime, timedelta
 from pathlib import Path
 
-from lark import Lark, Transformer, v_args, Token, Discard
+from dataclasses import replace
+from lark import Lark, Transformer, v_args
 import pytz
 from timefhuman.utils import generate_timezone_mapping, nodes_to_dict, nodes_to_multidict, get_month_mapping, tfhConfig, Direction, direction_to_offset
 from timefhuman.renderers import tfhDatetime, tfhDate, tfhTime, tfhRange, tfhList, tfhTimedelta, tfhAmbiguous, tfhUnknown, tfhDatelike, tfhMatchable
@@ -28,12 +28,16 @@ def get_parser():
     return parser
 
 
-def timefhuman(string, config: tfhConfig = tfhConfig(), raw=None):
+def timefhuman(string, config: tfhConfig = tfhConfig(), raw: bool=False, now: bool=False):
     parser = get_parser()
     tree = parser.parse(string)
 
     if raw:
         return tree
+    
+    config = replace(config, now=config.now or datetime.now())
+    if now:
+        return config.now
 
     transformer = tfhTransformer(config=config)
     renderers = transformer.transform(tree)
diff --git a/timefhuman/utils.py b/timefhuman/utils.py
index 7f39218..c715513 100644
--- a/timefhuman/utils.py
+++ b/timefhuman/utils.py
@@ -24,7 +24,7 @@ class tfhConfig:
     infer_datetimes: bool = True
     
     # The 'current' datetime, used if infer_datetimes is True
-    now: datetime = datetime.now()    
+    now: datetime | None = None
     
     # Return the matched text from the input string
     return_matched_text: bool = False