Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PythonExpressionGenerator {
ToDateTimeOperation: '''datetime.datetime.strptime(«generateExpression(expr.argument, ifLevel, isLambda)», "%Y-%m-%d %H:%M:%S")'''
ToIntOperation: '''int(«generateExpression(expr.argument, ifLevel, isLambda)»)'''
ToTimeOperation: '''datetime.datetime.strptime(«generateExpression(expr.argument, ifLevel, isLambda)», "%H:%M:%S").time()'''
ToZonedDateTimeOperation:'''datetime.datetime.strptime(«generateExpression(expr.argument, ifLevel, isLambda)», "%Y-%m-%d %H:%M:%S %z %Z")'''
ToZonedDateTimeOperation:'''rune_zoned_date_time(«generateExpression(expr.argument, ifLevel, isLambda)»)'''
// Rune Operations
RosettaAbsentExpression: '''(not rune_attr_exists(«generateExpression(expr.argument, ifLevel, isLambda)»))'''
RosettaBinaryOperation: generateBinaryExpression(expr, ifLevel, isLambda)
Expand Down
1 change: 1 addition & 0 deletions test/python_setup/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
setuptools>=62.0
tzdata>=2023.3
pytest
38 changes: 29 additions & 9 deletions test/python_unit_tests/semantics/test_to_zoned_date_time.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
'''to-zoned-date-time unit tests'''

import datetime
from zoneinfo import ZoneInfo

import pytest

from rosetta_dsl.test.semantic.zoned_date_time_operator.ZonedDateTimeOperatorTest import ZonedDateTimeOperatorTest
from rosetta_dsl.test.semantic.toZonedDateTimeOp.TestToZonedDateTimeOp import TestToZonedDateTimeOp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

believe this import and the class usage need to be aligned to the naming of the class created: ZonedDateTimeOperatorTest



def test_to_zoned_date_time_offset_and_time_zone():
to_zoned_date_time_test= TestToZonedDateTimeOp(a="2025-07-07 15:30:00 +0100 Europe/Lisbon",b=datetime.datetime(2025,7, 7, 15, 30, 0, tzinfo=ZoneInfo("Europe/Lisbon")))
to_zoned_date_time_test.validate_model()

def test_to_zoned_date_time_only_time_zone():
to_zoned_date_time_test= TestToZonedDateTimeOp(a="2025-07-07 15:30:00 Europe/Lisbon",b=datetime.datetime(2025,7, 7, 15, 30, 0, tzinfo=ZoneInfo("Europe/Lisbon")))
to_zoned_date_time_test.validate_model()

def test_to_zoned_date_time_passes():
'''no doc'''
to_zoned_date_time_test= ZonedDateTimeOperatorTest(a="2025-05-26 14:30:00 +0900 UTC",b=datetime.datetime(2025, 5, 26, 14, 30, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=9), 'UTC')))
def test_to_zoned_date_time_only_time_zone2():
to_zoned_date_time_test= TestToZonedDateTimeOp(a="2025-03-15 12:00:00 Zulu",b=datetime.datetime(2025,3, 15, 12, 0, 0, tzinfo=ZoneInfo("Zulu")))
to_zoned_date_time_test.validate_model()

def test_to_zoned_date_time_only_offset():
to_zoned_date_time_test= TestToZonedDateTimeOp(a="2025-05-26 14:30:00 +0900",b=datetime.datetime(2025,5, 26, 14, 30, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=9))))
to_zoned_date_time_test.validate_model()

def test_to_zoned_date_time_fails():
'''no doc'''
to_zoned_date_time_test= ZonedDateTimeOperatorTest(a="2025-05-26 14:30:00 +09x0 UTC",b=datetime.datetime(2025, 5, 26, 14, 30, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=9), 'UTC')))
to_zoned_date_time_test= TestToZonedDateTimeOp(a="2025-12-15 15:30:00 +0100 Europe/Lisbon",b=datetime.datetime(2025, 5, 26, 14, 30, 0, tzinfo=ZoneInfo("Europe/Lisbon")))
with pytest.raises(Exception):
to_zoned_date_time_test.validate_model()

def test_to_zoned_date_time_fails_format():
to_zoned_date_time_test= TestToZonedDateTimeOp(a="2025-05-26 14:30:00 +09x0",b=datetime.datetime(2025, 5, 26, 14, 30, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=9))))
with pytest.raises(Exception):
to_zoned_date_time_test.validate_model()

if __name__ == "__main__":
test_to_zoned_date_time_passes()
test_to_zoned_date_time_fails()
test_to_zoned_date_time_offset_and_time_zone()
test_to_zoned_date_time_only_time_zone()
test_to_zoned_date_time_only_time_zone2()
test_to_zoned_date_time_only_offset()
test_to_zoned_date_time_fails()
test_to_zoned_date_time_fails_format()