Skip to content

Commit c7bc43d

Browse files
committed
adding docs
1 parent 0d17101 commit c7bc43d

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Tested on Python 3.8+ and PyPy3.
2323

2424
Please check the [ChangeLog](CHANGELOG.md) file for the detailed information.
2525

26+
DeepDiff 8-4-0
27+
28+
- default_timezone can be passed now to set your default timezone to something other than UTC.
29+
- New summarization algorithm that produces valid json
30+
- Better type hint support
31+
2632
DeepDiff 8-3-0
2733

2834
- Fixed some static typing issues

docs/basics.rst

+24
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,28 @@ Example of using group_by_sort_key
296296
'old_value': 'Blue'}}}
297297

298298

299+
.. _default_timezone_label:
300+
301+
Default Time Zone
302+
-----------------
303+
304+
default_timezone defines the default timezone. If a datetime is timezone naive, which means it doesn't have a timezone, we assume the datetime is in this timezone. Also any datetime that has a timezone will be converted to this timezone so the datetimes can be compared properly all in the same timezone. Note that Python's default behavior assumes the default timezone is your local timezone. DeepDiff's default is UTC, not your local time zone.
305+
306+
307+
Note that if we change the default_timezone, the output timezone changes accordingly
308+
>>> from deepdiff import DeepDiff
309+
>>> import pytz
310+
>>> from datetime import date, datetime, time, timezone
311+
>>> dt_utc = datetime(2025, 2, 3, 12, 0, 0, tzinfo=pytz.utc) # UTC timezone
312+
>>> dt_utc2 = datetime(2025, 2, 3, 11, 0, 0, tzinfo=pytz.utc) # UTC timezone
313+
>>> dt_ny = dt_utc.astimezone(pytz.timezone('America/New_York'))
314+
>>> dt_ny2 = dt_utc2.astimezone(pytz.timezone('America/New_York'))
315+
>>> diff = DeepDiff(dt_ny, dt_ny2)
316+
>>> diff
317+
{'values_changed': {'root': {'new_value': datetime.datetime(2025, 2, 3, 11, 0, tzinfo=datetime.timezone.utc), 'old_value': datetime.datetime(2025, 2, 3, 12, 0, tzinfo=datetime.timezone.utc)}}}
318+
>>> diff2 = DeepDiff(dt_ny, dt_ny2, default_timezone=pytz.timezone('America/New_York'))
319+
>>> diff2
320+
{'values_changed': {'root': {'new_value': datetime.datetime(2025, 2, 3, 6, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>), 'old_value': datetime.datetime(2025, 2, 3, 7, 0, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>)}}}
321+
322+
299323
Back to :doc:`/index`

docs/diff_doc.rst

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ cache_tuning_sample_size : int >= 0, default = 0
3939
custom_operators : BaseOperator subclasses, default = None
4040
:ref:`custom_operators_label` if you are considering whether they are fruits or not. In that case, you can pass a *custom_operators* for the job.
4141

42+
default_timezone : datetime.timezone subclasses or pytz datetimes, default = datetime.timezone.utc
43+
:ref:`default_timezone_label` defines the default timezone. If a datetime is timezone naive, which means it doesn't have a timezone, we assume the datetime is in this timezone. Also any datetime that has a timezone will be converted to this timezone so the datetimes can be compared properly all in the same timezone. Note that Python's default behavior assumes the default timezone is your local timezone. DeepDiff's default is UTC, not your local time zone.
44+
4245
encodings: List, default = None
4346
:ref:`encodings_label` Character encodings to iterate through when we convert bytes into strings. You may want to pass an explicit list of encodings in your objects if you start getting UnicodeDecodeError from DeepHash. Also check out :ref:`ignore_encoding_errors_label` if you can get away with ignoring these errors and don't want to bother with an explicit list of encodings but it will come at the price of slightly less accuracy of the final results. Example: encodings=["utf-8", "latin-1"]
4447

docs/faq.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Q: Why my datetimes are reported in UTC?
154154
**Answer**
155155

156156
DeepDiff converts all datetimes into UTC. If a datetime is timezone naive, we assume it is in UTC too.
157-
That is different than what Python does. Python assumes your timezone naive datetime is in your local timezone.
157+
That is different than what Python does. Python assumes your timezone naive datetime is in your local timezone. However, you can override it to any other time zone such as your :ref:`default_timezone_label`.
158158

159159
>>> from deepdiff import DeepDiff
160160
>>> from datetime import datetime, timezone
@@ -171,6 +171,7 @@ That is different than what Python does. Python assumes your timezone naive date
171171
>>> d1 == d3
172172
False
173173

174+
174175
---------
175176

176177
.. admonition:: A message from `Sep <https://github.com/seperman>`__, the creator of DeepDiff

docs/index.rst

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ The DeepDiff library includes the following modules:
3131
What Is New
3232
***********
3333

34+
DeepDiff 8-4-0
35+
--------------
36+
37+
- default_timezone can be passed now to set your default timezone to something other than UTC.
38+
- New summarization algorithm that produces valid json
39+
- Better type hint support
40+
41+
3442
DeepDiff 8-3-0
3543
--------------
3644

tests/test_diff_datetime.py

+24
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ def test_diffs_datetimes_different_timezones(self):
9191
t2 = [dt_ny, dt_utc, dt_ny]
9292
assert not DeepDiff(t1, t2, ignore_order=True)
9393

94+
def test_diffs_datetimes_in_different_timezones(self):
95+
dt_utc = datetime(2025, 2, 3, 12, 0, 0, tzinfo=pytz.utc) # UTC timezone
96+
dt_utc2 = datetime(2025, 2, 3, 11, 0, 0, tzinfo=pytz.utc) # UTC timezone
97+
dt_ny = dt_utc.astimezone(pytz.timezone('America/New_York'))
98+
dt_ny2 = dt_utc2.astimezone(pytz.timezone('America/New_York'))
99+
diff = DeepDiff(dt_ny, dt_ny2)
100+
assert {
101+
"values_changed": {
102+
"root": {
103+
"new_value": dt_utc2,
104+
"old_value": dt_utc,
105+
}
106+
}
107+
} == diff
108+
diff2 = DeepDiff(dt_ny, dt_ny2, default_timezone=pytz.timezone('America/New_York'))
109+
assert {
110+
"values_changed": {
111+
"root": {
112+
"new_value": dt_ny2,
113+
"old_value": dt_ny,
114+
}
115+
}
116+
} == diff2
117+
94118
def test_datetime_within_array_with_timezone_diff(self):
95119
d1 = [datetime(2020, 8, 31, 13, 14, 1)]
96120
d2 = [datetime(2020, 8, 31, 13, 14, 1, tzinfo=timezone.utc)]

0 commit comments

Comments
 (0)