-
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.
Use only timezones for datetime parser (#108)
take into account the timezone when parsing datetime and getting the time from the computer
- Loading branch information
1 parent
7c792c6
commit 9466020
Showing
5 changed files
with
59 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ dependencies: | |
- syrupy==4.6.1 | ||
- pip: | ||
- pytest-order==1.2.1 | ||
- freezegun==1.5.1 |
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
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,31 @@ | ||
from datetime import datetime | ||
|
||
from freezegun import freeze_time | ||
|
||
from copernicusmarine.core_functions.utils import datetime_parser | ||
|
||
|
||
class TestUtilityFunctions: | ||
@freeze_time("2012-01-14 03:21:34", tz_offset=-2) | ||
def test_datetime_parser(self): | ||
# all parsed dates are in UTC | ||
assert datetime_parser("now") == datetime(2012, 1, 14, 1, 21, 34) | ||
assert datetime_parser("2012-01-14T03:21:34.000000+02:00") == datetime( | ||
2012, 1, 14, 1, 21, 34 | ||
) | ||
|
||
# All format are supported | ||
assert datetime_parser("2012") == datetime(2012, 1, 1, 0, 0, 0) | ||
assert datetime_parser("2012-01-14") == datetime(2012, 1, 14, 0, 0, 0) | ||
assert datetime_parser("2012-01-14T03:21:34") == datetime( | ||
2012, 1, 14, 3, 21, 34 | ||
) | ||
assert datetime_parser("2012-01-14 03:21:34") == datetime( | ||
2012, 1, 14, 3, 21, 34 | ||
) | ||
assert datetime_parser("2012-01-14T03:21:34.000000") == datetime( | ||
2012, 1, 14, 3, 21, 34 | ||
) | ||
assert datetime_parser("2012-01-14T03:21:34.000000Z") == datetime( | ||
2012, 1, 14, 3, 21, 34 | ||
) |